From 2f7c7931f51893b041f37675ad7d1ca615cbb8d2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Apr 2022 08:02:05 +0000 Subject: [PATCH 001/109] Auto-generated commit 65910cc0e9684ad3eabeb643abd24b9e96baac98 --- CONTRIBUTORS | 28 + LICENSE | 481 +++++++++ NOTICE | 1 + README.md | 358 +++++++ index.d.ts | 334 ++++++ index.mjs | 4 + index.mjs.map | 1 + package.json | 33 + stats.html | 2689 +++++++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 3929 insertions(+) create mode 100644 CONTRIBUTORS create mode 100644 LICENSE create mode 100644 NOTICE create mode 100644 README.md create mode 100644 index.d.ts create mode 100644 index.mjs create mode 100644 index.mjs.map create mode 100644 package.json create mode 100644 stats.html diff --git a/CONTRIBUTORS b/CONTRIBUTORS new file mode 100644 index 0000000..e5c896d --- /dev/null +++ b/CONTRIBUTORS @@ -0,0 +1,28 @@ +# This file is generated by tools/scripts/update_contributors. +# +# Contributors listed in alphabetical order. + +Ali Salesi +Athan Reines +Brendan Graetz +Bruno Fenzl +Christopher Dambamuromo +Dominik Moritz +Frank Kovacs +James +Jithin KS +Joey Reed +Joris Labie +Justin Dennison +Marcus +Matt Cochrane +Milan Raj +Momtchil Momtchev +Ognjen Jevremović +Philipp Burckhardt +Ricky Reusser +Ryan Seal +Seyyed Parsa Neshaei +Shraddheya Shendre +dorrin-sot <59933477+dorrin-sot@users.noreply.github.com> +rei2hu diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..fcc9934 --- /dev/null +++ b/LICENSE @@ -0,0 +1,481 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + + +Boost Software License - Version 1.0 - August 17th, 2003 + +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by this +license (the "Software") to use, reproduce, display, distribute, execute, and +transmit the Software, and to prepare derivative works of the Software, and to +permit third-parties to whom the Software is furnished to do so, all subject to +the following: + +The copyright notices in the Software and this entire statement, including the +above license grant, this restriction and the following disclaimer, must be +included in all copies of the Software, in whole or in part, and all derivative +works of the Software, unless such copies or derivative works are solely in the +form of machine-executable object code generated by a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE +COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES +OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + + + +DEPENDENCIES + +The library links against the following external libraries, which have their own +licenses: + +* OpenBLAS + +Copyright (c) 2011-2014, The OpenBLAS Project +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + 3. Neither the name of the OpenBLAS project nor the names of + its contributors may be used to endorse or promote products + derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +* Electron + +Copyright (c) 2013-2017 GitHub Inc. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + +* Boost + +Boost Software License - Version 1.0 - August 17th, 2003 + +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by +this license (the "Software") to use, reproduce, display, distribute, +execute, and transmit the Software, and to prepare derivative works of the +Software, and to permit third-parties to whom the Software is furnished to +do so, all subject to the following: + +The copyright notices in the Software and this entire statement, including +the above license grant, this restriction and the following disclaimer, +must be included in all copies of the Software, in whole or in part, and +all derivative works of the Software, unless such copies or derivative +works are solely in the form of machine-executable object code generated by +a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. + + +* Cephes + +Copyright (c) 1984-2000 Stephen L. Moshier + +Some software in this archive may be from the book _Methods and Programs for +Mathematical Functions_ (Prentice-Hall or Simon & Schuster International, 1989) +or from the Cephes Mathematical Library, a commercial product. In either event, +it is copyrighted by the author. What you see here may be used freely but it +comes with no support or guarantee. + +Stephen L. Moshier +moshier@na-net.ornl.gov + + + +ATTRIBUTION + +The library contains implementations from the following external libraries, +which have their own licenses: + +* FreeBSD + +Copyright (C) 1993-2004 by Sun Microsystems, Inc. All rights reserved. + +Developed at SunPro, a Sun Microsystems, Inc. business. +Permission to use, copy, modify, and distribute this +software is freely granted, provided that this notice +is preserved. + + +* FDLIBM + +Copyright (C) 2004 by Sun Microsystems, Inc. All rights reserved. + +Developed at SunPro, a Sun Microsystems, Inc. business. +Permission to use, copy, modify, and distribute this +software is freely granted, provided that this notice +is preserved. + + +* Go + +Copyright (c) 2009 The Go Authors. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of Google Inc. nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +* SLATEC Common Mathematical Library + +Public domain. + + +* ESLint + +Copyright JS Foundation and other contributors, https://js.foundation + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + + +* StatsFuns.jl + +Copyright (c) 2015: Dahua Lin. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + +* SpecialFunctions.jl + +The MIT License (MIT) + +Copyright (c) 2017 Jeff Bezanson, Stefan Karpinski, Viral B. Shah, and others: + +https://github.com/JuliaMath/SpecialFunctions.jl/graphs/contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + + +* MT19937 + +Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + 3. The names of its contributors may not be used to endorse or promote + products derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/NOTICE b/NOTICE new file mode 100644 index 0000000..10e6ba1 --- /dev/null +++ b/NOTICE @@ -0,0 +1 @@ +Copyright (c) 2016-2022 The Stdlib Authors. diff --git a/README.md b/README.md new file mode 100644 index 0000000..6752bc6 --- /dev/null +++ b/README.md @@ -0,0 +1,358 @@ + + +# Dispatch + +[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] + +> Create an [ndarray][@stdlib/ndarray/ctor] function interface which performs multiple dispatch. + +
+ +
+ + + + + +
+ +## Usage + +```javascript +import dispatch from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dispatch@esm/index.mjs'; +``` + +#### dispatch( fcns, types, data, nargs, nin, nout ) + +Returns an [ndarray][@stdlib/ndarray/ctor] function interface which performs multiple dispatch. + + + +```javascript +import unary from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-unary@esm/index.mjs'; +import Float64Array from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-float64@esm/index.mjs'; +import Float32Array from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-float32@esm/index.mjs'; +import ndarray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs'; + +function foo( x ) { + return x * 10.0; +} + +function bar( x ) { + return x * 5.0; +} + +// Define a list of ndarray 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 = 2; // input_array + output_array + +// Define the number of input ndarrays: +var nin = 1; + +// Define the number of output ndarrays: +var nout = 1; + +// Create an ndarray function interface: +var fcn = dispatch( fcns, types, data, nargs, nin, nout ); + +// ... + +var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); +var ybuf = new Float64Array( xbuf.length ); + +var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); +var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); + +fcn( x, y ); +// ybuf => [ 10.0, 20.0, 30.0 ] + +xbuf = new Float32Array( [ 1.0, 2.0, 3.0 ] ); +ybuf = new Float32Array( xbuf.length ); + +x = ndarray( 'float32', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); +y = ndarray( 'float32', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); + +fcn( x, y ); +// ybuf => [ 5.0, 10.0, 15.0 ] +``` + +The function accepts the following arguments: + +- **fcns**: list of [ndarray][@stdlib/ndarray/ctor] functions. +- **types**: one-dimensional list of [ndarray][@stdlib/ndarray/ctor] argument [data types][@stdlib/ndarray/dtypes]. The length of `types` must be the number of [ndarray][@stdlib/ndarray/ctor] functions multiplied by `nin+nout`. If `fcns` is a function, rather than a list, the number of [ndarray][@stdlib/ndarray/ctor] functions is computed as `types.length / (nin+nout)`. +- **data**: [ndarray][@stdlib/ndarray/ctor] function data (e.g., callbacks). If a list, the length of `data` must equal the number of [ndarray][@stdlib/ndarray/ctor] functions. If `null`, a returned [ndarray][@stdlib/ndarray/ctor] function interface does **not** provide a `data` argument to an invoked [ndarray][@stdlib/ndarray/ctor] function. +- **nargs**: total number of [ndarray][@stdlib/ndarray/ctor] function interface arguments. +- **nin**: number of input [ndarrays][@stdlib/ndarray/ctor]. +- **nout**: number of output [ndarrays][@stdlib/ndarray/ctor]. + +
+ + + +
+ +## Notes + +- A returned [ndarray][@stdlib/ndarray/ctor] function interface has the following signature: + + ```text + f( x, y, ... ) + ``` + + where + + - **x**: [ndarray][@stdlib/ndarray/ctor]. + - **y**: [ndarray][@stdlib/ndarray/ctor]. + - **...**: additional [ndarrays][@stdlib/ndarray/ctor]. + +- The number of [ndarray][@stdlib/ndarray/ctor] function interface parameters is derived from `nargs`, the number of input [ndarrays][@stdlib/ndarray/ctor] is derived from `nin`, and the number of output [ndarrays][@stdlib/ndarray/ctor] is derived from `nout`. + +- An [ndarray][@stdlib/ndarray/ctor] function (i.e., a value provided for the `fcns` argument) should have the following signature: + + ```text + f( arrays[, data] ) + ``` + + where + + - **arrays**: array containing input and output [ndarrays][@stdlib/ndarray/ctor]. + - **data**: [ndarray][@stdlib/ndarray/ctor] function data (e.g., a callback). + +- For convenience, a single [ndarray][@stdlib/ndarray/ctor] function may be provided which will be invoked whenever the [ndarray][@stdlib/ndarray/ctor] argument data types match a sequence of types in `types`. Providing a single [ndarray][@stdlib/ndarray/ctor] function is particularly convenient for the case where, regardless of array data types, traversing arrays remains the same, but the [ndarray][@stdlib/ndarray/ctor] function `data` differs (e.g., callbacks which differ based on the array data types). For example, the following + + + + ```javascript + import unary from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-unary@esm/index.mjs'; + + 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 fcn = dispatch( fcns, types, data, 2, 1, 1 ); + ``` + + is equivalent to + + + + ```javascript + import unary from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-unary@esm/index.mjs'; + + 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 fcn = dispatch( unary, types, data, 2, 1, 1 ); + ``` + +
+ + + +
+ +## Examples + + + +```html + + + + + + +``` + +
+ + + + + + + + + + + + +
+ +* * * + +## Notice + +This package is part of [stdlib][stdlib], a standard library 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-2022. The Stdlib [Authors][stdlib-authors]. + +
+ + + + + + + + diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..e8f79c8 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,334 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2021 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. +*/ + +// TypeScript Version: 2.0 + +/// + +import { ndarray } from '@stdlib/types/ndarray'; + +/** +* ndarray function. +* +* @param arrays - array containing input and output ndarrays +* @param data - ndarray function data (e.g., a callback) +* +* @example +* var numel = require( `@stdlib/ndarray/base/numel` ); +* var ind2sub = require( `@stdlib/ndarray/ind2sub` ); +* +* function ndarrayFcn( arrays, fcn ) { +* var xord; +* var yord; +* var opts; +* var sub; +* var sh; +* var N; +* var x; +* var y; +* var v; +* var i; +* +* x = arrays[ 0 ]; +* y = arrays[ 1 ]; +* sh = x.shape; +* N = numel( sh ); +* if ( N <= 0 ) { +* return; +* } +* xord = x.order; +* yord = y.order; +* opts = {}; +* opts.order = xord; +* for ( i = 0; i < N; i++ ) { +* // Convert a linear index to subscripts: +* opts.order = xord; +* sub = ind2sub( sh, i, opts ); +* +* // Retrieve an element from `x`: +* v = x.get.apply( x, sub ); +* +* // Convert a linear index to subscripts: +* opts.order = yord; +* sub = ind2sub( sh, i, opts ); +* +* // Append the result of applying the callback: +* sub.push( fcn( v ) ); +* +* // Assign the result to an element in `y`: +* y.set.apply( y, sub ); +* } +* } +*/ +type ndarrayFcn = ( arrays: Array, data?: any ) => void; + +/** +* Interface describing an ndarray function dispatcher. +*/ +interface Dispatcher { + /** + * Invokes an ndarray function based on the provided array data type(s). + * + * @param x - ndarray + * @throws input array arguments must be ndarray-like objects + * @throws output array arguments must be ndarray-like objects + * @throws unable to resolve an ndarray function supporting the provided array argument data types + * @returns destination array + * + * @example + * var nullary = require( `@stdlib/ndarray/base/nullary` ); + * var Float64Array = require( `@stdlib/array/float64` ); + * var ndarray = require( `@stdlib/ndarray/ctor` ); + * + * function value() { + * return 3.14; + * } + * + * var types = [ 'float64' ]; + * var data = [ value ]; + * + * var fcn = dispatch( nullary, types, data, 1, 0, 1 ); + * + * // ... + * + * var xbuf = new Float64Array( 5 ); + * var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); + * + * fcn( x ); + * // xbuf => [ 3.14, 3.14, 3.14, 3.14, 3.14 ] + */ + ( x: ndarray ): ndarray | void; + + /** + * Invokes an ndarray function based on the provided array data types. + * + * @param x - ndarray + * @param y - ndarray + * @throws input array arguments must be ndarray-like objects + * @throws output array arguments must be ndarray-like objects + * @throws unable to resolve an ndarray function supporting the provided array argument data types + * @returns destination array(s) + * + * @example + * var unary = require( `@stdlib/ndarray/base/unary` ); + * var Float64Array = require( `@stdlib/array/float64` ); + * var ndarray = require( `@stdlib/ndarray/ctor` ); + * var abs = require( `@stdlib/math/base/special/abs` ); + * + * var types = [ 'float64', 'float64' ]; + * var data = [ abs ]; + * + * var fcn = dispatch( unary, types, data, 2, 1, 1 ); + * + * // ... + * + * var xbuf = new Float64Array( [ -1.0, -2.0, -3.0 ] ); + * var ybuf = new Float64Array( xbuf.length ); + * + * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); + * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); + * + * fcn( x, y ); + * // ybuf => [ 1.0, 2.0, 3.0 ] + */ + ( x: ndarray, y: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures + + /** + * Invokes an ndarray function based on the provided array data types. + * + * @param x - ndarray + * @param y - ndarray + * @param z - ndarray + * @throws input array arguments must be ndarray-like objects + * @throws output array arguments must be ndarray-like objects + * @throws unable to resolve an ndarray function supporting the provided array argument data types + * @returns destination array(s) + * + * @example + * var ternary = require( `@stdlib/ndarray/base/ternary` ); + * var Float64Array = require( `@stdlib/array/float64` ); + * var ndarray = require( `@stdlib/ndarray/ctor` ); + * + * function add2( x, y ) { + * return x + y; + * } + * + * var types = [ 'float64', 'float64', 'float64' ]; + * var data = [ add2 ]; + * + * var fcn = dispatch( ternary, types, data, 3, 2, 1 ); + * + * // ... + * + * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + * var zbuf = new Float64Array( xbuf.length ); + * + * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); + * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); + * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); + * + * fcn( x, y, z ); + * // zbuf => [ 2.0, 4.0, 6.0 ] + */ + ( x: ndarray, y: ndarray, z: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures + + /** + * Invokes an ndarray function based on the provided array data types. + * + * @param x - ndarray + * @param y - ndarray + * @param z - ndarray + * @param w - ndarray + * @throws input array arguments must be ndarray-like objects + * @throws output array arguments must be ndarray-like objects + * @throws unable to resolve an ndarray function supporting the provided array argument data types + * @returns destination array(s) + * + * @example + * var quaternary = require( `@stdlib/ndarray/base/quaternary` ); + * var Float64Array = require( `@stdlib/array/float64` ); + * var ndarray = require( `@stdlib/ndarray/ctor` ); + * + * function add3( x, y, z ) { + * return x + y + z; + * } + * + * var types = [ 'float64', 'float64', 'float64', 'float64' ]; + * var data = [ add3 ]; + * + * var fcn = dispatch( quaternary, types, data, 4, 3, 1 ); + * + * // ... + * + * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + * var wbuf = new Float64Array( xbuf.length ); + * + * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); + * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); + * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); + * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); + * + * fcn( x, y, z, w ); + * // wbuf => [ 3.0, 6.0, 9.0 ] + */ + ( x: ndarray, y: ndarray, z: ndarray, w: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures + + /** + * Invokes an ndarray function based on the provided array data types. + * + * @param x - ndarray + * @param y - ndarray + * @param z - ndarray + * @param w - ndarray + * @param args - ndarray arguments + * @throws input array arguments must be ndarray-like objects + * @throws output array arguments must be ndarray-like objects + * @throws unable to resolve an ndarray function supporting the provided array argument data types + * @returns destination array(s) + * + * @example + * var quinary = require( `@stdlib/ndarray/base/quinary` ); + * var Float64Array = require( `@stdlib/array/float64` ); + * var ndarray = require( `@stdlib/ndarray/ctor` ); + * + * function add4( x, y, z, w ) { + * return x + y + z + w; + * } + * + * var types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; + * var data = [ add4 ]; + * + * var fcn = dispatch( quinary, types, data, 5, 4, 1 ); + * + * // ... + * + * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + * var wbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); + * var ubuf = new Float64Array( xbuf.length ); + * + * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); + * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); + * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); + * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); + * var u = ndarray( 'float64', ubuf, [ 3 ], [ 1 ], 0, 'row-major' ); + * + * fcn( x, y, z, w, u ); + * // ubuf => [ 4.0, 8.0, 12.0 ] + */ + ( x: ndarray, y: ndarray, z: ndarray, w: ndarray, ...args: Array ): ndarray | void; // tslint:disable-line:max-line-length unified-signatures +} + +/** +* Returns an ndarray function interface which performs multiple dispatch. +* +* @param fcns - list of ndarray functions +* @param types - one-dimensional list of ndarray argument data types +* @param data - ndarray function data (e.g., callbacks) +* @param nargs - total number of ndarray function interface arguments +* @param nin - number of input ndarrays +* @param nout - number of output ndarrays +* @throws first argument must be either a function or an array of functions +* @throws second argument must be an array-like object +* @throws third argument must be an array-like object or `null` +* @throws third and first arguments must have the same number of elements +* @throws fourth argument must be a positive integer +* @throws fifth argument must be a nonnegative integer +* @throws sixth argument must be a nonnegative integer +* @throws fourth argument must equal the specified number of input and output arrays +* @throws number of types must match the number of functions times the total number of array arguments for each function +* @throws interface must accept at least one input and/or output ndarray +* @returns ndarray function interface +* +* @example +* var unary = require( `@stdlib/ndarray/base/unary` ); +* var abs = require( `@stdlib/math/base/special/abs` ); +* var Float64Array = require( `@stdlib/array/float64` ); +* var ndarray = require( `@stdlib/ndarray/ctor` ); +* +* var types = [ +* 'float64', 'float64' +* ]; +* +* var data = [ +* abs +* ]; +* +* var fcn = dispatch( unary, types, data, 2, 1, 1 ); +* +* // ... +* +* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); +* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); +* +* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); +* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); +* +* fcn( x, y ); +* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] +*/ +declare function dispatch( fcns: ndarrayFcn | ArrayLike, types: ArrayLike, data: ArrayLike | null, nargs: number, nin: number, nout: number ): Dispatcher; // tslint:disable-line:max-line-length + + +// EXPORTS // + +export = dispatch; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..f98b50e --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@esm/index.mjs";var u=function(e,r,t,n,i,a,s,o,u){var m,d,l,f;for(m=a,l=0;l [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or `null`. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' );\n\t}\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( 'invalid invocation. Insufficient arguments.' );\n\t\t\t}\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( 'invalid argument. Input array argument must be an ndarray-like object.' );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( 'invalid argument. Output array argument must be an ndarray-like object.' );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( v.dtype );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = dispatch;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an ndarray function interface which performs multiple dispatch.\n*\n* @module @stdlib/ndarray-dispatch\n*\n* @example\n* var dispatch = require( '@stdlib/ndarray-dispatch' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var unary = require( '@stdlib/ndarray-base-unary' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var types = [\n* 'float64', 'float64'\n* ];\n*\n* var data = [\n* abs\n* ];\n*\n* var absolute = dispatch( unary, types, data, 2, 1, 1 );\n*\n* // ...\n*\n* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] );\n* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] );\n*\n* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' );\n* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' );\n*\n* absolute( x, y );\n* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\n\n// MODULES //\n\nvar dispatch = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = dispatch;\n"],"names":["index_of_types","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","i","j","isNonNegativeInteger","require$$0","isPrimitive","isPositiveInteger","require$$1","isInteger","require$$2","isFunctionArray","require$$3","isFunction","require$$4","isCollection","require$$5","isndarrayLike","require$$6","format","require$$7","indexOfTypes","require$$8","lib","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","TypeError","Error","length","arrays","dtypes","argc","idx","v","f","arguments","push","dtype","slice"],"mappings":";;ysBAyGA,IAAAA,EA5BA,SAAuBC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,KAAgBE,EAAGI,GADdE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,EAEP,OAAQ,GC7ELU,EAAuBC,EAAmDC,YAC1EC,EAAoBC,EACpBC,EAAYC,EAAuCJ,YACnDK,EAAkBC,EAClBC,EAAaC,EACbC,EAAeC,EACfC,EAAgBC,EAChBC,EAASC,EACTC,EAAeC,EAgLnB,ICjJAC,EDsBA,SAAmBC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKnB,EAAYW,GAChBQ,EAAMR,OACA,IAAMb,EAAiBa,GAC7B,MAAM,IAAIS,UAAWd,EAAQ,oGAAqGK,IAEnI,IAAMT,EAAcU,GACnB,MAAM,IAAIQ,UAAWd,EAAQ,+EAAgFM,IAE9G,IAAMV,EAAcW,IAAmB,OAATA,EAC7B,MAAM,IAAIO,UAAWd,EAAQ,wFAAyFO,IAEvH,IAAMnB,EAAmBoB,GACxB,MAAM,IAAIM,UAAWd,EAAQ,6EAA8EQ,IAE5G,IAAMvB,EAAsBwB,GAC3B,MAAM,IAAIK,UAAWd,EAAQ,+EAAgFS,IAE9G,IAAMxB,EAAsByB,GAC3B,MAAM,IAAII,UAAWd,EAAQ,+EAAgFU,IAG9G,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIK,MAAO,8IAElB,GAAKP,IAAUG,EACd,MAAM,IAAII,MAAO,8FAElB,GAAKF,GAEJ,GADAD,EAAQN,EAAMU,OAASL,GACjBrB,EAAWsB,GAChB,MAAM,IAAIG,MAAO,qJAIlB,GADAH,EAAQP,EAAKW,OACRV,EAAMU,SAAWJ,EAAMD,EAC3B,MAAM,IAAII,MAAO,gJAGnB,GAAKR,GAAQA,EAAKS,SAAWJ,EAC5B,MAAM,IAAIG,MAAO,qGAElB,OAeA,WACC,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAC,EACAvC,EAGJ,IADAoC,EAAOI,UAAUP,UACHR,EAAQ,CACrB,GAAKW,EAAOX,EACX,MAAM,IAAIO,MAAO,+CAElB,MAAM,IAAIA,MAAO,2CAIlB,IAFAE,EAAS,GACTC,EAAS,GACHnC,EAAI,EAAGA,EAAIyB,EAAOzB,IAAM,CAE7B,IAAMe,EADNuB,EAAIE,UAAWxC,IAEd,MAAKA,EAAI0B,EACF,IAAIK,UAAW,0EAEf,IAAIA,UAAW,2EAGvBG,EAAOO,KAAMH,GACbH,EAAOM,KAAMH,EAAEI,OAMhB,IAHAL,EAAMlB,EAAcU,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGO,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAIJ,UAAW,+GAIrBQ,EADIT,GAGAR,EAAMe,GAGNb,EACJe,EAAGL,EAAQV,EAAMa,IAEjBE,EAAGL,GAEJ,GAAc,IAATP,EACJ,OAAOO,EAAQN,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOO,EAAOS,MAAOjB"} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..5909f04 --- /dev/null +++ b/package.json @@ -0,0 +1,33 @@ +{ + "name": "@stdlib/ndarray-dispatch", + "version": "0.0.0", + "description": "Create an ndarray function interface which performs multiple dispatch.", + "license": "Apache-2.0", + "type": "module", + "main": "./index.mjs", + "homepage": "https://stdlib.io", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/ndarray-dispatch.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "keywords": [ + "stdlib", + "ndarray", + "multidimensional", + "array", + "matrix", + "tensor", + "vector", + "dispatch", + "multiple dispatch", + "multimethod", + "multimethods" + ], + "funding": { + "type": "patreon", + "url": "https://www.patreon.com/athan" + } +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..1a450a5 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + From 03236b3a1c362339267e83494f57455d1ae04a85 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 01:04:08 +0000 Subject: [PATCH 002/109] Transform error messages --- lib/main.js | 28 ++++++++++++++-------------- package.json | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/main.js b/lib/main.js index 3d28781..c8218ef 100644 --- a/lib/main.js +++ b/lib/main.js @@ -27,7 +27,7 @@ var isFunctionArray = require( '@stdlib/assert-is-function-array' ); var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var indexOfTypes = require( './index_of_types.js' ); @@ -89,43 +89,43 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { if ( isFunction( fcns ) ) { fcn = fcns; } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) ); + throw new TypeError( format( '0Mq5s', fcns ) ); } if ( !isCollection( types ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) ); + throw new TypeError( format( '0Mq3A', types ) ); } if ( !isCollection( data ) && data !== null ) { throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); } if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) ); + throw new TypeError( format( '0Mq5u', nargs ) ); } if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) ); + throw new TypeError( format( '0Mq5v', nin ) ); } if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) ); + throw new TypeError( format( '0Mq5w', nout ) ); } narrays = nin + nout; if ( narrays === 0 ) { - throw new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' ); + throw new Error( format( '0Mq0h' ) ); } if ( nargs !== narrays ) { - throw new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' ); + throw new Error( format( '0Mq0i' ) ); } if ( fcn ) { nfcns = types.length / narrays; if ( !isInteger( nfcns ) ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format( '0Mq0j' ) ); } } else { nfcns = fcns.length; if ( types.length !== nfcns*narrays ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format( '0Mq0j' ) ); } } if ( data && data.length !== nfcns ) { - throw new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' ); + throw new Error( format( '0Mq0k' ) ); } return dispatcher; @@ -154,9 +154,9 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { argc = arguments.length; if ( argc !== nargs ) { if ( argc < nargs ) { - throw new Error( 'invalid invocation. Insufficient arguments.' ); + throw new Error( format( '0Mq0l' ) ); } - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format( '0Mq0m' ) ); } arrays = []; dtypes = []; @@ -177,7 +177,7 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { // Check whether we were able to successfully resolve an ndarray function: if ( idx < 0 ) { - throw new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' ); + throw new TypeError( format( '0Mq0p' ) ); } // Retrieve the ndarray function: if ( fcn ) { diff --git a/package.json b/package.json index 014d480..9569eb2 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-ndarray-like": "^0.0.x", "@stdlib/assert-is-nonnegative-integer": "^0.0.x", "@stdlib/assert-is-positive-integer": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From 76704e32b60e958714440b44bd86972817b944e6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 16:06:48 +0000 Subject: [PATCH 003/109] Remove files --- index.d.ts | 334 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 3028 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index e8f79c8..0000000 --- a/index.d.ts +++ /dev/null @@ -1,334 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* ndarray function. -* -* @param arrays - array containing input and output ndarrays -* @param data - ndarray function data (e.g., a callback) -* -* @example -* var numel = require( `@stdlib/ndarray/base/numel` ); -* var ind2sub = require( `@stdlib/ndarray/ind2sub` ); -* -* function ndarrayFcn( arrays, fcn ) { -* var xord; -* var yord; -* var opts; -* var sub; -* var sh; -* var N; -* var x; -* var y; -* var v; -* var i; -* -* x = arrays[ 0 ]; -* y = arrays[ 1 ]; -* sh = x.shape; -* N = numel( sh ); -* if ( N <= 0 ) { -* return; -* } -* xord = x.order; -* yord = y.order; -* opts = {}; -* opts.order = xord; -* for ( i = 0; i < N; i++ ) { -* // Convert a linear index to subscripts: -* opts.order = xord; -* sub = ind2sub( sh, i, opts ); -* -* // Retrieve an element from `x`: -* v = x.get.apply( x, sub ); -* -* // Convert a linear index to subscripts: -* opts.order = yord; -* sub = ind2sub( sh, i, opts ); -* -* // Append the result of applying the callback: -* sub.push( fcn( v ) ); -* -* // Assign the result to an element in `y`: -* y.set.apply( y, sub ); -* } -* } -*/ -type ndarrayFcn = ( arrays: Array, data?: any ) => void; - -/** -* Interface describing an ndarray function dispatcher. -*/ -interface Dispatcher { - /** - * Invokes an ndarray function based on the provided array data type(s). - * - * @param x - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array - * - * @example - * var nullary = require( `@stdlib/ndarray/base/nullary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function value() { - * return 3.14; - * } - * - * var types = [ 'float64' ]; - * var data = [ value ]; - * - * var fcn = dispatch( nullary, types, data, 1, 0, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( 5 ); - * var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x ); - * // xbuf => [ 3.14, 3.14, 3.14, 3.14, 3.14 ] - */ - ( x: ndarray ): ndarray | void; - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var unary = require( `@stdlib/ndarray/base/unary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * var abs = require( `@stdlib/math/base/special/abs` ); - * - * var types = [ 'float64', 'float64' ]; - * var data = [ abs ]; - * - * var fcn = dispatch( unary, types, data, 2, 1, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - * var ybuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y ); - * // ybuf => [ 1.0, 2.0, 3.0 ] - */ - ( x: ndarray, y: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var ternary = require( `@stdlib/ndarray/base/ternary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add2( x, y ) { - * return x + y; - * } - * - * var types = [ 'float64', 'float64', 'float64' ]; - * var data = [ add2 ]; - * - * var fcn = dispatch( ternary, types, data, 3, 2, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z ); - * // zbuf => [ 2.0, 4.0, 6.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quaternary = require( `@stdlib/ndarray/base/quaternary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add3( x, y, z ) { - * return x + y + z; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add3 ]; - * - * var fcn = dispatch( quaternary, types, data, 4, 3, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w ); - * // wbuf => [ 3.0, 6.0, 9.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @param args - ndarray arguments - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quinary = require( `@stdlib/ndarray/base/quinary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add4( x, y, z, w ) { - * return x + y + z + w; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add4 ]; - * - * var fcn = dispatch( quinary, types, data, 5, 4, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ubuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var u = ndarray( 'float64', ubuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w, u ); - * // ubuf => [ 4.0, 8.0, 12.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray, ...args: Array ): ndarray | void; // tslint:disable-line:max-line-length unified-signatures -} - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param fcns - list of ndarray functions -* @param types - one-dimensional list of ndarray argument data types -* @param data - ndarray function data (e.g., callbacks) -* @param nargs - total number of ndarray function interface arguments -* @param nin - number of input ndarrays -* @param nout - number of output ndarrays -* @throws first argument must be either a function or an array of functions -* @throws second argument must be an array-like object -* @throws third argument must be an array-like object or `null` -* @throws third and first arguments must have the same number of elements -* @throws fourth argument must be a positive integer -* @throws fifth argument must be a nonnegative integer -* @throws sixth argument must be a nonnegative integer -* @throws fourth argument must equal the specified number of input and output arrays -* @throws number of types must match the number of functions times the total number of array arguments for each function -* @throws interface must accept at least one input and/or output ndarray -* @returns ndarray function interface -* -* @example -* var unary = require( `@stdlib/ndarray/base/unary` ); -* var abs = require( `@stdlib/math/base/special/abs` ); -* var Float64Array = require( `@stdlib/array/float64` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var fcn = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* fcn( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function dispatch( fcns: ndarrayFcn | ArrayLike, types: ArrayLike, data: ArrayLike | null, nargs: number, nin: number, nout: number ): Dispatcher; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = dispatch; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index f98b50e..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@esm/index.mjs";var u=function(e,r,t,n,i,a,s,o,u){var m,d,l,f;for(m=a,l=0;l [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or `null`. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' );\n\t}\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( 'invalid invocation. Insufficient arguments.' );\n\t\t\t}\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( 'invalid argument. Input array argument must be an ndarray-like object.' );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( 'invalid argument. Output array argument must be an ndarray-like object.' );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( v.dtype );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = dispatch;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an ndarray function interface which performs multiple dispatch.\n*\n* @module @stdlib/ndarray-dispatch\n*\n* @example\n* var dispatch = require( '@stdlib/ndarray-dispatch' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var unary = require( '@stdlib/ndarray-base-unary' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var types = [\n* 'float64', 'float64'\n* ];\n*\n* var data = [\n* abs\n* ];\n*\n* var absolute = dispatch( unary, types, data, 2, 1, 1 );\n*\n* // ...\n*\n* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] );\n* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] );\n*\n* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' );\n* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' );\n*\n* absolute( x, y );\n* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\n\n// MODULES //\n\nvar dispatch = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = dispatch;\n"],"names":["index_of_types","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","i","j","isNonNegativeInteger","require$$0","isPrimitive","isPositiveInteger","require$$1","isInteger","require$$2","isFunctionArray","require$$3","isFunction","require$$4","isCollection","require$$5","isndarrayLike","require$$6","format","require$$7","indexOfTypes","require$$8","lib","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","TypeError","Error","length","arrays","dtypes","argc","idx","v","f","arguments","push","dtype","slice"],"mappings":";;ysBAyGA,IAAAA,EA5BA,SAAuBC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,KAAgBE,EAAGI,GADdE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,EAEP,OAAQ,GC7ELU,EAAuBC,EAAmDC,YAC1EC,EAAoBC,EACpBC,EAAYC,EAAuCJ,YACnDK,EAAkBC,EAClBC,EAAaC,EACbC,EAAeC,EACfC,EAAgBC,EAChBC,EAASC,EACTC,EAAeC,EAgLnB,ICjJAC,EDsBA,SAAmBC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKnB,EAAYW,GAChBQ,EAAMR,OACA,IAAMb,EAAiBa,GAC7B,MAAM,IAAIS,UAAWd,EAAQ,oGAAqGK,IAEnI,IAAMT,EAAcU,GACnB,MAAM,IAAIQ,UAAWd,EAAQ,+EAAgFM,IAE9G,IAAMV,EAAcW,IAAmB,OAATA,EAC7B,MAAM,IAAIO,UAAWd,EAAQ,wFAAyFO,IAEvH,IAAMnB,EAAmBoB,GACxB,MAAM,IAAIM,UAAWd,EAAQ,6EAA8EQ,IAE5G,IAAMvB,EAAsBwB,GAC3B,MAAM,IAAIK,UAAWd,EAAQ,+EAAgFS,IAE9G,IAAMxB,EAAsByB,GAC3B,MAAM,IAAII,UAAWd,EAAQ,+EAAgFU,IAG9G,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIK,MAAO,8IAElB,GAAKP,IAAUG,EACd,MAAM,IAAII,MAAO,8FAElB,GAAKF,GAEJ,GADAD,EAAQN,EAAMU,OAASL,GACjBrB,EAAWsB,GAChB,MAAM,IAAIG,MAAO,qJAIlB,GADAH,EAAQP,EAAKW,OACRV,EAAMU,SAAWJ,EAAMD,EAC3B,MAAM,IAAII,MAAO,gJAGnB,GAAKR,GAAQA,EAAKS,SAAWJ,EAC5B,MAAM,IAAIG,MAAO,qGAElB,OAeA,WACC,IAAIE,EACAC,EACAC,EACAC,EACAC,EACAC,EACAvC,EAGJ,IADAoC,EAAOI,UAAUP,UACHR,EAAQ,CACrB,GAAKW,EAAOX,EACX,MAAM,IAAIO,MAAO,+CAElB,MAAM,IAAIA,MAAO,2CAIlB,IAFAE,EAAS,GACTC,EAAS,GACHnC,EAAI,EAAGA,EAAIyB,EAAOzB,IAAM,CAE7B,IAAMe,EADNuB,EAAIE,UAAWxC,IAEd,MAAKA,EAAI0B,EACF,IAAIK,UAAW,0EAEf,IAAIA,UAAW,2EAGvBG,EAAOO,KAAMH,GACbH,EAAOM,KAAMH,EAAEI,OAMhB,IAHAL,EAAMlB,EAAcU,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGO,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAIJ,UAAW,+GAIrBQ,EADIT,GAGAR,EAAMe,GAGNb,EACJe,EAAGL,EAAQV,EAAMa,IAEjBE,EAAGL,GAEJ,GAAc,IAATP,EACJ,OAAOO,EAAQN,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOO,EAAOS,MAAOjB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 1a450a5..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From f5f707d0eb631e98cbf630d42c703b786f04e46a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 16:07:49 +0000 Subject: [PATCH 004/109] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 33 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 681 ------ .github/workflows/publish.yml | 157 -- .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 59 +- benchmark/benchmark.dispatch_size.js | 156 -- benchmark/benchmark.js | 81 - branches.md | 53 - docs/repl.txt | 87 - docs/types/test.ts | 641 ----- examples/add.js | 121 - examples/sin.js | 142 -- examples/unary.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/index_of_types.js | 106 - lib/main.js | 207 -- package.json | 76 +- stats.html | 2689 +++++++++++++++++++++ test/fixtures/binary.js | 38 - test/fixtures/fill.js | 76 - test/fixtures/foreach.js | 72 - test/fixtures/map1n.js | 74 - test/fixtures/nullary.js | 36 - test/fixtures/quaternary.js | 40 - test/fixtures/quinary.js | 41 - test/fixtures/sum.js | 98 - test/fixtures/ternary.js | 39 - test/test.js | 363 --- test/test.two_arrays.js | 808 ------- 51 files changed, 2723 insertions(+), 6341 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.dispatch_size.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/add.js delete mode 100644 examples/sin.js delete mode 100644 examples/unary.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/index_of_types.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/fixtures/binary.js delete mode 100644 test/fixtures/fill.js delete mode 100644 test/fixtures/foreach.js delete mode 100644 test/fixtures/map1n.js delete mode 100644 test/fixtures/nullary.js delete mode 100644 test/fixtures/quaternary.js delete mode 100644 test/fixtures/quinary.js delete mode 100644 test/fixtures/sum.js delete mode 100644 test/fixtures/ternary.js delete mode 100644 test/test.js delete mode 100644 test/test.two_arrays.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 7212d81..0000000 --- a/.gitattributes +++ /dev/null @@ -1,33 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index b0d9a17..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-06-30T22:38:17.465Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ac0b7cd..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a7a7f51..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.9.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 920b304..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 39b1613..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 7ca169c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 8 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "::set-output name=package_name::$name" - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "::set-output name=data::$data" - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v2 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v2 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 128c22e..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,681 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the repository: - push: - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs rm -rf - - git add -A - git commit -m "Remove files" - - git merge -s recursive -X theirs origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch or create new branch tag: - - name: 'Push changes to `deno` branch or create new branch tag' - run: | - SLUG=${{ github.repository }} - VERSION=$(echo ${{ github.ref }} | sed -E -n 's/refs\/tags\/?(v[0-9]+.[0-9]+.[0-9]+).*/\1/p') - if [ -z "$VERSION" ]; then - echo "Workflow job was not triggered by a new tag...." - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - else - echo "Workflow job was triggered by a new tag: $VERSION" - echo "Creating new bundle branch tag of the form $VERSION-deno" - git tag -a $VERSION-deno -m "$VERSION-deno" - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" $VERSION-deno - fi - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs rm -rf - - git add -A - git commit -m "Remove files" - - git merge -s recursive -X theirs origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -291,7 +284,7 @@ console.log( ybuf ); ## 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. +This package is part of [stdlib][stdlib], a standard library 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]. @@ -353,11 +346,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm diff --git a/benchmark/benchmark.dispatch_size.js b/benchmark/benchmark.dispatch_size.js deleted file mode 100644 index 3bd0418..0000000 --- a/benchmark/benchmark.dispatch_size.js +++ /dev/null @@ -1,156 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib/main.js' ); - - -// FUNCTIONS // - -/** -* Evaluates the identity function. -* -* @private -* @param {*} v - value -* @returns {*} input value -*/ -function identity( v ) { - return v; -} - -/** -* Dummy function which throws an error. -* -* @private -* @throws {Error} unexpected error -*/ -function throwError() { - throw new Error( 'unexpected error' ); -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} size - dispatch size -* @returns {Function} benchmark function -*/ -function createBenchmark( size ) { - var types; - var data; - var fcn; - var x; - var y; - var t; - var i; - - types = []; - - // Create dummy types... - for ( i = 0; i < (size-1)*2; i += 2 ) { - t = 'foo' + i; - types.push( t ); - types.push( t ); - } - // Append test types: - types.push( 'float64' ); - types.push( 'float64' ); - - // Define a list of callbacks: - data = []; - for ( i = 0; i < size-1; i++ ) { - data.push( throwError ); - } - // Append a test callback: - data.push( identity ); - - // Create the dispatcher: - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - // Create sample arrays: - x = new Float64Array( 1 ); - y = new Float64Array( x.length ); - - x = ndarray( 'float64', x, [ 1 ], [ 1 ], 0, 'row-major' ); - y = ndarray( 'float64', y, [ 1 ], [ 1 ], 0, 'row-major' ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var z; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x.data[ 0 ] = i; - z = fcn( x, y ); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var size; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - size = pow( 2, i ); - f = createBenchmark( size ); - bench( pkg+':size='+size, f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index a70dc5c..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::fcns_array', function benchmark( b ) { - var types; - var fcns; - var data; - var out; - var i; - - fcns = [ unary ]; - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( fcns, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::fcn_arg', function benchmark( b ) { - var types; - var data; - var out; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( unary, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index d04d051..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch" -click B href "https://github.com/stdlib-js/ndarray-dispatch/tree/main" -click C href "https://github.com/stdlib-js/ndarray-dispatch/tree/production" -click D href "https://github.com/stdlib-js/ndarray-dispatch/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-dispatch/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-dispatch/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch -[production-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 02fe150..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,87 +0,0 @@ - -{{alias}}( fcns, types, data, nargs, nin, nout ) - Returns an ndarray function interface which performs multiple dispatch. - - An ndarray function interface has the following signature: - - f( x, y, ... ) - - where - - - x: ndarray. - - y: ndarray. - - ...: additional ndarrays. - - The number of parameters is derived from `nargs`, the number of input - ndarrays is derived from `nin`, and the number of output ndarrays is derived - from `nout`. - - Parameters - ---------- - fcns: Function|ArrayLikeObject - List of ndarray functions. An ndarray function should have the following - signature: - - f( arrays, data ) - - where - - - arrays: array containing input and output ndarrays. - - data: ndarray function data (e.g., a callback). - - For convenience, a single ndarray function may be provided which will be - invoked whenever the ndarray argument data types match a sequence of - types in `types`. Providing a single ndarray function is particularly - convenient for the case where, regardless of array data types, - traversing arrays remains the same, but the ndarray function `data` - differs (e.g., callbacks which differ based on the array data types). - - types: ArrayLikeObject - One-dimensional list of ndarray argument data types. - - data: ArrayLikeObject|null - ndarray function data (e.g., callbacks). If `null`, a returned ndarray - function interface does **not** provide a `data` argument to an invoked - ndarray function. - - nargs: integer - Total number of ndarray function interface arguments. - - nin: integer - Number of input ndarrays. - - nout: integer - Number of output ndarrays. - - Returns - ------- - fcn: Function - ndarray function interface. - - Examples - -------- - // Define ndarray argument data types: - > var t = [ 'float64', 'float64', 'float32', 'float32' ]; - - // Define a list of ndarray function data (callbacks): - > var d = [ {{alias:@stdlib/math/base/special/abs}}, {{alias:@stdlib/math/base/special/absf}} ]; - - // Create an ndarray function interface for applying unary callbacks: - > var f = {{alias}}( {{alias:@stdlib/ndarray/base/unary}}, t, d, 2, 1, 1 ); - - // Create an input ndarray: - > var xbuf = new {{alias:@stdlib/array/float64}}( [ -1.0, -2.0, -3.0, -4.0 ] ); - > var x = {{alias:@stdlib/ndarray/ctor}}( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Create an output ndarray: - > var ybuf = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 0.0, 0.0 ] ); - > var y = {{alias:@stdlib/ndarray/ctor}}( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Compute the element-wise absolute value: - > f( x, y ); - > ybuf - [ 1.0, 2.0, 3.0, 4.0 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 397185e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,641 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// tslint:disable:max-file-line-count - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import dispatch = require( './index' ); - - -// FUNCTIONS // - -/** -* Nullary callback. -* -* @return input value -*/ -function nullary(): any { - return 5.0; -} - -/** -* Unary callback. -* -* @param x - input value -* @return input value -*/ -function unary( x: any ): any { - return x; -} - -/** -* Binary callback. -* -* @param x - input value -* @param y - input value -* @return output value -*/ -function binary( x: number, y: number ): number { - return x + y; -} - -/** -* Ternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @return output value -*/ -function ternary( x: number, y: number, z: number ): number { - return x + y + z; -} - -/** -* Quaternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @param w - input value -* @return output value -*/ -function quaternary( x: number, y: number, z: number, w: number ): number { - return x + y + z + w; -} - -/** -* Mock `ind2sub` function. -* -* @param shape - dimensions -* @param idx - linear index -* @param opts - options -* @return subscripts -*/ -function ind2sub( shape: ArrayLike, idx: number, opts?: any ): Array { // tslint:disable-line:max-line-length - let out; - let i; - - out = []; - if ( typeof opts === 'object' && opts !== null && opts.order === 'row-major' ) { // tslint:disable-line:max-line-length no-unsafe-any - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } else { - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } - return out; -} - -/** -* Mock ndarray function. -* -* @param arrays - ndarrays -* @param fcn - callback -*/ -function ndarrayFcn( arrays: Array, fcn: ( x: any ) => any ): void { - let xord; - let yord; - let opts; - let sub; - let sh; - let N; - let x; - let y; - let v; - let i; - - x = arrays[ 0 ]; - y = arrays[ 1 ]; - sh = x.shape; - if ( sh.length === 0 ) { - return; - } - N = 1; - for ( i = 0; i < sh.length; i += 1 ) { - N *= sh[ i ]; - } - xord = x.order; - yord = y.order; - opts = { - 'order': '' - }; - opts.order = xord; - for ( i = 0; i < N; i += 1 ) { - // Convert a linear index to subscripts: - opts.order = xord; - sub = ind2sub( sh, i, opts ); - - // Retrieve an element from `x`: - v = x.get.apply( x, sub ); - - // Convert a linear index to subscripts: - opts.order = yord; - sub = ind2sub( sh, i, opts ); - - // Append the result of applying the callback: - sub[ sub.length ] = fcn( v ) as number; - - // Assign the result to an element in `y`: - y.set.apply( y, sub ); - } -} - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a dispatch function... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, 1 ); // $ExpectType Dispatcher - dispatch( [ ndarrayFcn ], types, data, 2, 1, 1 ); // $ExpectType Dispatcher -} - -// The compiler throws an error if the function is provided a first argument which is not either an ndarray function or an array-like object containing ndarray functions... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( '10', types, data, 2, 1, 1 ); // $ExpectError - dispatch( 10, types, data, 2, 1, 1 ); // $ExpectError - dispatch( true, types, data, 2, 1, 1 ); // $ExpectError - dispatch( false, types, data, 2, 1, 1 ); // $ExpectError - dispatch( null, types, data, 2, 1, 1 ); // $ExpectError - dispatch( undefined, types, data, 2, 1, 1 ); // $ExpectError - dispatch( [ '1' ], types, data, 2, 1, 1 ); // $ExpectError - dispatch( {}, types, data, 2, 1, 1 ); // $ExpectError - dispatch( ( x: number ): number => x, types, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object... -{ - const data = [ unary ]; - - dispatch( ndarrayFcn, 10, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, true, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, false, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, null, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, undefined, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, {}, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object or null... -{ - const types = [ 'float64', 'float64' ]; - - dispatch( ndarrayFcn, types, 10, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, true, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, false, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, undefined, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, {}, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, '10', 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, true, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, false, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, null, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, undefined, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, [ '1' ], 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, {}, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, ( x: number ): number => x, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, '10', 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, true, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, false, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, null, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, undefined, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, [ '1' ], 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, {}, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, ( x: number ): number => x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, '10' ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, true ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, false ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, null ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, undefined ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, [ '1' ] ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, {} ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch(); // $ExpectError - dispatch( ndarrayFcn ); // $ExpectError - dispatch( ndarrayFcn, types ); // $ExpectError - dispatch( ndarrayFcn, types, data ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, 1, 0 ); // $ExpectError -} - -// The function returns a dispatch function... -{ - const x = array(); - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const t1 = [ 'float64' ]; - const d1 = [ nullary ]; - const f1 = dispatch( ndarrayFcn, t1, d1, 1, 1, 0 ); - f1( x ); // $ExpectType void | ndarray - - const t2 = [ 'float64', 'float64' ]; - const d2 = [ unary ]; - const f2 = dispatch( ndarrayFcn, t2, d2, 2, 1, 1 ); - f2( x, y ); // $ExpectType void | ndarray - - const t3 = [ 'float64', 'float64', 'float64' ]; - const d3 = [ binary ]; - const f3 = dispatch( ndarrayFcn, t3, d3, 3, 2, 1 ); - f3( x, y, z ); // $ExpectType void | ndarray - - const t4 = [ 'float64', 'float64', 'float64', 'float64' ]; - const d4 = [ ternary ]; - const f4 = dispatch( ndarrayFcn, t4, d4, 4, 3, 1 ); - f4( x, y, z, w ); // $ExpectType void | ndarray - - const t5 = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const d5 = [ quaternary ]; - const f5 = dispatch( ndarrayFcn, t5, d5, 5, 4, 1 ); - f5( x, y, z, w, u ); // $ExpectType void | ndarray -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (1 ndarray)... -{ - const types = [ 'float64' ]; - const data = [ nullary ]; - - const f = dispatch( ndarrayFcn, types, data, 1, 0, 1 ); - f( '10' ); // $ExpectError - f( 10 ); // $ExpectError - f( true ); // $ExpectError - f( false ); // $ExpectError - f( null ); // $ExpectError - f( undefined ); // $ExpectError - f( [ '1' ] ); // $ExpectError - f( {} ); // $ExpectError - f( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( 10, y ); // $ExpectError - f( '10', y ); // $ExpectError - f( true, y ); // $ExpectError - f( false, y ); // $ExpectError - f( null, y ); // $ExpectError - f( undefined, y ); // $ExpectError - f( [ '1' ], y ); // $ExpectError - f( {}, y ); // $ExpectError - f( ( x: number ): number => x, y ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const x = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( x, 10 ); // $ExpectError - f( x, '10' ); // $ExpectError - f( x, true ); // $ExpectError - f( x, false ); // $ExpectError - f( x, null ); // $ExpectError - f( x, undefined ); // $ExpectError - f( x, [ '1' ] ); // $ExpectError - f( x, {} ); // $ExpectError - f( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( 10, y, z ); // $ExpectError - f( '10', y, z ); // $ExpectError - f( true, y, z ); // $ExpectError - f( false, y, z ); // $ExpectError - f( null, y, z ); // $ExpectError - f( undefined, y, z ); // $ExpectError - f( [ '1' ], y, z ); // $ExpectError - f( {}, y, z ); // $ExpectError - f( ( x: number ): number => x, y, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, 10, z ); // $ExpectError - f( x, '10', z ); // $ExpectError - f( x, true, z ); // $ExpectError - f( x, false, z ); // $ExpectError - f( x, null, z ); // $ExpectError - f( x, undefined, z ); // $ExpectError - f( x, [ '1' ], z ); // $ExpectError - f( x, {}, z ); // $ExpectError - f( x, ( x: number ): number => x, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, y, '10' ); // $ExpectError - f( x, y, true ); // $ExpectError - f( x, y, false ); // $ExpectError - f( x, y, null ); // $ExpectError - f( x, y, undefined ); // $ExpectError - f( x, y, [ '1' ] ); // $ExpectError - f( x, y, {} ); // $ExpectError - f( x, y, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( 10, y, z, w ); // $ExpectError - f( '10', y, z, w ); // $ExpectError - f( true, y, z, w ); // $ExpectError - f( false, y, z, w ); // $ExpectError - f( null, y, z, w ); // $ExpectError - f( undefined, y, z, w ); // $ExpectError - f( [ '1' ], y, z, w ); // $ExpectError - f( {}, y, z, w ); // $ExpectError - f( ( x: number ): number => x, y, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, 10, z, w ); // $ExpectError - f( x, '10', z, w ); // $ExpectError - f( x, true, z, w ); // $ExpectError - f( x, false, z, w ); // $ExpectError - f( x, null, z, w ); // $ExpectError - f( x, undefined, z, w ); // $ExpectError - f( x, [ '1' ], z, w ); // $ExpectError - f( x, {}, z, w ); // $ExpectError - f( x, ( x: number ): number => x, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, 10, w ); // $ExpectError - f( x, y, '10', w ); // $ExpectError - f( x, y, true, w ); // $ExpectError - f( x, y, false, w ); // $ExpectError - f( x, y, null, w ); // $ExpectError - f( x, y, undefined, w ); // $ExpectError - f( x, y, [ '1' ], w ); // $ExpectError - f( x, y, {}, w ); // $ExpectError - f( x, y, ( x: number ): number => x, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, z, 10 ); // $ExpectError - f( x, y, z, '10' ); // $ExpectError - f( x, y, z, true ); // $ExpectError - f( x, y, z, false ); // $ExpectError - f( x, y, z, null ); // $ExpectError - f( x, y, z, undefined ); // $ExpectError - f( x, y, z, [ '1' ] ); // $ExpectError - f( x, y, z, {} ); // $ExpectError - f( x, y, z, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( 10, y, z, w, u ); // $ExpectError - f( '10', y, z, w, u ); // $ExpectError - f( true, y, z, w, u ); // $ExpectError - f( false, y, z, w, u ); // $ExpectError - f( null, y, z, w, u ); // $ExpectError - f( undefined, y, z, w, u ); // $ExpectError - f( [ '1' ], y, z, w, u ); // $ExpectError - f( {}, y, z, w, u ); // $ExpectError - f( ( x: number ): number => x, y, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, 10, z, w, u ); // $ExpectError - f( x, '10', z, w, u ); // $ExpectError - f( x, true, z, w, u ); // $ExpectError - f( x, false, z, w, u ); // $ExpectError - f( x, null, z, w, u ); // $ExpectError - f( x, undefined, z, w, u ); // $ExpectError - f( x, [ '1' ], z, w, u ); // $ExpectError - f( x, {}, z, w, u ); // $ExpectError - f( x, ( x: number ): number => x, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, 10, w, u ); // $ExpectError - f( x, y, '10', w, u ); // $ExpectError - f( x, y, true, w, u ); // $ExpectError - f( x, y, false, w, u ); // $ExpectError - f( x, y, null, w, u ); // $ExpectError - f( x, y, undefined, w, u ); // $ExpectError - f( x, y, [ '1' ], w, u ); // $ExpectError - f( x, y, {}, w, u ); // $ExpectError - f( x, y, ( x: number ): number => x, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, 10, u ); // $ExpectError - f( x, y, z, '10', u ); // $ExpectError - f( x, y, z, true, u ); // $ExpectError - f( x, y, z, false, u ); // $ExpectError - f( x, y, z, null, u ); // $ExpectError - f( x, y, z, undefined, u ); // $ExpectError - f( x, y, z, [ '1' ], u ); // $ExpectError - f( x, y, z, {}, u ); // $ExpectError - f( x, y, z, ( x: number ): number => x, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fifth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, w, 10 ); // $ExpectError - f( x, y, z, w, '10' ); // $ExpectError - f( x, y, z, w, true ); // $ExpectError - f( x, y, z, w, false ); // $ExpectError - f( x, y, z, w, null ); // $ExpectError - f( x, y, z, w, undefined ); // $ExpectError - f( x, y, z, w, [ '1' ] ); // $ExpectError - f( x, y, z, w, {} ); // $ExpectError - f( x, y, z, w, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/add.js b/examples/add.js deleted file mode 100644 index 775b711..0000000 --- a/examples/add.js +++ /dev/null @@ -1,121 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var dispatch = require( './../lib' ); - -function add2( arrays ) { - var opts; - var xo; - var yo; - var zo; - var sx; - var sy; - var sz; - var sh; - var N; - var x; - var y; - var z; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - z = arrays[ 2 ]; - xo = x.order; - yo = y.order; - zo = z.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - opts.order = yo; - sy = ind2sub( sh, i, opts ); - v = x.get.apply( x, sx ) + y.get.apply( y, sy ); - - opts.order = zo; - sz = ind2sub( sh, i, opts ); - sz.push( v ); - z.set.apply( z, sz ); - } -} - -var fcns = [ - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2 -]; - -var types = [ - dtypes.float64, dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.int32, dtypes.int32, - dtypes.uint32, dtypes.uint32, dtypes.uint32, - dtypes.int16, dtypes.int16, dtypes.int16, - dtypes.uint16, dtypes.uint16, dtypes.uint16, - dtypes.int8, dtypes.int8, dtypes.int8, - dtypes.uint8, dtypes.uint8, dtypes.uint8, - dtypes.uint8c, dtypes.uint8c, dtypes.uint8c -]; - -var add = dispatch( fcns, types, null, 3, 2, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var zbuf = new Float64Array( xbuf.length ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var z = ndarray( 'float64', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); - -xbuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -ybuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -zbuf = new Int32Array( xbuf.length ); - -x = ndarray( 'int32', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'int32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -z = ndarray( 'int32', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); diff --git a/examples/sin.js b/examples/sin.js deleted file mode 100644 index 8cd4871..0000000 --- a/examples/sin.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int8Array = require( '@stdlib/array-int8' ); -var sin = require( '@stdlib/math-base-special-sin' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/strided-dtypes' ); -var dispatch = require( './../lib' ); - -function apply( arrays, fcn ) { - var opts; - var xo; - var yo; - var sx; - var sy; - var sh; - var N; - var x; - var y; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - xo = x.order; - yo = y.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - v = fcn( x.get.apply( x, sx ) ); - - opts.order = yo; - sy = ind2sub( sh, i, opts ); - sy.push( v ); - y.set.apply( y, sy ); - } -} - -var fcns = [ - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply -]; - -var types = [ - dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float64, - dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.float64, - dtypes.uint32, dtypes.float64, - dtypes.int16, dtypes.float64, - dtypes.int16, dtypes.float32, - dtypes.uint16, dtypes.float64, - dtypes.uint16, dtypes.float32, - dtypes.int8, dtypes.float64, - dtypes.int8, dtypes.float32, - dtypes.uint8, dtypes.float64, - dtypes.uint8, dtypes.float32, - dtypes.uint8c, dtypes.float64, - dtypes.uint8c, dtypes.float32 -]; - -var data = [ - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin -]; - -var sine = dispatch( fcns, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); - -xbuf = new Int8Array( [ 1, 2, 3, 4, 5 ] ); -ybuf = new Float32Array( xbuf.length ); - -x = ndarray( 'int8', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'float32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); diff --git a/examples/unary.js b/examples/unary.js deleted file mode 100644 index e9c3fb4..0000000 --- a/examples/unary.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -var unary = require( '@stdlib/ndarray-base-unary' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var dispatch = require( './../lib' ); - -var types = [ 'float64', 'float64' ]; - -var data = [ - abs -]; - -var absolute = dispatch( unary, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -absolute( x, y ); -console.log( ybuf ); -// => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 610167d..e8f79c8 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..3bf42ba --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";function m(r,e,t,i,s,n,o,l,m){var d,a,h,f;for(d=n,h=0;h [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0Mq5s', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0Mq3A', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0Mq5u', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0Mq5v', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0Mq5w', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format( '0Mq0h' ) );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format( '0Mq0i' ) );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format( '0Mq0k' ) );\n\t}\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format( '0Mq0l' ) );\n\t\t\t}\n\t\t\tthrow new Error( format( '0Mq0m' ) );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( v.dtype );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format( '0Mq0p' ) );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n"],"names":["indexOfTypes","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","i","j","dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","push","dtype","slice"],"mappings":";;gvBA6EA,SAASA,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,KAAgBE,EAAGI,GADdE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,EAEP,OAAQ,EChBT,SAASU,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,sFAAuFV,IAErH,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAQ,UAE1B,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAQ,UAE1B,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAQ,eAI1B,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAQ,UAG3B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAQ,UAE1B,OAeA,WACC,IAAIO,EACAC,EACAC,EACAC,EACAC,EACAC,EACA3B,EAGJ,IADAwB,EAAOI,UAAUR,UACHd,EAAQ,CACrB,GAAKkB,EAAOlB,EACX,MAAM,IAAIa,MAAOJ,EAAQ,UAE1B,MAAM,IAAII,MAAOJ,EAAQ,UAI1B,IAFAO,EAAS,GACTC,EAAS,GACHvB,EAAI,EAAGA,EAAIM,EAAON,IAAM,CAE7B,IAAM6B,EADNH,EAAIE,UAAW5B,IAEd,MAAKA,EAAIO,EACF,IAAIO,UAAWC,EAAQ,6EAA8EW,IAErG,IAAIZ,UAAWC,EAAQ,8EAA+EW,IAG9GJ,EAAOQ,KAAMJ,GACbH,EAAOO,KAAMJ,EAAEK,OAMhB,IAHAN,EAAMrC,EAAcsB,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGc,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAIT,UAAWC,EAAQ,UAI7BY,EADIhB,GAGAR,EAAMsB,GAGNpB,EACJsB,EAAGL,EAAQjB,EAAMoB,IAEjBE,EAAGL,GAEJ,GAAc,IAATd,EACJ,OAAOc,EAAQb,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOc,EAAOU,MAAOzB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f9d8aef..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Create an ndarray function interface which performs multiple dispatch. -* -* @module @stdlib/ndarray-dispatch -* -* @example -* var dispatch = require( '@stdlib/ndarray-dispatch' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// MODULES // - -var dispatch = require( './main.js' ); - - -// EXPORTS // - -module.exports = dispatch; diff --git a/lib/index_of_types.js b/lib/index_of_types.js deleted file mode 100644 index fda2297..0000000 --- a/lib/index_of_types.js +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found). -* -* ## Notes -* -* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types). -* - The function assumes that `x` is stored in row-major order. -* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`. -* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value. -* -* @private -* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension) -* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension) -* @param {ArrayLikeObject} x - input two-dimensional reference array -* @param {integer} strideX1 - `x` stride length along first dimension -* @param {integer} strideX2 - `x` stride length along second dimension -* @param {NonNegativeInteger} offsetX - `x` starting index -* @param {ArrayLikeObject} y - search array -* @param {integer} strideY - `y` stride length -* @param {NonNegativeInteger} offsetY - `y` starting index -* @returns {integer} row index (if found) and `-1` otherwise -* -* @example -* // Define a reference array to search: -* var types = [ -* 'float64', 'float64', 'float64', -* 'float32', 'float32', 'float32', -* 'uint32', 'uint32', 'float64', -* 'int32', 'int32', 'float64', -* 'uint16', 'uint16', 'float64', -* 'int16', 'int16', 'float64', -* 'uint8', 'uint8', 'float64', -* 'int8', 'int8', 'float64' -* ]; -* -* // Define reference array dimensions: -* var N = 8; // rows -* var M = 3; // columns -* -* // Define a search array: -* y1 = [ -* 'float32', 'float32', 'float32', -* ]; -* -* // Find the list of types: -* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 ); -* // returns 1 -* -// Define a search array: -* y2 = [ -* 'float32', 'float32', 'float64', -* ]; -* -* // Find the list of types: -* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 ); -* // returns -1 -*/ -function indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len - var ix; - var iy; - var i; - var j; - - // Search for the first row which matches `y`... - ix = offsetX; - for ( i = 0; i < N; i++ ) { - iy = offsetY; - for ( j = 0; j < M; j++ ) { - if ( x[ ix+(j*strideX2) ] !== y[ iy ] ) { - break; - } - iy += strideY; - } - // If we successfully iterated over all columns, then that means we've found a match... - if ( j === M ) { - return i; - } - ix += strideX1; - } - return -1; -} - - -// EXPORTS // - -module.exports = indexOfTypes; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c8218ef..0000000 --- a/lib/main.js +++ /dev/null @@ -1,207 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isFunctionArray = require( '@stdlib/assert-is-function-array' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var indexOfTypes = require( './index_of_types.js' ); - - -// MAIN // - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param {(FunctionArray|Function)} fcns - list of ndarray functions -* @param {Collection} types - one-dimensional list of ndarray argument data types -* @param {(Collection|null)} data - ndarray function data (e.g., callbacks) -* @param {PositiveInteger} nargs - total number of ndarray function interface arguments -* @param {NonNegativeInteger} nin - number of input ndarrays -* @param {NonNegativeInteger} nout - number of output ndarrays -* @throws {TypeError} first argument must be either a function or an array of functions -* @throws {TypeError} second argument must be an array-like object -* @throws {TypeError} third argument must be an array-like object or `null` -* @throws {Error} third and first arguments must have the same number of elements -* @throws {TypeError} fourth argument must be a positive integer -* @throws {TypeError} fifth argument must be a nonnegative integer -* @throws {TypeError} sixth argument must be a nonnegative integer -* @throws {Error} fourth argument must equal the specified number of input and output arrays -* @throws {Error} number of types must match the number of functions times the total number of array arguments for each function -* @throws {Error} interface must accept at least one input and/or output ndarray -* @returns {Function} ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function dispatch( fcns, types, data, nargs, nin, nout ) { - var narrays; - var nfcns; - var fcn; - - if ( isFunction( fcns ) ) { - fcn = fcns; - } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( '0Mq5s', fcns ) ); - } - if ( !isCollection( types ) ) { - throw new TypeError( format( '0Mq3A', types ) ); - } - if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); - } - if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( '0Mq5u', nargs ) ); - } - if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( '0Mq5v', nin ) ); - } - if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( '0Mq5w', nout ) ); - } - narrays = nin + nout; - if ( narrays === 0 ) { - throw new Error( format( '0Mq0h' ) ); - } - if ( nargs !== narrays ) { - throw new Error( format( '0Mq0i' ) ); - } - if ( fcn ) { - nfcns = types.length / narrays; - if ( !isInteger( nfcns ) ) { - throw new Error( format( '0Mq0j' ) ); - } - } else { - nfcns = fcns.length; - if ( types.length !== nfcns*narrays ) { - throw new Error( format( '0Mq0j' ) ); - } - } - if ( data && data.length !== nfcns ) { - throw new Error( format( '0Mq0k' ) ); - } - return dispatcher; - - /** - * ndarray function interface which performs multiple dispatch. - * - * @private - * @param {ndarrayLike} x - ndarray - * @param {...ndarrayLike} args - ndarray arguments - * @throws {Error} insufficient arguments - * @throws {Error} too many arguments - * @throws {TypeError} input array arguments must be ndarray-like objects - * @throws {TypeError} output array arguments must be ndarray-like objects - * @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types - * @returns {(ndarrayLike|Array|void)} destination array(s) - */ - function dispatcher() { - var arrays; - var dtypes; - var argc; - var idx; - var v; - var f; - var i; - - argc = arguments.length; - if ( argc !== nargs ) { - if ( argc < nargs ) { - throw new Error( format( '0Mq0l' ) ); - } - throw new Error( format( '0Mq0m' ) ); - } - arrays = []; - dtypes = []; - for ( i = 0; i < nargs; i++ ) { - v = arguments[ i ]; - if ( !isndarrayLike( v ) ) { - if ( i < nin ) { - throw new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) ); - } else { - throw new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) ); - } - } - arrays.push( v ); - dtypes.push( v.dtype ); - } - // Resolve the ndarray function satisfying the input array types: - idx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len - - // Check whether we were able to successfully resolve an ndarray function: - if ( idx < 0 ) { - throw new TypeError( format( '0Mq0p' ) ); - } - // Retrieve the ndarray function: - if ( fcn ) { - f = fcn; - } else { - f = fcns[ idx ]; - } - // Evaluate the ndarray function: - if ( data ) { - f( arrays, data[ idx ] ); - } else { - f( arrays ); - } - if ( nout === 1 ) { - return arrays[ narrays-1 ]; - } - if ( nout === 0 ) { - return; - } - return arrays.slice( nin ); - } -} - - -// EXPORTS // - -module.exports = dispatch; diff --git a/package.json b/package.json index 9569eb2..aab393c 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Create an ndarray function interface which performs multiple dispatch.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@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-ndarray-like": "^0.0.x", - "@stdlib/assert-is-nonnegative-integer": "^0.0.x", - "@stdlib/assert-is-positive-integer": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/array-int32": "^0.0.x", - "@stdlib/array-int8": "^0.0.x", - "@stdlib/array-uint8": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/math-base-assert-is-nan": "^0.0.x", - "@stdlib/math-base-special-abs": "^0.0.x", - "@stdlib/math-base-special-pow": "^0.0.x", - "@stdlib/math-base-special-sin": "^0.0.x", - "@stdlib/ndarray-base-buffer-dtype": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/ndarray-base-unary": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/ndarray-dtypes": "^0.0.x", - "@stdlib/ndarray-ind2sub": "^0.0.x", - "@stdlib/strided-dtypes": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "ndarray", @@ -97,7 +26,6 @@ "multimethod", "multimethods" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..d4eed99 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/fixtures/binary.js b/test/fixtures/binary.js deleted file mode 100644 index a60dfa2..0000000 --- a/test/fixtures/binary.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Binary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @returns {number} sum -*/ -function binary( x, y ) { - return x + y; -} - - -// EXPORTS // - -module.exports = binary; diff --git a/test/fixtures/fill.js b/test/fixtures/fill.js deleted file mode 100644 index 41b2958..0000000 --- a/test/fixtures/fill.js +++ /dev/null @@ -1,76 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which fills one or more ndarrays. -* -* @private -* @param {*} value - fill value -* @returns {Function} ndarray function -*/ -function fill( value ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - */ - function ndarrayFcn( arrays ) { - var opts; - var sub; - var arr; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - opts = { - 'order': '' - }; - for ( j = 0; j < M; j++ ) { - arr = arrays[ j ]; - opts.order = arrays[ j ].order; - for ( i = 0; i < N; i++ ) { - sub = ind2sub( sh, i, opts ); - sub.push( value ); - arr.set.apply( arr, sub ); - } - } - } -} - - -// EXPORTS // - -module.exports = fill; diff --git a/test/fixtures/foreach.js b/test/fixtures/foreach.js deleted file mode 100644 index a426290..0000000 --- a/test/fixtures/foreach.js +++ /dev/null @@ -1,72 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function forEach( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - fcn.apply( null, args ); - } -} - - -// EXPORTS // - -module.exports = forEach; diff --git a/test/fixtures/map1n.js b/test/fixtures/map1n.js deleted file mode 100644 index 614196b..0000000 --- a/test/fixtures/map1n.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function which maps the return value of a callback to `N` arrays. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function map1N( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var v; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - v = fcn(); - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - sub.push( v ); - arrays[ j ].set.apply( arrays[ j ], sub ); - } - } -} - - -// EXPORTS // - -module.exports = map1N; diff --git a/test/fixtures/nullary.js b/test/fixtures/nullary.js deleted file mode 100644 index 4f22126..0000000 --- a/test/fixtures/nullary.js +++ /dev/null @@ -1,36 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Nullary callback. -* -* @private -* @returns {number} value -*/ -function nullary() { - return 3.0; -} - - -// EXPORTS // - -module.exports = nullary; diff --git a/test/fixtures/quaternary.js b/test/fixtures/quaternary.js deleted file mode 100644 index 548437b..0000000 --- a/test/fixtures/quaternary.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quaternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @returns {number} sum -*/ -function quaternary( x, y, z, w ) { - return x + y + z + w; -} - - -// EXPORTS // - -module.exports = quaternary; diff --git a/test/fixtures/quinary.js b/test/fixtures/quinary.js deleted file mode 100644 index 36068de..0000000 --- a/test/fixtures/quinary.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quinary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @param {number} u - input value -* @returns {number} sum -*/ -function quinary( x, y, z, w, u ) { - return x + y + z + w + u; -} - - -// EXPORTS // - -module.exports = quinary; diff --git a/test/fixtures/sum.js b/test/fixtures/sum.js deleted file mode 100644 index efdbb1b..0000000 --- a/test/fixtures/sum.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which computes the sum across one or more ndarrays. -* -* @private -* @param {Object} ctx - context -* @param {number} ctx.sum - initial sum -* @returns {Function} ndarray function -*/ -function wrapper( ctx ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - * @param {Function} [fcn] - callback - */ - function ndarrayFcn( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var f; - var i; - var j; - - if ( arguments.length > 1 ) { - f = fcn; - } - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - if ( f ) { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - ctx.sum += f.apply( null, args ); - } - } else { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - ctx.sum += arrays[ j ].get.apply( arrays[ j ], sub ); - } - } - } - } -} - - -// EXPORTS // - -module.exports = wrapper; diff --git a/test/fixtures/ternary.js b/test/fixtures/ternary.js deleted file mode 100644 index 0595d5f..0000000 --- a/test/fixtures/ternary.js +++ /dev/null @@ -1,39 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Ternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @returns {number} sum -*/ -function ternary( x, y, z ) { - return x + y + z; -} - - -// EXPORTS // - -module.exports = ternary; diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d6c2c8e..0000000 --- a/test/test.js +++ /dev/null @@ -1,363 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var fill = require( './fixtures/fill.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either a function or an array of functions as a first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( value, types, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object as a second argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided either an array-like object or `null` as a third argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - dispatch( unary, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a positive integer for a fourth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 0, - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a fifth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, value, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a sixth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, 1, value ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function array)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var fcns = [ unary, unary, unary ]; - var data = [ abs, abs, abs ]; - dispatch( fcns, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function argument)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs, abs, abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the length of `data` argument does not match the number of ndarray functions', function test( t ) { - var values; - var i; - - values = [ - [], - [ abs, abs ], - [ abs, abs, abs ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var fcns = [ unary ]; - dispatch( fcns, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the fourth argument is incompatible with the number of input and output ndarrays', function test( t ) { - var values; - var i; - - values = [ - 0, - 1, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of specified input and output ndarrays is zero', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var types = [ 'float64' ]; - dispatch( fill( 3 ), types, null, 1, 0, 0 ); - } -}); - -tape( 'the function returns an ndarray function interface', function test( t ) { - var types; - var data; - var f; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - f = dispatch( unary, types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ unary ], types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( fill( 3 ), types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ fill( 3 ) ], types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.two_arrays.js b/test/test.two_arrays.js deleted file mode 100644 index 071500e..0000000 --- a/test/test.two_arrays.js +++ /dev/null @@ -1,808 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var dtype = require( '@stdlib/ndarray-base-buffer-dtype' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var forEach = require( './fixtures/foreach.js' ); -var map1N = require( './fixtures/map1n.js' ); -var fill = require( './fixtures/fill.js' ); -var sum = require( './fixtures/sum.js' ); - - -// TESTS // - -tape( 'the function returns a function which throws an error if not provided an ndarray for the first argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var ybuf = new Float64Array( 10 ); - var y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( value, y ); - }; - } -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the second argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var xbuf = new Float64Array( 10 ); - var x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( x, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided insufficient arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var f; - var x; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [], - [ x ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided too many arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var ybuf; - var f; - var x; - var y; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [ x, y, y ], - [ x, y, y, y ], - [ x, y, y, y, y ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if unable to resolve a ndarray function supporting the provided array argument data types', function test( t ) { - var values; - var types; - var data; - var xbuf; - var fcn; - var x; - var i; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ abs, abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 4 ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - values = [ - new Uint8Array( 4 ), - new Int32Array( 4 ), - [ 0, 0, 0, 0 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided an array having data type: ' + dtype( values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var y = ndarray( dtype( value ), value, [ value.length ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - }; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only input arrays)', function test( t ) { - var types; - var xbuf; - var ybuf; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only output arrays)', function test( t ) { - var expected; - var types; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only input arrays)', function test( t ) { - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var ctx; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcns = [ - sum( ctx ), - sum( ctx ) - ]; - fcn = dispatch( fcns, types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only output arrays)', function test( t ) { - var expected; - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcns = [ - fill( 3.0 ), - fill( 4.0 ) - ]; - fcn = dispatch( fcns, types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - - fcn = dispatch( forEach, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - - fcn = dispatch( map1N, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - fcns = [ - forEach, - forEach - ]; - fcn = dispatch( fcns, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - fcns = [ - map1N, - map1N - ]; - fcn = dispatch( fcns, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - fcns = [ - unary, - unary - ]; - fcn = dispatch( fcns, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which returns one or more output arrays, if one or more output arrays is specified, and otherwise returns `undefined`', function test( t ) { - var types; - var data; - var xbuf; - var ybuf; - var out; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - // No output arrays... - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, void 0, 'returns expected value' ); - - // One output array... - data = [ - abs, - abs - ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - fcn = dispatch( fill( 3.0 ), types, null, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - // Two output arrays... - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.end(); -}); From 820c27a314eaf694e5baa682b9b7d85472725680 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 18:14:54 +0000 Subject: [PATCH 005/109] Transform error messages --- lib/main.js | 28 ++++++++++++++-------------- package.json | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/main.js b/lib/main.js index 3d28781..c8218ef 100644 --- a/lib/main.js +++ b/lib/main.js @@ -27,7 +27,7 @@ var isFunctionArray = require( '@stdlib/assert-is-function-array' ); var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var indexOfTypes = require( './index_of_types.js' ); @@ -89,43 +89,43 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { if ( isFunction( fcns ) ) { fcn = fcns; } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) ); + throw new TypeError( format( '0Mq5s', fcns ) ); } if ( !isCollection( types ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) ); + throw new TypeError( format( '0Mq3A', types ) ); } if ( !isCollection( data ) && data !== null ) { throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); } if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) ); + throw new TypeError( format( '0Mq5u', nargs ) ); } if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) ); + throw new TypeError( format( '0Mq5v', nin ) ); } if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) ); + throw new TypeError( format( '0Mq5w', nout ) ); } narrays = nin + nout; if ( narrays === 0 ) { - throw new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' ); + throw new Error( format( '0Mq0h' ) ); } if ( nargs !== narrays ) { - throw new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' ); + throw new Error( format( '0Mq0i' ) ); } if ( fcn ) { nfcns = types.length / narrays; if ( !isInteger( nfcns ) ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format( '0Mq0j' ) ); } } else { nfcns = fcns.length; if ( types.length !== nfcns*narrays ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format( '0Mq0j' ) ); } } if ( data && data.length !== nfcns ) { - throw new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' ); + throw new Error( format( '0Mq0k' ) ); } return dispatcher; @@ -154,9 +154,9 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { argc = arguments.length; if ( argc !== nargs ) { if ( argc < nargs ) { - throw new Error( 'invalid invocation. Insufficient arguments.' ); + throw new Error( format( '0Mq0l' ) ); } - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format( '0Mq0m' ) ); } arrays = []; dtypes = []; @@ -177,7 +177,7 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { // Check whether we were able to successfully resolve an ndarray function: if ( idx < 0 ) { - throw new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' ); + throw new TypeError( format( '0Mq0p' ) ); } // Retrieve the ndarray function: if ( fcn ) { diff --git a/package.json b/package.json index 014d480..9569eb2 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-ndarray-like": "^0.0.x", "@stdlib/assert-is-nonnegative-integer": "^0.0.x", "@stdlib/assert-is-positive-integer": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From e9640c82d717962ed6d421bd81fe0aea0996b30e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Jul 2022 08:41:12 +0000 Subject: [PATCH 006/109] Remove files --- index.d.ts | 334 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 3028 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index e8f79c8..0000000 --- a/index.d.ts +++ /dev/null @@ -1,334 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* ndarray function. -* -* @param arrays - array containing input and output ndarrays -* @param data - ndarray function data (e.g., a callback) -* -* @example -* var numel = require( `@stdlib/ndarray/base/numel` ); -* var ind2sub = require( `@stdlib/ndarray/ind2sub` ); -* -* function ndarrayFcn( arrays, fcn ) { -* var xord; -* var yord; -* var opts; -* var sub; -* var sh; -* var N; -* var x; -* var y; -* var v; -* var i; -* -* x = arrays[ 0 ]; -* y = arrays[ 1 ]; -* sh = x.shape; -* N = numel( sh ); -* if ( N <= 0 ) { -* return; -* } -* xord = x.order; -* yord = y.order; -* opts = {}; -* opts.order = xord; -* for ( i = 0; i < N; i++ ) { -* // Convert a linear index to subscripts: -* opts.order = xord; -* sub = ind2sub( sh, i, opts ); -* -* // Retrieve an element from `x`: -* v = x.get.apply( x, sub ); -* -* // Convert a linear index to subscripts: -* opts.order = yord; -* sub = ind2sub( sh, i, opts ); -* -* // Append the result of applying the callback: -* sub.push( fcn( v ) ); -* -* // Assign the result to an element in `y`: -* y.set.apply( y, sub ); -* } -* } -*/ -type ndarrayFcn = ( arrays: Array, data?: any ) => void; - -/** -* Interface describing an ndarray function dispatcher. -*/ -interface Dispatcher { - /** - * Invokes an ndarray function based on the provided array data type(s). - * - * @param x - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array - * - * @example - * var nullary = require( `@stdlib/ndarray/base/nullary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function value() { - * return 3.14; - * } - * - * var types = [ 'float64' ]; - * var data = [ value ]; - * - * var fcn = dispatch( nullary, types, data, 1, 0, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( 5 ); - * var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x ); - * // xbuf => [ 3.14, 3.14, 3.14, 3.14, 3.14 ] - */ - ( x: ndarray ): ndarray | void; - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var unary = require( `@stdlib/ndarray/base/unary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * var abs = require( `@stdlib/math/base/special/abs` ); - * - * var types = [ 'float64', 'float64' ]; - * var data = [ abs ]; - * - * var fcn = dispatch( unary, types, data, 2, 1, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - * var ybuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y ); - * // ybuf => [ 1.0, 2.0, 3.0 ] - */ - ( x: ndarray, y: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var ternary = require( `@stdlib/ndarray/base/ternary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add2( x, y ) { - * return x + y; - * } - * - * var types = [ 'float64', 'float64', 'float64' ]; - * var data = [ add2 ]; - * - * var fcn = dispatch( ternary, types, data, 3, 2, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z ); - * // zbuf => [ 2.0, 4.0, 6.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quaternary = require( `@stdlib/ndarray/base/quaternary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add3( x, y, z ) { - * return x + y + z; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add3 ]; - * - * var fcn = dispatch( quaternary, types, data, 4, 3, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w ); - * // wbuf => [ 3.0, 6.0, 9.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @param args - ndarray arguments - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quinary = require( `@stdlib/ndarray/base/quinary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add4( x, y, z, w ) { - * return x + y + z + w; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add4 ]; - * - * var fcn = dispatch( quinary, types, data, 5, 4, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ubuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var u = ndarray( 'float64', ubuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w, u ); - * // ubuf => [ 4.0, 8.0, 12.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray, ...args: Array ): ndarray | void; // tslint:disable-line:max-line-length unified-signatures -} - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param fcns - list of ndarray functions -* @param types - one-dimensional list of ndarray argument data types -* @param data - ndarray function data (e.g., callbacks) -* @param nargs - total number of ndarray function interface arguments -* @param nin - number of input ndarrays -* @param nout - number of output ndarrays -* @throws first argument must be either a function or an array of functions -* @throws second argument must be an array-like object -* @throws third argument must be an array-like object or `null` -* @throws third and first arguments must have the same number of elements -* @throws fourth argument must be a positive integer -* @throws fifth argument must be a nonnegative integer -* @throws sixth argument must be a nonnegative integer -* @throws fourth argument must equal the specified number of input and output arrays -* @throws number of types must match the number of functions times the total number of array arguments for each function -* @throws interface must accept at least one input and/or output ndarray -* @returns ndarray function interface -* -* @example -* var unary = require( `@stdlib/ndarray/base/unary` ); -* var abs = require( `@stdlib/math/base/special/abs` ); -* var Float64Array = require( `@stdlib/array/float64` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var fcn = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* fcn( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function dispatch( fcns: ndarrayFcn | ArrayLike, types: ArrayLike, data: ArrayLike | null, nargs: number, nin: number, nout: number ): Dispatcher; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = dispatch; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 3bf42ba..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";function m(r,e,t,i,s,n,o,l,m){var d,a,h,f;for(d=n,h=0;h [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0Mq5s', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0Mq3A', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0Mq5u', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0Mq5v', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0Mq5w', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format( '0Mq0h' ) );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format( '0Mq0i' ) );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format( '0Mq0k' ) );\n\t}\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format( '0Mq0l' ) );\n\t\t\t}\n\t\t\tthrow new Error( format( '0Mq0m' ) );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( v.dtype );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format( '0Mq0p' ) );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n"],"names":["indexOfTypes","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","i","j","dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","push","dtype","slice"],"mappings":";;gvBA6EA,SAASA,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,KAAgBE,EAAGI,GADdE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,EAEP,OAAQ,EChBT,SAASU,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,sFAAuFV,IAErH,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAQ,UAE1B,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAQ,UAE1B,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAQ,eAI1B,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAQ,UAG3B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAQ,UAE1B,OAeA,WACC,IAAIO,EACAC,EACAC,EACAC,EACAC,EACAC,EACA3B,EAGJ,IADAwB,EAAOI,UAAUR,UACHd,EAAQ,CACrB,GAAKkB,EAAOlB,EACX,MAAM,IAAIa,MAAOJ,EAAQ,UAE1B,MAAM,IAAII,MAAOJ,EAAQ,UAI1B,IAFAO,EAAS,GACTC,EAAS,GACHvB,EAAI,EAAGA,EAAIM,EAAON,IAAM,CAE7B,IAAM6B,EADNH,EAAIE,UAAW5B,IAEd,MAAKA,EAAIO,EACF,IAAIO,UAAWC,EAAQ,6EAA8EW,IAErG,IAAIZ,UAAWC,EAAQ,8EAA+EW,IAG9GJ,EAAOQ,KAAMJ,GACbH,EAAOO,KAAMJ,EAAEK,OAMhB,IAHAN,EAAMrC,EAAcsB,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGc,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAIT,UAAWC,EAAQ,UAI7BY,EADIhB,GAGAR,EAAMsB,GAGNpB,EACJsB,EAAGL,EAAQjB,EAAMoB,IAEjBE,EAAGL,GAEJ,GAAc,IAATd,EACJ,OAAOc,EAAQb,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOc,EAAOU,MAAOzB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d4eed99..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 969974faddfffa948bba9967af623f28bb90dca2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Jul 2022 08:41:55 +0000 Subject: [PATCH 007/109] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 33 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 681 ------ .github/workflows/publish.yml | 157 -- .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 59 +- benchmark/benchmark.dispatch_size.js | 156 -- benchmark/benchmark.js | 81 - branches.md | 53 - docs/repl.txt | 87 - docs/types/test.ts | 641 ----- examples/add.js | 121 - examples/sin.js | 142 -- examples/unary.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/index_of_types.js | 106 - lib/main.js | 207 -- package.json | 76 +- stats.html | 2689 +++++++++++++++++++++ test/fixtures/binary.js | 38 - test/fixtures/fill.js | 76 - test/fixtures/foreach.js | 72 - test/fixtures/map1n.js | 74 - test/fixtures/nullary.js | 36 - test/fixtures/quaternary.js | 40 - test/fixtures/quinary.js | 41 - test/fixtures/sum.js | 98 - test/fixtures/ternary.js | 39 - test/test.js | 363 --- test/test.two_arrays.js | 808 ------- 51 files changed, 2723 insertions(+), 6341 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.dispatch_size.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/add.js delete mode 100644 examples/sin.js delete mode 100644 examples/unary.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/index_of_types.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/fixtures/binary.js delete mode 100644 test/fixtures/fill.js delete mode 100644 test/fixtures/foreach.js delete mode 100644 test/fixtures/map1n.js delete mode 100644 test/fixtures/nullary.js delete mode 100644 test/fixtures/quaternary.js delete mode 100644 test/fixtures/quinary.js delete mode 100644 test/fixtures/sum.js delete mode 100644 test/fixtures/ternary.js delete mode 100644 test/test.js delete mode 100644 test/test.two_arrays.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 7212d81..0000000 --- a/.gitattributes +++ /dev/null @@ -1,33 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 43366a3..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-07-01T01:32:24.445Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ac0b7cd..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a7a7f51..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.9.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 920b304..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 39b1613..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 7ca169c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 8 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "::set-output name=package_name::$name" - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "::set-output name=data::$data" - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v2 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v2 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 128c22e..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,681 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the repository: - push: - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs rm -rf - - git add -A - git commit -m "Remove files" - - git merge -s recursive -X theirs origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch or create new branch tag: - - name: 'Push changes to `deno` branch or create new branch tag' - run: | - SLUG=${{ github.repository }} - VERSION=$(echo ${{ github.ref }} | sed -E -n 's/refs\/tags\/?(v[0-9]+.[0-9]+.[0-9]+).*/\1/p') - if [ -z "$VERSION" ]; then - echo "Workflow job was not triggered by a new tag...." - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - else - echo "Workflow job was triggered by a new tag: $VERSION" - echo "Creating new bundle branch tag of the form $VERSION-deno" - git tag -a $VERSION-deno -m "$VERSION-deno" - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" $VERSION-deno - fi - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs rm -rf - - git add -A - git commit -m "Remove files" - - git merge -s recursive -X theirs origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -291,7 +284,7 @@ console.log( ybuf ); ## 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. +This package is part of [stdlib][stdlib], a standard library 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]. @@ -353,11 +346,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm diff --git a/benchmark/benchmark.dispatch_size.js b/benchmark/benchmark.dispatch_size.js deleted file mode 100644 index 3bd0418..0000000 --- a/benchmark/benchmark.dispatch_size.js +++ /dev/null @@ -1,156 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib/main.js' ); - - -// FUNCTIONS // - -/** -* Evaluates the identity function. -* -* @private -* @param {*} v - value -* @returns {*} input value -*/ -function identity( v ) { - return v; -} - -/** -* Dummy function which throws an error. -* -* @private -* @throws {Error} unexpected error -*/ -function throwError() { - throw new Error( 'unexpected error' ); -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} size - dispatch size -* @returns {Function} benchmark function -*/ -function createBenchmark( size ) { - var types; - var data; - var fcn; - var x; - var y; - var t; - var i; - - types = []; - - // Create dummy types... - for ( i = 0; i < (size-1)*2; i += 2 ) { - t = 'foo' + i; - types.push( t ); - types.push( t ); - } - // Append test types: - types.push( 'float64' ); - types.push( 'float64' ); - - // Define a list of callbacks: - data = []; - for ( i = 0; i < size-1; i++ ) { - data.push( throwError ); - } - // Append a test callback: - data.push( identity ); - - // Create the dispatcher: - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - // Create sample arrays: - x = new Float64Array( 1 ); - y = new Float64Array( x.length ); - - x = ndarray( 'float64', x, [ 1 ], [ 1 ], 0, 'row-major' ); - y = ndarray( 'float64', y, [ 1 ], [ 1 ], 0, 'row-major' ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var z; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x.data[ 0 ] = i; - z = fcn( x, y ); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var size; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - size = pow( 2, i ); - f = createBenchmark( size ); - bench( pkg+':size='+size, f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index a70dc5c..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::fcns_array', function benchmark( b ) { - var types; - var fcns; - var data; - var out; - var i; - - fcns = [ unary ]; - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( fcns, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::fcn_arg', function benchmark( b ) { - var types; - var data; - var out; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( unary, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index d04d051..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch" -click B href "https://github.com/stdlib-js/ndarray-dispatch/tree/main" -click C href "https://github.com/stdlib-js/ndarray-dispatch/tree/production" -click D href "https://github.com/stdlib-js/ndarray-dispatch/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-dispatch/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-dispatch/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch -[production-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 02fe150..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,87 +0,0 @@ - -{{alias}}( fcns, types, data, nargs, nin, nout ) - Returns an ndarray function interface which performs multiple dispatch. - - An ndarray function interface has the following signature: - - f( x, y, ... ) - - where - - - x: ndarray. - - y: ndarray. - - ...: additional ndarrays. - - The number of parameters is derived from `nargs`, the number of input - ndarrays is derived from `nin`, and the number of output ndarrays is derived - from `nout`. - - Parameters - ---------- - fcns: Function|ArrayLikeObject - List of ndarray functions. An ndarray function should have the following - signature: - - f( arrays, data ) - - where - - - arrays: array containing input and output ndarrays. - - data: ndarray function data (e.g., a callback). - - For convenience, a single ndarray function may be provided which will be - invoked whenever the ndarray argument data types match a sequence of - types in `types`. Providing a single ndarray function is particularly - convenient for the case where, regardless of array data types, - traversing arrays remains the same, but the ndarray function `data` - differs (e.g., callbacks which differ based on the array data types). - - types: ArrayLikeObject - One-dimensional list of ndarray argument data types. - - data: ArrayLikeObject|null - ndarray function data (e.g., callbacks). If `null`, a returned ndarray - function interface does **not** provide a `data` argument to an invoked - ndarray function. - - nargs: integer - Total number of ndarray function interface arguments. - - nin: integer - Number of input ndarrays. - - nout: integer - Number of output ndarrays. - - Returns - ------- - fcn: Function - ndarray function interface. - - Examples - -------- - // Define ndarray argument data types: - > var t = [ 'float64', 'float64', 'float32', 'float32' ]; - - // Define a list of ndarray function data (callbacks): - > var d = [ {{alias:@stdlib/math/base/special/abs}}, {{alias:@stdlib/math/base/special/absf}} ]; - - // Create an ndarray function interface for applying unary callbacks: - > var f = {{alias}}( {{alias:@stdlib/ndarray/base/unary}}, t, d, 2, 1, 1 ); - - // Create an input ndarray: - > var xbuf = new {{alias:@stdlib/array/float64}}( [ -1.0, -2.0, -3.0, -4.0 ] ); - > var x = {{alias:@stdlib/ndarray/ctor}}( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Create an output ndarray: - > var ybuf = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 0.0, 0.0 ] ); - > var y = {{alias:@stdlib/ndarray/ctor}}( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Compute the element-wise absolute value: - > f( x, y ); - > ybuf - [ 1.0, 2.0, 3.0, 4.0 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 397185e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,641 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// tslint:disable:max-file-line-count - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import dispatch = require( './index' ); - - -// FUNCTIONS // - -/** -* Nullary callback. -* -* @return input value -*/ -function nullary(): any { - return 5.0; -} - -/** -* Unary callback. -* -* @param x - input value -* @return input value -*/ -function unary( x: any ): any { - return x; -} - -/** -* Binary callback. -* -* @param x - input value -* @param y - input value -* @return output value -*/ -function binary( x: number, y: number ): number { - return x + y; -} - -/** -* Ternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @return output value -*/ -function ternary( x: number, y: number, z: number ): number { - return x + y + z; -} - -/** -* Quaternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @param w - input value -* @return output value -*/ -function quaternary( x: number, y: number, z: number, w: number ): number { - return x + y + z + w; -} - -/** -* Mock `ind2sub` function. -* -* @param shape - dimensions -* @param idx - linear index -* @param opts - options -* @return subscripts -*/ -function ind2sub( shape: ArrayLike, idx: number, opts?: any ): Array { // tslint:disable-line:max-line-length - let out; - let i; - - out = []; - if ( typeof opts === 'object' && opts !== null && opts.order === 'row-major' ) { // tslint:disable-line:max-line-length no-unsafe-any - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } else { - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } - return out; -} - -/** -* Mock ndarray function. -* -* @param arrays - ndarrays -* @param fcn - callback -*/ -function ndarrayFcn( arrays: Array, fcn: ( x: any ) => any ): void { - let xord; - let yord; - let opts; - let sub; - let sh; - let N; - let x; - let y; - let v; - let i; - - x = arrays[ 0 ]; - y = arrays[ 1 ]; - sh = x.shape; - if ( sh.length === 0 ) { - return; - } - N = 1; - for ( i = 0; i < sh.length; i += 1 ) { - N *= sh[ i ]; - } - xord = x.order; - yord = y.order; - opts = { - 'order': '' - }; - opts.order = xord; - for ( i = 0; i < N; i += 1 ) { - // Convert a linear index to subscripts: - opts.order = xord; - sub = ind2sub( sh, i, opts ); - - // Retrieve an element from `x`: - v = x.get.apply( x, sub ); - - // Convert a linear index to subscripts: - opts.order = yord; - sub = ind2sub( sh, i, opts ); - - // Append the result of applying the callback: - sub[ sub.length ] = fcn( v ) as number; - - // Assign the result to an element in `y`: - y.set.apply( y, sub ); - } -} - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a dispatch function... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, 1 ); // $ExpectType Dispatcher - dispatch( [ ndarrayFcn ], types, data, 2, 1, 1 ); // $ExpectType Dispatcher -} - -// The compiler throws an error if the function is provided a first argument which is not either an ndarray function or an array-like object containing ndarray functions... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( '10', types, data, 2, 1, 1 ); // $ExpectError - dispatch( 10, types, data, 2, 1, 1 ); // $ExpectError - dispatch( true, types, data, 2, 1, 1 ); // $ExpectError - dispatch( false, types, data, 2, 1, 1 ); // $ExpectError - dispatch( null, types, data, 2, 1, 1 ); // $ExpectError - dispatch( undefined, types, data, 2, 1, 1 ); // $ExpectError - dispatch( [ '1' ], types, data, 2, 1, 1 ); // $ExpectError - dispatch( {}, types, data, 2, 1, 1 ); // $ExpectError - dispatch( ( x: number ): number => x, types, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object... -{ - const data = [ unary ]; - - dispatch( ndarrayFcn, 10, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, true, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, false, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, null, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, undefined, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, {}, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object or null... -{ - const types = [ 'float64', 'float64' ]; - - dispatch( ndarrayFcn, types, 10, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, true, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, false, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, undefined, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, {}, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, '10', 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, true, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, false, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, null, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, undefined, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, [ '1' ], 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, {}, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, ( x: number ): number => x, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, '10', 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, true, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, false, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, null, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, undefined, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, [ '1' ], 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, {}, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, ( x: number ): number => x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, '10' ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, true ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, false ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, null ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, undefined ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, [ '1' ] ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, {} ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch(); // $ExpectError - dispatch( ndarrayFcn ); // $ExpectError - dispatch( ndarrayFcn, types ); // $ExpectError - dispatch( ndarrayFcn, types, data ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, 1, 0 ); // $ExpectError -} - -// The function returns a dispatch function... -{ - const x = array(); - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const t1 = [ 'float64' ]; - const d1 = [ nullary ]; - const f1 = dispatch( ndarrayFcn, t1, d1, 1, 1, 0 ); - f1( x ); // $ExpectType void | ndarray - - const t2 = [ 'float64', 'float64' ]; - const d2 = [ unary ]; - const f2 = dispatch( ndarrayFcn, t2, d2, 2, 1, 1 ); - f2( x, y ); // $ExpectType void | ndarray - - const t3 = [ 'float64', 'float64', 'float64' ]; - const d3 = [ binary ]; - const f3 = dispatch( ndarrayFcn, t3, d3, 3, 2, 1 ); - f3( x, y, z ); // $ExpectType void | ndarray - - const t4 = [ 'float64', 'float64', 'float64', 'float64' ]; - const d4 = [ ternary ]; - const f4 = dispatch( ndarrayFcn, t4, d4, 4, 3, 1 ); - f4( x, y, z, w ); // $ExpectType void | ndarray - - const t5 = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const d5 = [ quaternary ]; - const f5 = dispatch( ndarrayFcn, t5, d5, 5, 4, 1 ); - f5( x, y, z, w, u ); // $ExpectType void | ndarray -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (1 ndarray)... -{ - const types = [ 'float64' ]; - const data = [ nullary ]; - - const f = dispatch( ndarrayFcn, types, data, 1, 0, 1 ); - f( '10' ); // $ExpectError - f( 10 ); // $ExpectError - f( true ); // $ExpectError - f( false ); // $ExpectError - f( null ); // $ExpectError - f( undefined ); // $ExpectError - f( [ '1' ] ); // $ExpectError - f( {} ); // $ExpectError - f( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( 10, y ); // $ExpectError - f( '10', y ); // $ExpectError - f( true, y ); // $ExpectError - f( false, y ); // $ExpectError - f( null, y ); // $ExpectError - f( undefined, y ); // $ExpectError - f( [ '1' ], y ); // $ExpectError - f( {}, y ); // $ExpectError - f( ( x: number ): number => x, y ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const x = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( x, 10 ); // $ExpectError - f( x, '10' ); // $ExpectError - f( x, true ); // $ExpectError - f( x, false ); // $ExpectError - f( x, null ); // $ExpectError - f( x, undefined ); // $ExpectError - f( x, [ '1' ] ); // $ExpectError - f( x, {} ); // $ExpectError - f( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( 10, y, z ); // $ExpectError - f( '10', y, z ); // $ExpectError - f( true, y, z ); // $ExpectError - f( false, y, z ); // $ExpectError - f( null, y, z ); // $ExpectError - f( undefined, y, z ); // $ExpectError - f( [ '1' ], y, z ); // $ExpectError - f( {}, y, z ); // $ExpectError - f( ( x: number ): number => x, y, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, 10, z ); // $ExpectError - f( x, '10', z ); // $ExpectError - f( x, true, z ); // $ExpectError - f( x, false, z ); // $ExpectError - f( x, null, z ); // $ExpectError - f( x, undefined, z ); // $ExpectError - f( x, [ '1' ], z ); // $ExpectError - f( x, {}, z ); // $ExpectError - f( x, ( x: number ): number => x, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, y, '10' ); // $ExpectError - f( x, y, true ); // $ExpectError - f( x, y, false ); // $ExpectError - f( x, y, null ); // $ExpectError - f( x, y, undefined ); // $ExpectError - f( x, y, [ '1' ] ); // $ExpectError - f( x, y, {} ); // $ExpectError - f( x, y, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( 10, y, z, w ); // $ExpectError - f( '10', y, z, w ); // $ExpectError - f( true, y, z, w ); // $ExpectError - f( false, y, z, w ); // $ExpectError - f( null, y, z, w ); // $ExpectError - f( undefined, y, z, w ); // $ExpectError - f( [ '1' ], y, z, w ); // $ExpectError - f( {}, y, z, w ); // $ExpectError - f( ( x: number ): number => x, y, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, 10, z, w ); // $ExpectError - f( x, '10', z, w ); // $ExpectError - f( x, true, z, w ); // $ExpectError - f( x, false, z, w ); // $ExpectError - f( x, null, z, w ); // $ExpectError - f( x, undefined, z, w ); // $ExpectError - f( x, [ '1' ], z, w ); // $ExpectError - f( x, {}, z, w ); // $ExpectError - f( x, ( x: number ): number => x, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, 10, w ); // $ExpectError - f( x, y, '10', w ); // $ExpectError - f( x, y, true, w ); // $ExpectError - f( x, y, false, w ); // $ExpectError - f( x, y, null, w ); // $ExpectError - f( x, y, undefined, w ); // $ExpectError - f( x, y, [ '1' ], w ); // $ExpectError - f( x, y, {}, w ); // $ExpectError - f( x, y, ( x: number ): number => x, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, z, 10 ); // $ExpectError - f( x, y, z, '10' ); // $ExpectError - f( x, y, z, true ); // $ExpectError - f( x, y, z, false ); // $ExpectError - f( x, y, z, null ); // $ExpectError - f( x, y, z, undefined ); // $ExpectError - f( x, y, z, [ '1' ] ); // $ExpectError - f( x, y, z, {} ); // $ExpectError - f( x, y, z, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( 10, y, z, w, u ); // $ExpectError - f( '10', y, z, w, u ); // $ExpectError - f( true, y, z, w, u ); // $ExpectError - f( false, y, z, w, u ); // $ExpectError - f( null, y, z, w, u ); // $ExpectError - f( undefined, y, z, w, u ); // $ExpectError - f( [ '1' ], y, z, w, u ); // $ExpectError - f( {}, y, z, w, u ); // $ExpectError - f( ( x: number ): number => x, y, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, 10, z, w, u ); // $ExpectError - f( x, '10', z, w, u ); // $ExpectError - f( x, true, z, w, u ); // $ExpectError - f( x, false, z, w, u ); // $ExpectError - f( x, null, z, w, u ); // $ExpectError - f( x, undefined, z, w, u ); // $ExpectError - f( x, [ '1' ], z, w, u ); // $ExpectError - f( x, {}, z, w, u ); // $ExpectError - f( x, ( x: number ): number => x, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, 10, w, u ); // $ExpectError - f( x, y, '10', w, u ); // $ExpectError - f( x, y, true, w, u ); // $ExpectError - f( x, y, false, w, u ); // $ExpectError - f( x, y, null, w, u ); // $ExpectError - f( x, y, undefined, w, u ); // $ExpectError - f( x, y, [ '1' ], w, u ); // $ExpectError - f( x, y, {}, w, u ); // $ExpectError - f( x, y, ( x: number ): number => x, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, 10, u ); // $ExpectError - f( x, y, z, '10', u ); // $ExpectError - f( x, y, z, true, u ); // $ExpectError - f( x, y, z, false, u ); // $ExpectError - f( x, y, z, null, u ); // $ExpectError - f( x, y, z, undefined, u ); // $ExpectError - f( x, y, z, [ '1' ], u ); // $ExpectError - f( x, y, z, {}, u ); // $ExpectError - f( x, y, z, ( x: number ): number => x, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fifth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, w, 10 ); // $ExpectError - f( x, y, z, w, '10' ); // $ExpectError - f( x, y, z, w, true ); // $ExpectError - f( x, y, z, w, false ); // $ExpectError - f( x, y, z, w, null ); // $ExpectError - f( x, y, z, w, undefined ); // $ExpectError - f( x, y, z, w, [ '1' ] ); // $ExpectError - f( x, y, z, w, {} ); // $ExpectError - f( x, y, z, w, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/add.js b/examples/add.js deleted file mode 100644 index 775b711..0000000 --- a/examples/add.js +++ /dev/null @@ -1,121 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var dispatch = require( './../lib' ); - -function add2( arrays ) { - var opts; - var xo; - var yo; - var zo; - var sx; - var sy; - var sz; - var sh; - var N; - var x; - var y; - var z; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - z = arrays[ 2 ]; - xo = x.order; - yo = y.order; - zo = z.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - opts.order = yo; - sy = ind2sub( sh, i, opts ); - v = x.get.apply( x, sx ) + y.get.apply( y, sy ); - - opts.order = zo; - sz = ind2sub( sh, i, opts ); - sz.push( v ); - z.set.apply( z, sz ); - } -} - -var fcns = [ - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2 -]; - -var types = [ - dtypes.float64, dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.int32, dtypes.int32, - dtypes.uint32, dtypes.uint32, dtypes.uint32, - dtypes.int16, dtypes.int16, dtypes.int16, - dtypes.uint16, dtypes.uint16, dtypes.uint16, - dtypes.int8, dtypes.int8, dtypes.int8, - dtypes.uint8, dtypes.uint8, dtypes.uint8, - dtypes.uint8c, dtypes.uint8c, dtypes.uint8c -]; - -var add = dispatch( fcns, types, null, 3, 2, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var zbuf = new Float64Array( xbuf.length ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var z = ndarray( 'float64', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); - -xbuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -ybuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -zbuf = new Int32Array( xbuf.length ); - -x = ndarray( 'int32', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'int32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -z = ndarray( 'int32', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); diff --git a/examples/sin.js b/examples/sin.js deleted file mode 100644 index 8cd4871..0000000 --- a/examples/sin.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int8Array = require( '@stdlib/array-int8' ); -var sin = require( '@stdlib/math-base-special-sin' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/strided-dtypes' ); -var dispatch = require( './../lib' ); - -function apply( arrays, fcn ) { - var opts; - var xo; - var yo; - var sx; - var sy; - var sh; - var N; - var x; - var y; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - xo = x.order; - yo = y.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - v = fcn( x.get.apply( x, sx ) ); - - opts.order = yo; - sy = ind2sub( sh, i, opts ); - sy.push( v ); - y.set.apply( y, sy ); - } -} - -var fcns = [ - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply -]; - -var types = [ - dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float64, - dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.float64, - dtypes.uint32, dtypes.float64, - dtypes.int16, dtypes.float64, - dtypes.int16, dtypes.float32, - dtypes.uint16, dtypes.float64, - dtypes.uint16, dtypes.float32, - dtypes.int8, dtypes.float64, - dtypes.int8, dtypes.float32, - dtypes.uint8, dtypes.float64, - dtypes.uint8, dtypes.float32, - dtypes.uint8c, dtypes.float64, - dtypes.uint8c, dtypes.float32 -]; - -var data = [ - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin -]; - -var sine = dispatch( fcns, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); - -xbuf = new Int8Array( [ 1, 2, 3, 4, 5 ] ); -ybuf = new Float32Array( xbuf.length ); - -x = ndarray( 'int8', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'float32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); diff --git a/examples/unary.js b/examples/unary.js deleted file mode 100644 index e9c3fb4..0000000 --- a/examples/unary.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -var unary = require( '@stdlib/ndarray-base-unary' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var dispatch = require( './../lib' ); - -var types = [ 'float64', 'float64' ]; - -var data = [ - abs -]; - -var absolute = dispatch( unary, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -absolute( x, y ); -console.log( ybuf ); -// => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 610167d..e8f79c8 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..3bf42ba --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";function m(r,e,t,i,s,n,o,l,m){var d,a,h,f;for(d=n,h=0;h [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0Mq5s', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0Mq3A', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0Mq5u', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0Mq5v', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0Mq5w', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format( '0Mq0h' ) );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format( '0Mq0i' ) );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format( '0Mq0k' ) );\n\t}\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format( '0Mq0l' ) );\n\t\t\t}\n\t\t\tthrow new Error( format( '0Mq0m' ) );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( v.dtype );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format( '0Mq0p' ) );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n"],"names":["indexOfTypes","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","i","j","dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","push","dtype","slice"],"mappings":";;gvBA6EA,SAASA,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,KAAgBE,EAAGI,GADdE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,EAEP,OAAQ,EChBT,SAASU,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,sFAAuFV,IAErH,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAQ,UAE1B,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAQ,UAE1B,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAQ,eAI1B,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAQ,UAG3B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAQ,UAE1B,OAeA,WACC,IAAIO,EACAC,EACAC,EACAC,EACAC,EACAC,EACA3B,EAGJ,IADAwB,EAAOI,UAAUR,UACHd,EAAQ,CACrB,GAAKkB,EAAOlB,EACX,MAAM,IAAIa,MAAOJ,EAAQ,UAE1B,MAAM,IAAII,MAAOJ,EAAQ,UAI1B,IAFAO,EAAS,GACTC,EAAS,GACHvB,EAAI,EAAGA,EAAIM,EAAON,IAAM,CAE7B,IAAM6B,EADNH,EAAIE,UAAW5B,IAEd,MAAKA,EAAIO,EACF,IAAIO,UAAWC,EAAQ,6EAA8EW,IAErG,IAAIZ,UAAWC,EAAQ,8EAA+EW,IAG9GJ,EAAOQ,KAAMJ,GACbH,EAAOO,KAAMJ,EAAEK,OAMhB,IAHAN,EAAMrC,EAAcsB,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGc,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAIT,UAAWC,EAAQ,UAI7BY,EADIhB,GAGAR,EAAMsB,GAGNpB,EACJsB,EAAGL,EAAQjB,EAAMoB,IAEjBE,EAAGL,GAEJ,GAAc,IAATd,EACJ,OAAOc,EAAQb,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOc,EAAOU,MAAOzB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f9d8aef..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Create an ndarray function interface which performs multiple dispatch. -* -* @module @stdlib/ndarray-dispatch -* -* @example -* var dispatch = require( '@stdlib/ndarray-dispatch' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// MODULES // - -var dispatch = require( './main.js' ); - - -// EXPORTS // - -module.exports = dispatch; diff --git a/lib/index_of_types.js b/lib/index_of_types.js deleted file mode 100644 index fda2297..0000000 --- a/lib/index_of_types.js +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found). -* -* ## Notes -* -* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types). -* - The function assumes that `x` is stored in row-major order. -* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`. -* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value. -* -* @private -* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension) -* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension) -* @param {ArrayLikeObject} x - input two-dimensional reference array -* @param {integer} strideX1 - `x` stride length along first dimension -* @param {integer} strideX2 - `x` stride length along second dimension -* @param {NonNegativeInteger} offsetX - `x` starting index -* @param {ArrayLikeObject} y - search array -* @param {integer} strideY - `y` stride length -* @param {NonNegativeInteger} offsetY - `y` starting index -* @returns {integer} row index (if found) and `-1` otherwise -* -* @example -* // Define a reference array to search: -* var types = [ -* 'float64', 'float64', 'float64', -* 'float32', 'float32', 'float32', -* 'uint32', 'uint32', 'float64', -* 'int32', 'int32', 'float64', -* 'uint16', 'uint16', 'float64', -* 'int16', 'int16', 'float64', -* 'uint8', 'uint8', 'float64', -* 'int8', 'int8', 'float64' -* ]; -* -* // Define reference array dimensions: -* var N = 8; // rows -* var M = 3; // columns -* -* // Define a search array: -* y1 = [ -* 'float32', 'float32', 'float32', -* ]; -* -* // Find the list of types: -* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 ); -* // returns 1 -* -// Define a search array: -* y2 = [ -* 'float32', 'float32', 'float64', -* ]; -* -* // Find the list of types: -* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 ); -* // returns -1 -*/ -function indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len - var ix; - var iy; - var i; - var j; - - // Search for the first row which matches `y`... - ix = offsetX; - for ( i = 0; i < N; i++ ) { - iy = offsetY; - for ( j = 0; j < M; j++ ) { - if ( x[ ix+(j*strideX2) ] !== y[ iy ] ) { - break; - } - iy += strideY; - } - // If we successfully iterated over all columns, then that means we've found a match... - if ( j === M ) { - return i; - } - ix += strideX1; - } - return -1; -} - - -// EXPORTS // - -module.exports = indexOfTypes; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c8218ef..0000000 --- a/lib/main.js +++ /dev/null @@ -1,207 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isFunctionArray = require( '@stdlib/assert-is-function-array' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var indexOfTypes = require( './index_of_types.js' ); - - -// MAIN // - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param {(FunctionArray|Function)} fcns - list of ndarray functions -* @param {Collection} types - one-dimensional list of ndarray argument data types -* @param {(Collection|null)} data - ndarray function data (e.g., callbacks) -* @param {PositiveInteger} nargs - total number of ndarray function interface arguments -* @param {NonNegativeInteger} nin - number of input ndarrays -* @param {NonNegativeInteger} nout - number of output ndarrays -* @throws {TypeError} first argument must be either a function or an array of functions -* @throws {TypeError} second argument must be an array-like object -* @throws {TypeError} third argument must be an array-like object or `null` -* @throws {Error} third and first arguments must have the same number of elements -* @throws {TypeError} fourth argument must be a positive integer -* @throws {TypeError} fifth argument must be a nonnegative integer -* @throws {TypeError} sixth argument must be a nonnegative integer -* @throws {Error} fourth argument must equal the specified number of input and output arrays -* @throws {Error} number of types must match the number of functions times the total number of array arguments for each function -* @throws {Error} interface must accept at least one input and/or output ndarray -* @returns {Function} ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function dispatch( fcns, types, data, nargs, nin, nout ) { - var narrays; - var nfcns; - var fcn; - - if ( isFunction( fcns ) ) { - fcn = fcns; - } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( '0Mq5s', fcns ) ); - } - if ( !isCollection( types ) ) { - throw new TypeError( format( '0Mq3A', types ) ); - } - if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); - } - if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( '0Mq5u', nargs ) ); - } - if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( '0Mq5v', nin ) ); - } - if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( '0Mq5w', nout ) ); - } - narrays = nin + nout; - if ( narrays === 0 ) { - throw new Error( format( '0Mq0h' ) ); - } - if ( nargs !== narrays ) { - throw new Error( format( '0Mq0i' ) ); - } - if ( fcn ) { - nfcns = types.length / narrays; - if ( !isInteger( nfcns ) ) { - throw new Error( format( '0Mq0j' ) ); - } - } else { - nfcns = fcns.length; - if ( types.length !== nfcns*narrays ) { - throw new Error( format( '0Mq0j' ) ); - } - } - if ( data && data.length !== nfcns ) { - throw new Error( format( '0Mq0k' ) ); - } - return dispatcher; - - /** - * ndarray function interface which performs multiple dispatch. - * - * @private - * @param {ndarrayLike} x - ndarray - * @param {...ndarrayLike} args - ndarray arguments - * @throws {Error} insufficient arguments - * @throws {Error} too many arguments - * @throws {TypeError} input array arguments must be ndarray-like objects - * @throws {TypeError} output array arguments must be ndarray-like objects - * @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types - * @returns {(ndarrayLike|Array|void)} destination array(s) - */ - function dispatcher() { - var arrays; - var dtypes; - var argc; - var idx; - var v; - var f; - var i; - - argc = arguments.length; - if ( argc !== nargs ) { - if ( argc < nargs ) { - throw new Error( format( '0Mq0l' ) ); - } - throw new Error( format( '0Mq0m' ) ); - } - arrays = []; - dtypes = []; - for ( i = 0; i < nargs; i++ ) { - v = arguments[ i ]; - if ( !isndarrayLike( v ) ) { - if ( i < nin ) { - throw new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) ); - } else { - throw new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) ); - } - } - arrays.push( v ); - dtypes.push( v.dtype ); - } - // Resolve the ndarray function satisfying the input array types: - idx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len - - // Check whether we were able to successfully resolve an ndarray function: - if ( idx < 0 ) { - throw new TypeError( format( '0Mq0p' ) ); - } - // Retrieve the ndarray function: - if ( fcn ) { - f = fcn; - } else { - f = fcns[ idx ]; - } - // Evaluate the ndarray function: - if ( data ) { - f( arrays, data[ idx ] ); - } else { - f( arrays ); - } - if ( nout === 1 ) { - return arrays[ narrays-1 ]; - } - if ( nout === 0 ) { - return; - } - return arrays.slice( nin ); - } -} - - -// EXPORTS // - -module.exports = dispatch; diff --git a/package.json b/package.json index 9569eb2..aab393c 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Create an ndarray function interface which performs multiple dispatch.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@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-ndarray-like": "^0.0.x", - "@stdlib/assert-is-nonnegative-integer": "^0.0.x", - "@stdlib/assert-is-positive-integer": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/array-int32": "^0.0.x", - "@stdlib/array-int8": "^0.0.x", - "@stdlib/array-uint8": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/math-base-assert-is-nan": "^0.0.x", - "@stdlib/math-base-special-abs": "^0.0.x", - "@stdlib/math-base-special-pow": "^0.0.x", - "@stdlib/math-base-special-sin": "^0.0.x", - "@stdlib/ndarray-base-buffer-dtype": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/ndarray-base-unary": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/ndarray-dtypes": "^0.0.x", - "@stdlib/ndarray-ind2sub": "^0.0.x", - "@stdlib/strided-dtypes": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "ndarray", @@ -97,7 +26,6 @@ "multimethod", "multimethods" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..7d3c509 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/fixtures/binary.js b/test/fixtures/binary.js deleted file mode 100644 index a60dfa2..0000000 --- a/test/fixtures/binary.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Binary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @returns {number} sum -*/ -function binary( x, y ) { - return x + y; -} - - -// EXPORTS // - -module.exports = binary; diff --git a/test/fixtures/fill.js b/test/fixtures/fill.js deleted file mode 100644 index 41b2958..0000000 --- a/test/fixtures/fill.js +++ /dev/null @@ -1,76 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which fills one or more ndarrays. -* -* @private -* @param {*} value - fill value -* @returns {Function} ndarray function -*/ -function fill( value ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - */ - function ndarrayFcn( arrays ) { - var opts; - var sub; - var arr; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - opts = { - 'order': '' - }; - for ( j = 0; j < M; j++ ) { - arr = arrays[ j ]; - opts.order = arrays[ j ].order; - for ( i = 0; i < N; i++ ) { - sub = ind2sub( sh, i, opts ); - sub.push( value ); - arr.set.apply( arr, sub ); - } - } - } -} - - -// EXPORTS // - -module.exports = fill; diff --git a/test/fixtures/foreach.js b/test/fixtures/foreach.js deleted file mode 100644 index a426290..0000000 --- a/test/fixtures/foreach.js +++ /dev/null @@ -1,72 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function forEach( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - fcn.apply( null, args ); - } -} - - -// EXPORTS // - -module.exports = forEach; diff --git a/test/fixtures/map1n.js b/test/fixtures/map1n.js deleted file mode 100644 index 614196b..0000000 --- a/test/fixtures/map1n.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function which maps the return value of a callback to `N` arrays. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function map1N( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var v; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - v = fcn(); - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - sub.push( v ); - arrays[ j ].set.apply( arrays[ j ], sub ); - } - } -} - - -// EXPORTS // - -module.exports = map1N; diff --git a/test/fixtures/nullary.js b/test/fixtures/nullary.js deleted file mode 100644 index 4f22126..0000000 --- a/test/fixtures/nullary.js +++ /dev/null @@ -1,36 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Nullary callback. -* -* @private -* @returns {number} value -*/ -function nullary() { - return 3.0; -} - - -// EXPORTS // - -module.exports = nullary; diff --git a/test/fixtures/quaternary.js b/test/fixtures/quaternary.js deleted file mode 100644 index 548437b..0000000 --- a/test/fixtures/quaternary.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quaternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @returns {number} sum -*/ -function quaternary( x, y, z, w ) { - return x + y + z + w; -} - - -// EXPORTS // - -module.exports = quaternary; diff --git a/test/fixtures/quinary.js b/test/fixtures/quinary.js deleted file mode 100644 index 36068de..0000000 --- a/test/fixtures/quinary.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quinary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @param {number} u - input value -* @returns {number} sum -*/ -function quinary( x, y, z, w, u ) { - return x + y + z + w + u; -} - - -// EXPORTS // - -module.exports = quinary; diff --git a/test/fixtures/sum.js b/test/fixtures/sum.js deleted file mode 100644 index efdbb1b..0000000 --- a/test/fixtures/sum.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which computes the sum across one or more ndarrays. -* -* @private -* @param {Object} ctx - context -* @param {number} ctx.sum - initial sum -* @returns {Function} ndarray function -*/ -function wrapper( ctx ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - * @param {Function} [fcn] - callback - */ - function ndarrayFcn( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var f; - var i; - var j; - - if ( arguments.length > 1 ) { - f = fcn; - } - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - if ( f ) { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - ctx.sum += f.apply( null, args ); - } - } else { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - ctx.sum += arrays[ j ].get.apply( arrays[ j ], sub ); - } - } - } - } -} - - -// EXPORTS // - -module.exports = wrapper; diff --git a/test/fixtures/ternary.js b/test/fixtures/ternary.js deleted file mode 100644 index 0595d5f..0000000 --- a/test/fixtures/ternary.js +++ /dev/null @@ -1,39 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Ternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @returns {number} sum -*/ -function ternary( x, y, z ) { - return x + y + z; -} - - -// EXPORTS // - -module.exports = ternary; diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d6c2c8e..0000000 --- a/test/test.js +++ /dev/null @@ -1,363 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var fill = require( './fixtures/fill.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either a function or an array of functions as a first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( value, types, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object as a second argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided either an array-like object or `null` as a third argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - dispatch( unary, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a positive integer for a fourth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 0, - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a fifth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, value, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a sixth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, 1, value ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function array)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var fcns = [ unary, unary, unary ]; - var data = [ abs, abs, abs ]; - dispatch( fcns, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function argument)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs, abs, abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the length of `data` argument does not match the number of ndarray functions', function test( t ) { - var values; - var i; - - values = [ - [], - [ abs, abs ], - [ abs, abs, abs ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var fcns = [ unary ]; - dispatch( fcns, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the fourth argument is incompatible with the number of input and output ndarrays', function test( t ) { - var values; - var i; - - values = [ - 0, - 1, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of specified input and output ndarrays is zero', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var types = [ 'float64' ]; - dispatch( fill( 3 ), types, null, 1, 0, 0 ); - } -}); - -tape( 'the function returns an ndarray function interface', function test( t ) { - var types; - var data; - var f; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - f = dispatch( unary, types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ unary ], types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( fill( 3 ), types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ fill( 3 ) ], types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.two_arrays.js b/test/test.two_arrays.js deleted file mode 100644 index 071500e..0000000 --- a/test/test.two_arrays.js +++ /dev/null @@ -1,808 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var dtype = require( '@stdlib/ndarray-base-buffer-dtype' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var forEach = require( './fixtures/foreach.js' ); -var map1N = require( './fixtures/map1n.js' ); -var fill = require( './fixtures/fill.js' ); -var sum = require( './fixtures/sum.js' ); - - -// TESTS // - -tape( 'the function returns a function which throws an error if not provided an ndarray for the first argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var ybuf = new Float64Array( 10 ); - var y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( value, y ); - }; - } -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the second argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var xbuf = new Float64Array( 10 ); - var x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( x, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided insufficient arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var f; - var x; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [], - [ x ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided too many arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var ybuf; - var f; - var x; - var y; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [ x, y, y ], - [ x, y, y, y ], - [ x, y, y, y, y ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if unable to resolve a ndarray function supporting the provided array argument data types', function test( t ) { - var values; - var types; - var data; - var xbuf; - var fcn; - var x; - var i; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ abs, abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 4 ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - values = [ - new Uint8Array( 4 ), - new Int32Array( 4 ), - [ 0, 0, 0, 0 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided an array having data type: ' + dtype( values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var y = ndarray( dtype( value ), value, [ value.length ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - }; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only input arrays)', function test( t ) { - var types; - var xbuf; - var ybuf; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only output arrays)', function test( t ) { - var expected; - var types; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only input arrays)', function test( t ) { - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var ctx; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcns = [ - sum( ctx ), - sum( ctx ) - ]; - fcn = dispatch( fcns, types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only output arrays)', function test( t ) { - var expected; - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcns = [ - fill( 3.0 ), - fill( 4.0 ) - ]; - fcn = dispatch( fcns, types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - - fcn = dispatch( forEach, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - - fcn = dispatch( map1N, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - fcns = [ - forEach, - forEach - ]; - fcn = dispatch( fcns, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - fcns = [ - map1N, - map1N - ]; - fcn = dispatch( fcns, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - fcns = [ - unary, - unary - ]; - fcn = dispatch( fcns, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which returns one or more output arrays, if one or more output arrays is specified, and otherwise returns `undefined`', function test( t ) { - var types; - var data; - var xbuf; - var ybuf; - var out; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - // No output arrays... - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, void 0, 'returns expected value' ); - - // One output array... - data = [ - abs, - abs - ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - fcn = dispatch( fill( 3.0 ), types, null, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - // Two output arrays... - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.end(); -}); From 3b287a2185e1dcd3cfe8310de7e6748d09948ff0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 6 Jul 2022 18:41:52 +0000 Subject: [PATCH 008/109] Transform error messages --- lib/main.js | 28 ++++++++++++++-------------- package.json | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/main.js b/lib/main.js index 3d28781..c8218ef 100644 --- a/lib/main.js +++ b/lib/main.js @@ -27,7 +27,7 @@ var isFunctionArray = require( '@stdlib/assert-is-function-array' ); var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var indexOfTypes = require( './index_of_types.js' ); @@ -89,43 +89,43 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { if ( isFunction( fcns ) ) { fcn = fcns; } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) ); + throw new TypeError( format( '0Mq5s', fcns ) ); } if ( !isCollection( types ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) ); + throw new TypeError( format( '0Mq3A', types ) ); } if ( !isCollection( data ) && data !== null ) { throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); } if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) ); + throw new TypeError( format( '0Mq5u', nargs ) ); } if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) ); + throw new TypeError( format( '0Mq5v', nin ) ); } if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) ); + throw new TypeError( format( '0Mq5w', nout ) ); } narrays = nin + nout; if ( narrays === 0 ) { - throw new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' ); + throw new Error( format( '0Mq0h' ) ); } if ( nargs !== narrays ) { - throw new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' ); + throw new Error( format( '0Mq0i' ) ); } if ( fcn ) { nfcns = types.length / narrays; if ( !isInteger( nfcns ) ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format( '0Mq0j' ) ); } } else { nfcns = fcns.length; if ( types.length !== nfcns*narrays ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format( '0Mq0j' ) ); } } if ( data && data.length !== nfcns ) { - throw new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' ); + throw new Error( format( '0Mq0k' ) ); } return dispatcher; @@ -154,9 +154,9 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { argc = arguments.length; if ( argc !== nargs ) { if ( argc < nargs ) { - throw new Error( 'invalid invocation. Insufficient arguments.' ); + throw new Error( format( '0Mq0l' ) ); } - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format( '0Mq0m' ) ); } arrays = []; dtypes = []; @@ -177,7 +177,7 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { // Check whether we were able to successfully resolve an ndarray function: if ( idx < 0 ) { - throw new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' ); + throw new TypeError( format( '0Mq0p' ) ); } // Retrieve the ndarray function: if ( fcn ) { diff --git a/package.json b/package.json index 014d480..9569eb2 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-ndarray-like": "^0.0.x", "@stdlib/assert-is-nonnegative-integer": "^0.0.x", "@stdlib/assert-is-positive-integer": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From 17e18012fb74fb2a490228ce0777a825a9869005 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 6 Jul 2022 18:55:59 +0000 Subject: [PATCH 009/109] Remove files --- index.d.ts | 334 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 3028 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index e8f79c8..0000000 --- a/index.d.ts +++ /dev/null @@ -1,334 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* ndarray function. -* -* @param arrays - array containing input and output ndarrays -* @param data - ndarray function data (e.g., a callback) -* -* @example -* var numel = require( `@stdlib/ndarray/base/numel` ); -* var ind2sub = require( `@stdlib/ndarray/ind2sub` ); -* -* function ndarrayFcn( arrays, fcn ) { -* var xord; -* var yord; -* var opts; -* var sub; -* var sh; -* var N; -* var x; -* var y; -* var v; -* var i; -* -* x = arrays[ 0 ]; -* y = arrays[ 1 ]; -* sh = x.shape; -* N = numel( sh ); -* if ( N <= 0 ) { -* return; -* } -* xord = x.order; -* yord = y.order; -* opts = {}; -* opts.order = xord; -* for ( i = 0; i < N; i++ ) { -* // Convert a linear index to subscripts: -* opts.order = xord; -* sub = ind2sub( sh, i, opts ); -* -* // Retrieve an element from `x`: -* v = x.get.apply( x, sub ); -* -* // Convert a linear index to subscripts: -* opts.order = yord; -* sub = ind2sub( sh, i, opts ); -* -* // Append the result of applying the callback: -* sub.push( fcn( v ) ); -* -* // Assign the result to an element in `y`: -* y.set.apply( y, sub ); -* } -* } -*/ -type ndarrayFcn = ( arrays: Array, data?: any ) => void; - -/** -* Interface describing an ndarray function dispatcher. -*/ -interface Dispatcher { - /** - * Invokes an ndarray function based on the provided array data type(s). - * - * @param x - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array - * - * @example - * var nullary = require( `@stdlib/ndarray/base/nullary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function value() { - * return 3.14; - * } - * - * var types = [ 'float64' ]; - * var data = [ value ]; - * - * var fcn = dispatch( nullary, types, data, 1, 0, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( 5 ); - * var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x ); - * // xbuf => [ 3.14, 3.14, 3.14, 3.14, 3.14 ] - */ - ( x: ndarray ): ndarray | void; - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var unary = require( `@stdlib/ndarray/base/unary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * var abs = require( `@stdlib/math/base/special/abs` ); - * - * var types = [ 'float64', 'float64' ]; - * var data = [ abs ]; - * - * var fcn = dispatch( unary, types, data, 2, 1, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - * var ybuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y ); - * // ybuf => [ 1.0, 2.0, 3.0 ] - */ - ( x: ndarray, y: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var ternary = require( `@stdlib/ndarray/base/ternary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add2( x, y ) { - * return x + y; - * } - * - * var types = [ 'float64', 'float64', 'float64' ]; - * var data = [ add2 ]; - * - * var fcn = dispatch( ternary, types, data, 3, 2, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z ); - * // zbuf => [ 2.0, 4.0, 6.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quaternary = require( `@stdlib/ndarray/base/quaternary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add3( x, y, z ) { - * return x + y + z; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add3 ]; - * - * var fcn = dispatch( quaternary, types, data, 4, 3, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w ); - * // wbuf => [ 3.0, 6.0, 9.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @param args - ndarray arguments - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quinary = require( `@stdlib/ndarray/base/quinary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add4( x, y, z, w ) { - * return x + y + z + w; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add4 ]; - * - * var fcn = dispatch( quinary, types, data, 5, 4, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ubuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var u = ndarray( 'float64', ubuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w, u ); - * // ubuf => [ 4.0, 8.0, 12.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray, ...args: Array ): ndarray | void; // tslint:disable-line:max-line-length unified-signatures -} - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param fcns - list of ndarray functions -* @param types - one-dimensional list of ndarray argument data types -* @param data - ndarray function data (e.g., callbacks) -* @param nargs - total number of ndarray function interface arguments -* @param nin - number of input ndarrays -* @param nout - number of output ndarrays -* @throws first argument must be either a function or an array of functions -* @throws second argument must be an array-like object -* @throws third argument must be an array-like object or `null` -* @throws third and first arguments must have the same number of elements -* @throws fourth argument must be a positive integer -* @throws fifth argument must be a nonnegative integer -* @throws sixth argument must be a nonnegative integer -* @throws fourth argument must equal the specified number of input and output arrays -* @throws number of types must match the number of functions times the total number of array arguments for each function -* @throws interface must accept at least one input and/or output ndarray -* @returns ndarray function interface -* -* @example -* var unary = require( `@stdlib/ndarray/base/unary` ); -* var abs = require( `@stdlib/math/base/special/abs` ); -* var Float64Array = require( `@stdlib/array/float64` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var fcn = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* fcn( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function dispatch( fcns: ndarrayFcn | ArrayLike, types: ArrayLike, data: ArrayLike | null, nargs: number, nin: number, nout: number ): Dispatcher; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = dispatch; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 3bf42ba..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";function m(r,e,t,i,s,n,o,l,m){var d,a,h,f;for(d=n,h=0;h [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0Mq5s', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0Mq3A', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0Mq5u', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0Mq5v', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0Mq5w', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format( '0Mq0h' ) );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format( '0Mq0i' ) );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format( '0Mq0k' ) );\n\t}\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format( '0Mq0l' ) );\n\t\t\t}\n\t\t\tthrow new Error( format( '0Mq0m' ) );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( v.dtype );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format( '0Mq0p' ) );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n"],"names":["indexOfTypes","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","i","j","dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","push","dtype","slice"],"mappings":";;gvBA6EA,SAASA,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,KAAgBE,EAAGI,GADdE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,EAEP,OAAQ,EChBT,SAASU,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,sFAAuFV,IAErH,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAQ,UAE1B,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAQ,UAE1B,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAQ,eAI1B,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAQ,UAG3B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAQ,UAE1B,OAeA,WACC,IAAIO,EACAC,EACAC,EACAC,EACAC,EACAC,EACA3B,EAGJ,IADAwB,EAAOI,UAAUR,UACHd,EAAQ,CACrB,GAAKkB,EAAOlB,EACX,MAAM,IAAIa,MAAOJ,EAAQ,UAE1B,MAAM,IAAII,MAAOJ,EAAQ,UAI1B,IAFAO,EAAS,GACTC,EAAS,GACHvB,EAAI,EAAGA,EAAIM,EAAON,IAAM,CAE7B,IAAM6B,EADNH,EAAIE,UAAW5B,IAEd,MAAKA,EAAIO,EACF,IAAIO,UAAWC,EAAQ,6EAA8EW,IAErG,IAAIZ,UAAWC,EAAQ,8EAA+EW,IAG9GJ,EAAOQ,KAAMJ,GACbH,EAAOO,KAAMJ,EAAEK,OAMhB,IAHAN,EAAMrC,EAAcsB,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGc,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAIT,UAAWC,EAAQ,UAI7BY,EADIhB,GAGAR,EAAMsB,GAGNpB,EACJsB,EAAGL,EAAQjB,EAAMoB,IAEjBE,EAAGL,GAEJ,GAAc,IAATd,EACJ,OAAOc,EAAQb,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOc,EAAOU,MAAOzB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 7d3c509..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 028b123d908a3029a412eee741cb49d9301dfa65 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 6 Jul 2022 18:56:54 +0000 Subject: [PATCH 010/109] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 33 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 687 ------ .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 59 +- benchmark/benchmark.dispatch_size.js | 156 -- benchmark/benchmark.js | 81 - branches.md | 53 - docs/repl.txt | 87 - docs/types/test.ts | 641 ----- examples/add.js | 121 - examples/sin.js | 142 -- examples/unary.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/index_of_types.js | 106 - lib/main.js | 207 -- package.json | 76 +- stats.html | 2689 +++++++++++++++++++++ test/fixtures/binary.js | 38 - test/fixtures/fill.js | 76 - test/fixtures/foreach.js | 72 - test/fixtures/map1n.js | 74 - test/fixtures/nullary.js | 36 - test/fixtures/quaternary.js | 40 - test/fixtures/quinary.js | 41 - test/fixtures/sum.js | 98 - test/fixtures/ternary.js | 39 - test/test.js | 363 --- test/test.two_arrays.js | 808 ------- 50 files changed, 2723 insertions(+), 6306 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.dispatch_size.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/add.js delete mode 100644 examples/sin.js delete mode 100644 examples/unary.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/index_of_types.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/fixtures/binary.js delete mode 100644 test/fixtures/fill.js delete mode 100644 test/fixtures/foreach.js delete mode 100644 test/fixtures/map1n.js delete mode 100644 test/fixtures/nullary.js delete mode 100644 test/fixtures/quaternary.js delete mode 100644 test/fixtures/quinary.js delete mode 100644 test/fixtures/sum.js delete mode 100644 test/fixtures/ternary.js delete mode 100644 test/test.js delete mode 100644 test/test.two_arrays.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 7212d81..0000000 --- a/.gitattributes +++ /dev/null @@ -1,33 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ac0b7cd..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a7a7f51..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.9.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 920b304..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 39b1613..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 7ca169c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 8 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "::set-output name=package_name::$name" - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "::set-output name=data::$data" - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v2 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v2 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 6726965..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,687 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the repository: - push: - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch or create new branch tag: - - name: 'Push changes to `deno` branch or create new branch tag' - run: | - SLUG=${{ github.repository }} - VERSION=$(echo ${{ github.ref }} | sed -E -n 's/refs\/tags\/?(v[0-9]+.[0-9]+.[0-9]+).*/\1/p') - if [ -z "$VERSION" ]; then - echo "Workflow job was not triggered by a new tag...." - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - else - echo "Workflow job was triggered by a new tag: $VERSION" - echo "Creating new bundle branch tag of the form $VERSION-deno" - git tag -a $VERSION-deno -m "$VERSION-deno" - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" $VERSION-deno - fi - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -291,7 +284,7 @@ console.log( ybuf ); ## 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. +This package is part of [stdlib][stdlib], a standard library 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]. @@ -353,11 +346,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm diff --git a/benchmark/benchmark.dispatch_size.js b/benchmark/benchmark.dispatch_size.js deleted file mode 100644 index 3bd0418..0000000 --- a/benchmark/benchmark.dispatch_size.js +++ /dev/null @@ -1,156 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib/main.js' ); - - -// FUNCTIONS // - -/** -* Evaluates the identity function. -* -* @private -* @param {*} v - value -* @returns {*} input value -*/ -function identity( v ) { - return v; -} - -/** -* Dummy function which throws an error. -* -* @private -* @throws {Error} unexpected error -*/ -function throwError() { - throw new Error( 'unexpected error' ); -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} size - dispatch size -* @returns {Function} benchmark function -*/ -function createBenchmark( size ) { - var types; - var data; - var fcn; - var x; - var y; - var t; - var i; - - types = []; - - // Create dummy types... - for ( i = 0; i < (size-1)*2; i += 2 ) { - t = 'foo' + i; - types.push( t ); - types.push( t ); - } - // Append test types: - types.push( 'float64' ); - types.push( 'float64' ); - - // Define a list of callbacks: - data = []; - for ( i = 0; i < size-1; i++ ) { - data.push( throwError ); - } - // Append a test callback: - data.push( identity ); - - // Create the dispatcher: - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - // Create sample arrays: - x = new Float64Array( 1 ); - y = new Float64Array( x.length ); - - x = ndarray( 'float64', x, [ 1 ], [ 1 ], 0, 'row-major' ); - y = ndarray( 'float64', y, [ 1 ], [ 1 ], 0, 'row-major' ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var z; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x.data[ 0 ] = i; - z = fcn( x, y ); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var size; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - size = pow( 2, i ); - f = createBenchmark( size ); - bench( pkg+':size='+size, f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index a70dc5c..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::fcns_array', function benchmark( b ) { - var types; - var fcns; - var data; - var out; - var i; - - fcns = [ unary ]; - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( fcns, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::fcn_arg', function benchmark( b ) { - var types; - var data; - var out; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( unary, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index d04d051..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch" -click B href "https://github.com/stdlib-js/ndarray-dispatch/tree/main" -click C href "https://github.com/stdlib-js/ndarray-dispatch/tree/production" -click D href "https://github.com/stdlib-js/ndarray-dispatch/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-dispatch/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-dispatch/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch -[production-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 02fe150..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,87 +0,0 @@ - -{{alias}}( fcns, types, data, nargs, nin, nout ) - Returns an ndarray function interface which performs multiple dispatch. - - An ndarray function interface has the following signature: - - f( x, y, ... ) - - where - - - x: ndarray. - - y: ndarray. - - ...: additional ndarrays. - - The number of parameters is derived from `nargs`, the number of input - ndarrays is derived from `nin`, and the number of output ndarrays is derived - from `nout`. - - Parameters - ---------- - fcns: Function|ArrayLikeObject - List of ndarray functions. An ndarray function should have the following - signature: - - f( arrays, data ) - - where - - - arrays: array containing input and output ndarrays. - - data: ndarray function data (e.g., a callback). - - For convenience, a single ndarray function may be provided which will be - invoked whenever the ndarray argument data types match a sequence of - types in `types`. Providing a single ndarray function is particularly - convenient for the case where, regardless of array data types, - traversing arrays remains the same, but the ndarray function `data` - differs (e.g., callbacks which differ based on the array data types). - - types: ArrayLikeObject - One-dimensional list of ndarray argument data types. - - data: ArrayLikeObject|null - ndarray function data (e.g., callbacks). If `null`, a returned ndarray - function interface does **not** provide a `data` argument to an invoked - ndarray function. - - nargs: integer - Total number of ndarray function interface arguments. - - nin: integer - Number of input ndarrays. - - nout: integer - Number of output ndarrays. - - Returns - ------- - fcn: Function - ndarray function interface. - - Examples - -------- - // Define ndarray argument data types: - > var t = [ 'float64', 'float64', 'float32', 'float32' ]; - - // Define a list of ndarray function data (callbacks): - > var d = [ {{alias:@stdlib/math/base/special/abs}}, {{alias:@stdlib/math/base/special/absf}} ]; - - // Create an ndarray function interface for applying unary callbacks: - > var f = {{alias}}( {{alias:@stdlib/ndarray/base/unary}}, t, d, 2, 1, 1 ); - - // Create an input ndarray: - > var xbuf = new {{alias:@stdlib/array/float64}}( [ -1.0, -2.0, -3.0, -4.0 ] ); - > var x = {{alias:@stdlib/ndarray/ctor}}( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Create an output ndarray: - > var ybuf = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 0.0, 0.0 ] ); - > var y = {{alias:@stdlib/ndarray/ctor}}( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Compute the element-wise absolute value: - > f( x, y ); - > ybuf - [ 1.0, 2.0, 3.0, 4.0 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 397185e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,641 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// tslint:disable:max-file-line-count - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import dispatch = require( './index' ); - - -// FUNCTIONS // - -/** -* Nullary callback. -* -* @return input value -*/ -function nullary(): any { - return 5.0; -} - -/** -* Unary callback. -* -* @param x - input value -* @return input value -*/ -function unary( x: any ): any { - return x; -} - -/** -* Binary callback. -* -* @param x - input value -* @param y - input value -* @return output value -*/ -function binary( x: number, y: number ): number { - return x + y; -} - -/** -* Ternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @return output value -*/ -function ternary( x: number, y: number, z: number ): number { - return x + y + z; -} - -/** -* Quaternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @param w - input value -* @return output value -*/ -function quaternary( x: number, y: number, z: number, w: number ): number { - return x + y + z + w; -} - -/** -* Mock `ind2sub` function. -* -* @param shape - dimensions -* @param idx - linear index -* @param opts - options -* @return subscripts -*/ -function ind2sub( shape: ArrayLike, idx: number, opts?: any ): Array { // tslint:disable-line:max-line-length - let out; - let i; - - out = []; - if ( typeof opts === 'object' && opts !== null && opts.order === 'row-major' ) { // tslint:disable-line:max-line-length no-unsafe-any - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } else { - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } - return out; -} - -/** -* Mock ndarray function. -* -* @param arrays - ndarrays -* @param fcn - callback -*/ -function ndarrayFcn( arrays: Array, fcn: ( x: any ) => any ): void { - let xord; - let yord; - let opts; - let sub; - let sh; - let N; - let x; - let y; - let v; - let i; - - x = arrays[ 0 ]; - y = arrays[ 1 ]; - sh = x.shape; - if ( sh.length === 0 ) { - return; - } - N = 1; - for ( i = 0; i < sh.length; i += 1 ) { - N *= sh[ i ]; - } - xord = x.order; - yord = y.order; - opts = { - 'order': '' - }; - opts.order = xord; - for ( i = 0; i < N; i += 1 ) { - // Convert a linear index to subscripts: - opts.order = xord; - sub = ind2sub( sh, i, opts ); - - // Retrieve an element from `x`: - v = x.get.apply( x, sub ); - - // Convert a linear index to subscripts: - opts.order = yord; - sub = ind2sub( sh, i, opts ); - - // Append the result of applying the callback: - sub[ sub.length ] = fcn( v ) as number; - - // Assign the result to an element in `y`: - y.set.apply( y, sub ); - } -} - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a dispatch function... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, 1 ); // $ExpectType Dispatcher - dispatch( [ ndarrayFcn ], types, data, 2, 1, 1 ); // $ExpectType Dispatcher -} - -// The compiler throws an error if the function is provided a first argument which is not either an ndarray function or an array-like object containing ndarray functions... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( '10', types, data, 2, 1, 1 ); // $ExpectError - dispatch( 10, types, data, 2, 1, 1 ); // $ExpectError - dispatch( true, types, data, 2, 1, 1 ); // $ExpectError - dispatch( false, types, data, 2, 1, 1 ); // $ExpectError - dispatch( null, types, data, 2, 1, 1 ); // $ExpectError - dispatch( undefined, types, data, 2, 1, 1 ); // $ExpectError - dispatch( [ '1' ], types, data, 2, 1, 1 ); // $ExpectError - dispatch( {}, types, data, 2, 1, 1 ); // $ExpectError - dispatch( ( x: number ): number => x, types, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object... -{ - const data = [ unary ]; - - dispatch( ndarrayFcn, 10, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, true, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, false, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, null, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, undefined, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, {}, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object or null... -{ - const types = [ 'float64', 'float64' ]; - - dispatch( ndarrayFcn, types, 10, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, true, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, false, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, undefined, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, {}, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, '10', 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, true, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, false, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, null, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, undefined, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, [ '1' ], 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, {}, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, ( x: number ): number => x, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, '10', 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, true, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, false, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, null, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, undefined, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, [ '1' ], 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, {}, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, ( x: number ): number => x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, '10' ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, true ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, false ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, null ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, undefined ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, [ '1' ] ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, {} ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch(); // $ExpectError - dispatch( ndarrayFcn ); // $ExpectError - dispatch( ndarrayFcn, types ); // $ExpectError - dispatch( ndarrayFcn, types, data ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, 1, 0 ); // $ExpectError -} - -// The function returns a dispatch function... -{ - const x = array(); - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const t1 = [ 'float64' ]; - const d1 = [ nullary ]; - const f1 = dispatch( ndarrayFcn, t1, d1, 1, 1, 0 ); - f1( x ); // $ExpectType void | ndarray - - const t2 = [ 'float64', 'float64' ]; - const d2 = [ unary ]; - const f2 = dispatch( ndarrayFcn, t2, d2, 2, 1, 1 ); - f2( x, y ); // $ExpectType void | ndarray - - const t3 = [ 'float64', 'float64', 'float64' ]; - const d3 = [ binary ]; - const f3 = dispatch( ndarrayFcn, t3, d3, 3, 2, 1 ); - f3( x, y, z ); // $ExpectType void | ndarray - - const t4 = [ 'float64', 'float64', 'float64', 'float64' ]; - const d4 = [ ternary ]; - const f4 = dispatch( ndarrayFcn, t4, d4, 4, 3, 1 ); - f4( x, y, z, w ); // $ExpectType void | ndarray - - const t5 = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const d5 = [ quaternary ]; - const f5 = dispatch( ndarrayFcn, t5, d5, 5, 4, 1 ); - f5( x, y, z, w, u ); // $ExpectType void | ndarray -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (1 ndarray)... -{ - const types = [ 'float64' ]; - const data = [ nullary ]; - - const f = dispatch( ndarrayFcn, types, data, 1, 0, 1 ); - f( '10' ); // $ExpectError - f( 10 ); // $ExpectError - f( true ); // $ExpectError - f( false ); // $ExpectError - f( null ); // $ExpectError - f( undefined ); // $ExpectError - f( [ '1' ] ); // $ExpectError - f( {} ); // $ExpectError - f( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( 10, y ); // $ExpectError - f( '10', y ); // $ExpectError - f( true, y ); // $ExpectError - f( false, y ); // $ExpectError - f( null, y ); // $ExpectError - f( undefined, y ); // $ExpectError - f( [ '1' ], y ); // $ExpectError - f( {}, y ); // $ExpectError - f( ( x: number ): number => x, y ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const x = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( x, 10 ); // $ExpectError - f( x, '10' ); // $ExpectError - f( x, true ); // $ExpectError - f( x, false ); // $ExpectError - f( x, null ); // $ExpectError - f( x, undefined ); // $ExpectError - f( x, [ '1' ] ); // $ExpectError - f( x, {} ); // $ExpectError - f( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( 10, y, z ); // $ExpectError - f( '10', y, z ); // $ExpectError - f( true, y, z ); // $ExpectError - f( false, y, z ); // $ExpectError - f( null, y, z ); // $ExpectError - f( undefined, y, z ); // $ExpectError - f( [ '1' ], y, z ); // $ExpectError - f( {}, y, z ); // $ExpectError - f( ( x: number ): number => x, y, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, 10, z ); // $ExpectError - f( x, '10', z ); // $ExpectError - f( x, true, z ); // $ExpectError - f( x, false, z ); // $ExpectError - f( x, null, z ); // $ExpectError - f( x, undefined, z ); // $ExpectError - f( x, [ '1' ], z ); // $ExpectError - f( x, {}, z ); // $ExpectError - f( x, ( x: number ): number => x, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, y, '10' ); // $ExpectError - f( x, y, true ); // $ExpectError - f( x, y, false ); // $ExpectError - f( x, y, null ); // $ExpectError - f( x, y, undefined ); // $ExpectError - f( x, y, [ '1' ] ); // $ExpectError - f( x, y, {} ); // $ExpectError - f( x, y, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( 10, y, z, w ); // $ExpectError - f( '10', y, z, w ); // $ExpectError - f( true, y, z, w ); // $ExpectError - f( false, y, z, w ); // $ExpectError - f( null, y, z, w ); // $ExpectError - f( undefined, y, z, w ); // $ExpectError - f( [ '1' ], y, z, w ); // $ExpectError - f( {}, y, z, w ); // $ExpectError - f( ( x: number ): number => x, y, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, 10, z, w ); // $ExpectError - f( x, '10', z, w ); // $ExpectError - f( x, true, z, w ); // $ExpectError - f( x, false, z, w ); // $ExpectError - f( x, null, z, w ); // $ExpectError - f( x, undefined, z, w ); // $ExpectError - f( x, [ '1' ], z, w ); // $ExpectError - f( x, {}, z, w ); // $ExpectError - f( x, ( x: number ): number => x, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, 10, w ); // $ExpectError - f( x, y, '10', w ); // $ExpectError - f( x, y, true, w ); // $ExpectError - f( x, y, false, w ); // $ExpectError - f( x, y, null, w ); // $ExpectError - f( x, y, undefined, w ); // $ExpectError - f( x, y, [ '1' ], w ); // $ExpectError - f( x, y, {}, w ); // $ExpectError - f( x, y, ( x: number ): number => x, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, z, 10 ); // $ExpectError - f( x, y, z, '10' ); // $ExpectError - f( x, y, z, true ); // $ExpectError - f( x, y, z, false ); // $ExpectError - f( x, y, z, null ); // $ExpectError - f( x, y, z, undefined ); // $ExpectError - f( x, y, z, [ '1' ] ); // $ExpectError - f( x, y, z, {} ); // $ExpectError - f( x, y, z, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( 10, y, z, w, u ); // $ExpectError - f( '10', y, z, w, u ); // $ExpectError - f( true, y, z, w, u ); // $ExpectError - f( false, y, z, w, u ); // $ExpectError - f( null, y, z, w, u ); // $ExpectError - f( undefined, y, z, w, u ); // $ExpectError - f( [ '1' ], y, z, w, u ); // $ExpectError - f( {}, y, z, w, u ); // $ExpectError - f( ( x: number ): number => x, y, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, 10, z, w, u ); // $ExpectError - f( x, '10', z, w, u ); // $ExpectError - f( x, true, z, w, u ); // $ExpectError - f( x, false, z, w, u ); // $ExpectError - f( x, null, z, w, u ); // $ExpectError - f( x, undefined, z, w, u ); // $ExpectError - f( x, [ '1' ], z, w, u ); // $ExpectError - f( x, {}, z, w, u ); // $ExpectError - f( x, ( x: number ): number => x, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, 10, w, u ); // $ExpectError - f( x, y, '10', w, u ); // $ExpectError - f( x, y, true, w, u ); // $ExpectError - f( x, y, false, w, u ); // $ExpectError - f( x, y, null, w, u ); // $ExpectError - f( x, y, undefined, w, u ); // $ExpectError - f( x, y, [ '1' ], w, u ); // $ExpectError - f( x, y, {}, w, u ); // $ExpectError - f( x, y, ( x: number ): number => x, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, 10, u ); // $ExpectError - f( x, y, z, '10', u ); // $ExpectError - f( x, y, z, true, u ); // $ExpectError - f( x, y, z, false, u ); // $ExpectError - f( x, y, z, null, u ); // $ExpectError - f( x, y, z, undefined, u ); // $ExpectError - f( x, y, z, [ '1' ], u ); // $ExpectError - f( x, y, z, {}, u ); // $ExpectError - f( x, y, z, ( x: number ): number => x, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fifth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, w, 10 ); // $ExpectError - f( x, y, z, w, '10' ); // $ExpectError - f( x, y, z, w, true ); // $ExpectError - f( x, y, z, w, false ); // $ExpectError - f( x, y, z, w, null ); // $ExpectError - f( x, y, z, w, undefined ); // $ExpectError - f( x, y, z, w, [ '1' ] ); // $ExpectError - f( x, y, z, w, {} ); // $ExpectError - f( x, y, z, w, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/add.js b/examples/add.js deleted file mode 100644 index 775b711..0000000 --- a/examples/add.js +++ /dev/null @@ -1,121 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var dispatch = require( './../lib' ); - -function add2( arrays ) { - var opts; - var xo; - var yo; - var zo; - var sx; - var sy; - var sz; - var sh; - var N; - var x; - var y; - var z; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - z = arrays[ 2 ]; - xo = x.order; - yo = y.order; - zo = z.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - opts.order = yo; - sy = ind2sub( sh, i, opts ); - v = x.get.apply( x, sx ) + y.get.apply( y, sy ); - - opts.order = zo; - sz = ind2sub( sh, i, opts ); - sz.push( v ); - z.set.apply( z, sz ); - } -} - -var fcns = [ - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2 -]; - -var types = [ - dtypes.float64, dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.int32, dtypes.int32, - dtypes.uint32, dtypes.uint32, dtypes.uint32, - dtypes.int16, dtypes.int16, dtypes.int16, - dtypes.uint16, dtypes.uint16, dtypes.uint16, - dtypes.int8, dtypes.int8, dtypes.int8, - dtypes.uint8, dtypes.uint8, dtypes.uint8, - dtypes.uint8c, dtypes.uint8c, dtypes.uint8c -]; - -var add = dispatch( fcns, types, null, 3, 2, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var zbuf = new Float64Array( xbuf.length ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var z = ndarray( 'float64', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); - -xbuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -ybuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -zbuf = new Int32Array( xbuf.length ); - -x = ndarray( 'int32', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'int32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -z = ndarray( 'int32', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); diff --git a/examples/sin.js b/examples/sin.js deleted file mode 100644 index 8cd4871..0000000 --- a/examples/sin.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int8Array = require( '@stdlib/array-int8' ); -var sin = require( '@stdlib/math-base-special-sin' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/strided-dtypes' ); -var dispatch = require( './../lib' ); - -function apply( arrays, fcn ) { - var opts; - var xo; - var yo; - var sx; - var sy; - var sh; - var N; - var x; - var y; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - xo = x.order; - yo = y.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - v = fcn( x.get.apply( x, sx ) ); - - opts.order = yo; - sy = ind2sub( sh, i, opts ); - sy.push( v ); - y.set.apply( y, sy ); - } -} - -var fcns = [ - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply -]; - -var types = [ - dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float64, - dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.float64, - dtypes.uint32, dtypes.float64, - dtypes.int16, dtypes.float64, - dtypes.int16, dtypes.float32, - dtypes.uint16, dtypes.float64, - dtypes.uint16, dtypes.float32, - dtypes.int8, dtypes.float64, - dtypes.int8, dtypes.float32, - dtypes.uint8, dtypes.float64, - dtypes.uint8, dtypes.float32, - dtypes.uint8c, dtypes.float64, - dtypes.uint8c, dtypes.float32 -]; - -var data = [ - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin -]; - -var sine = dispatch( fcns, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); - -xbuf = new Int8Array( [ 1, 2, 3, 4, 5 ] ); -ybuf = new Float32Array( xbuf.length ); - -x = ndarray( 'int8', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'float32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); diff --git a/examples/unary.js b/examples/unary.js deleted file mode 100644 index e9c3fb4..0000000 --- a/examples/unary.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -var unary = require( '@stdlib/ndarray-base-unary' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var dispatch = require( './../lib' ); - -var types = [ 'float64', 'float64' ]; - -var data = [ - abs -]; - -var absolute = dispatch( unary, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -absolute( x, y ); -console.log( ybuf ); -// => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 610167d..e8f79c8 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..3bf42ba --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";function m(r,e,t,i,s,n,o,l,m){var d,a,h,f;for(d=n,h=0;h [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0Mq5s', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0Mq3A', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0Mq5u', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0Mq5v', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0Mq5w', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format( '0Mq0h' ) );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format( '0Mq0i' ) );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format( '0Mq0k' ) );\n\t}\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format( '0Mq0l' ) );\n\t\t\t}\n\t\t\tthrow new Error( format( '0Mq0m' ) );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( v.dtype );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format( '0Mq0p' ) );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n"],"names":["indexOfTypes","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","i","j","dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","push","dtype","slice"],"mappings":";;gvBA6EA,SAASA,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,KAAgBE,EAAGI,GADdE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,EAEP,OAAQ,EChBT,SAASU,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,sFAAuFV,IAErH,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAQ,UAE1B,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAQ,UAE1B,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAQ,eAI1B,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAQ,UAG3B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAQ,UAE1B,OAeA,WACC,IAAIO,EACAC,EACAC,EACAC,EACAC,EACAC,EACA3B,EAGJ,IADAwB,EAAOI,UAAUR,UACHd,EAAQ,CACrB,GAAKkB,EAAOlB,EACX,MAAM,IAAIa,MAAOJ,EAAQ,UAE1B,MAAM,IAAII,MAAOJ,EAAQ,UAI1B,IAFAO,EAAS,GACTC,EAAS,GACHvB,EAAI,EAAGA,EAAIM,EAAON,IAAM,CAE7B,IAAM6B,EADNH,EAAIE,UAAW5B,IAEd,MAAKA,EAAIO,EACF,IAAIO,UAAWC,EAAQ,6EAA8EW,IAErG,IAAIZ,UAAWC,EAAQ,8EAA+EW,IAG9GJ,EAAOQ,KAAMJ,GACbH,EAAOO,KAAMJ,EAAEK,OAMhB,IAHAN,EAAMrC,EAAcsB,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGc,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAIT,UAAWC,EAAQ,UAI7BY,EADIhB,GAGAR,EAAMsB,GAGNpB,EACJsB,EAAGL,EAAQjB,EAAMoB,IAEjBE,EAAGL,GAEJ,GAAc,IAATd,EACJ,OAAOc,EAAQb,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOc,EAAOU,MAAOzB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f9d8aef..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Create an ndarray function interface which performs multiple dispatch. -* -* @module @stdlib/ndarray-dispatch -* -* @example -* var dispatch = require( '@stdlib/ndarray-dispatch' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// MODULES // - -var dispatch = require( './main.js' ); - - -// EXPORTS // - -module.exports = dispatch; diff --git a/lib/index_of_types.js b/lib/index_of_types.js deleted file mode 100644 index fda2297..0000000 --- a/lib/index_of_types.js +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found). -* -* ## Notes -* -* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types). -* - The function assumes that `x` is stored in row-major order. -* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`. -* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value. -* -* @private -* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension) -* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension) -* @param {ArrayLikeObject} x - input two-dimensional reference array -* @param {integer} strideX1 - `x` stride length along first dimension -* @param {integer} strideX2 - `x` stride length along second dimension -* @param {NonNegativeInteger} offsetX - `x` starting index -* @param {ArrayLikeObject} y - search array -* @param {integer} strideY - `y` stride length -* @param {NonNegativeInteger} offsetY - `y` starting index -* @returns {integer} row index (if found) and `-1` otherwise -* -* @example -* // Define a reference array to search: -* var types = [ -* 'float64', 'float64', 'float64', -* 'float32', 'float32', 'float32', -* 'uint32', 'uint32', 'float64', -* 'int32', 'int32', 'float64', -* 'uint16', 'uint16', 'float64', -* 'int16', 'int16', 'float64', -* 'uint8', 'uint8', 'float64', -* 'int8', 'int8', 'float64' -* ]; -* -* // Define reference array dimensions: -* var N = 8; // rows -* var M = 3; // columns -* -* // Define a search array: -* y1 = [ -* 'float32', 'float32', 'float32', -* ]; -* -* // Find the list of types: -* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 ); -* // returns 1 -* -// Define a search array: -* y2 = [ -* 'float32', 'float32', 'float64', -* ]; -* -* // Find the list of types: -* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 ); -* // returns -1 -*/ -function indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len - var ix; - var iy; - var i; - var j; - - // Search for the first row which matches `y`... - ix = offsetX; - for ( i = 0; i < N; i++ ) { - iy = offsetY; - for ( j = 0; j < M; j++ ) { - if ( x[ ix+(j*strideX2) ] !== y[ iy ] ) { - break; - } - iy += strideY; - } - // If we successfully iterated over all columns, then that means we've found a match... - if ( j === M ) { - return i; - } - ix += strideX1; - } - return -1; -} - - -// EXPORTS // - -module.exports = indexOfTypes; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c8218ef..0000000 --- a/lib/main.js +++ /dev/null @@ -1,207 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isFunctionArray = require( '@stdlib/assert-is-function-array' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var indexOfTypes = require( './index_of_types.js' ); - - -// MAIN // - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param {(FunctionArray|Function)} fcns - list of ndarray functions -* @param {Collection} types - one-dimensional list of ndarray argument data types -* @param {(Collection|null)} data - ndarray function data (e.g., callbacks) -* @param {PositiveInteger} nargs - total number of ndarray function interface arguments -* @param {NonNegativeInteger} nin - number of input ndarrays -* @param {NonNegativeInteger} nout - number of output ndarrays -* @throws {TypeError} first argument must be either a function or an array of functions -* @throws {TypeError} second argument must be an array-like object -* @throws {TypeError} third argument must be an array-like object or `null` -* @throws {Error} third and first arguments must have the same number of elements -* @throws {TypeError} fourth argument must be a positive integer -* @throws {TypeError} fifth argument must be a nonnegative integer -* @throws {TypeError} sixth argument must be a nonnegative integer -* @throws {Error} fourth argument must equal the specified number of input and output arrays -* @throws {Error} number of types must match the number of functions times the total number of array arguments for each function -* @throws {Error} interface must accept at least one input and/or output ndarray -* @returns {Function} ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function dispatch( fcns, types, data, nargs, nin, nout ) { - var narrays; - var nfcns; - var fcn; - - if ( isFunction( fcns ) ) { - fcn = fcns; - } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( '0Mq5s', fcns ) ); - } - if ( !isCollection( types ) ) { - throw new TypeError( format( '0Mq3A', types ) ); - } - if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); - } - if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( '0Mq5u', nargs ) ); - } - if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( '0Mq5v', nin ) ); - } - if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( '0Mq5w', nout ) ); - } - narrays = nin + nout; - if ( narrays === 0 ) { - throw new Error( format( '0Mq0h' ) ); - } - if ( nargs !== narrays ) { - throw new Error( format( '0Mq0i' ) ); - } - if ( fcn ) { - nfcns = types.length / narrays; - if ( !isInteger( nfcns ) ) { - throw new Error( format( '0Mq0j' ) ); - } - } else { - nfcns = fcns.length; - if ( types.length !== nfcns*narrays ) { - throw new Error( format( '0Mq0j' ) ); - } - } - if ( data && data.length !== nfcns ) { - throw new Error( format( '0Mq0k' ) ); - } - return dispatcher; - - /** - * ndarray function interface which performs multiple dispatch. - * - * @private - * @param {ndarrayLike} x - ndarray - * @param {...ndarrayLike} args - ndarray arguments - * @throws {Error} insufficient arguments - * @throws {Error} too many arguments - * @throws {TypeError} input array arguments must be ndarray-like objects - * @throws {TypeError} output array arguments must be ndarray-like objects - * @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types - * @returns {(ndarrayLike|Array|void)} destination array(s) - */ - function dispatcher() { - var arrays; - var dtypes; - var argc; - var idx; - var v; - var f; - var i; - - argc = arguments.length; - if ( argc !== nargs ) { - if ( argc < nargs ) { - throw new Error( format( '0Mq0l' ) ); - } - throw new Error( format( '0Mq0m' ) ); - } - arrays = []; - dtypes = []; - for ( i = 0; i < nargs; i++ ) { - v = arguments[ i ]; - if ( !isndarrayLike( v ) ) { - if ( i < nin ) { - throw new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) ); - } else { - throw new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) ); - } - } - arrays.push( v ); - dtypes.push( v.dtype ); - } - // Resolve the ndarray function satisfying the input array types: - idx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len - - // Check whether we were able to successfully resolve an ndarray function: - if ( idx < 0 ) { - throw new TypeError( format( '0Mq0p' ) ); - } - // Retrieve the ndarray function: - if ( fcn ) { - f = fcn; - } else { - f = fcns[ idx ]; - } - // Evaluate the ndarray function: - if ( data ) { - f( arrays, data[ idx ] ); - } else { - f( arrays ); - } - if ( nout === 1 ) { - return arrays[ narrays-1 ]; - } - if ( nout === 0 ) { - return; - } - return arrays.slice( nin ); - } -} - - -// EXPORTS // - -module.exports = dispatch; diff --git a/package.json b/package.json index 9569eb2..aab393c 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Create an ndarray function interface which performs multiple dispatch.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@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-ndarray-like": "^0.0.x", - "@stdlib/assert-is-nonnegative-integer": "^0.0.x", - "@stdlib/assert-is-positive-integer": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/array-int32": "^0.0.x", - "@stdlib/array-int8": "^0.0.x", - "@stdlib/array-uint8": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/math-base-assert-is-nan": "^0.0.x", - "@stdlib/math-base-special-abs": "^0.0.x", - "@stdlib/math-base-special-pow": "^0.0.x", - "@stdlib/math-base-special-sin": "^0.0.x", - "@stdlib/ndarray-base-buffer-dtype": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/ndarray-base-unary": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/ndarray-dtypes": "^0.0.x", - "@stdlib/ndarray-ind2sub": "^0.0.x", - "@stdlib/strided-dtypes": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "ndarray", @@ -97,7 +26,6 @@ "multimethod", "multimethods" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..fb8a991 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/fixtures/binary.js b/test/fixtures/binary.js deleted file mode 100644 index a60dfa2..0000000 --- a/test/fixtures/binary.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Binary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @returns {number} sum -*/ -function binary( x, y ) { - return x + y; -} - - -// EXPORTS // - -module.exports = binary; diff --git a/test/fixtures/fill.js b/test/fixtures/fill.js deleted file mode 100644 index 41b2958..0000000 --- a/test/fixtures/fill.js +++ /dev/null @@ -1,76 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which fills one or more ndarrays. -* -* @private -* @param {*} value - fill value -* @returns {Function} ndarray function -*/ -function fill( value ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - */ - function ndarrayFcn( arrays ) { - var opts; - var sub; - var arr; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - opts = { - 'order': '' - }; - for ( j = 0; j < M; j++ ) { - arr = arrays[ j ]; - opts.order = arrays[ j ].order; - for ( i = 0; i < N; i++ ) { - sub = ind2sub( sh, i, opts ); - sub.push( value ); - arr.set.apply( arr, sub ); - } - } - } -} - - -// EXPORTS // - -module.exports = fill; diff --git a/test/fixtures/foreach.js b/test/fixtures/foreach.js deleted file mode 100644 index a426290..0000000 --- a/test/fixtures/foreach.js +++ /dev/null @@ -1,72 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function forEach( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - fcn.apply( null, args ); - } -} - - -// EXPORTS // - -module.exports = forEach; diff --git a/test/fixtures/map1n.js b/test/fixtures/map1n.js deleted file mode 100644 index 614196b..0000000 --- a/test/fixtures/map1n.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function which maps the return value of a callback to `N` arrays. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function map1N( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var v; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - v = fcn(); - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - sub.push( v ); - arrays[ j ].set.apply( arrays[ j ], sub ); - } - } -} - - -// EXPORTS // - -module.exports = map1N; diff --git a/test/fixtures/nullary.js b/test/fixtures/nullary.js deleted file mode 100644 index 4f22126..0000000 --- a/test/fixtures/nullary.js +++ /dev/null @@ -1,36 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Nullary callback. -* -* @private -* @returns {number} value -*/ -function nullary() { - return 3.0; -} - - -// EXPORTS // - -module.exports = nullary; diff --git a/test/fixtures/quaternary.js b/test/fixtures/quaternary.js deleted file mode 100644 index 548437b..0000000 --- a/test/fixtures/quaternary.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quaternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @returns {number} sum -*/ -function quaternary( x, y, z, w ) { - return x + y + z + w; -} - - -// EXPORTS // - -module.exports = quaternary; diff --git a/test/fixtures/quinary.js b/test/fixtures/quinary.js deleted file mode 100644 index 36068de..0000000 --- a/test/fixtures/quinary.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quinary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @param {number} u - input value -* @returns {number} sum -*/ -function quinary( x, y, z, w, u ) { - return x + y + z + w + u; -} - - -// EXPORTS // - -module.exports = quinary; diff --git a/test/fixtures/sum.js b/test/fixtures/sum.js deleted file mode 100644 index efdbb1b..0000000 --- a/test/fixtures/sum.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which computes the sum across one or more ndarrays. -* -* @private -* @param {Object} ctx - context -* @param {number} ctx.sum - initial sum -* @returns {Function} ndarray function -*/ -function wrapper( ctx ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - * @param {Function} [fcn] - callback - */ - function ndarrayFcn( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var f; - var i; - var j; - - if ( arguments.length > 1 ) { - f = fcn; - } - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - if ( f ) { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - ctx.sum += f.apply( null, args ); - } - } else { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - ctx.sum += arrays[ j ].get.apply( arrays[ j ], sub ); - } - } - } - } -} - - -// EXPORTS // - -module.exports = wrapper; diff --git a/test/fixtures/ternary.js b/test/fixtures/ternary.js deleted file mode 100644 index 0595d5f..0000000 --- a/test/fixtures/ternary.js +++ /dev/null @@ -1,39 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Ternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @returns {number} sum -*/ -function ternary( x, y, z ) { - return x + y + z; -} - - -// EXPORTS // - -module.exports = ternary; diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d6c2c8e..0000000 --- a/test/test.js +++ /dev/null @@ -1,363 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var fill = require( './fixtures/fill.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either a function or an array of functions as a first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( value, types, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object as a second argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided either an array-like object or `null` as a third argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - dispatch( unary, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a positive integer for a fourth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 0, - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a fifth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, value, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a sixth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, 1, value ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function array)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var fcns = [ unary, unary, unary ]; - var data = [ abs, abs, abs ]; - dispatch( fcns, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function argument)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs, abs, abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the length of `data` argument does not match the number of ndarray functions', function test( t ) { - var values; - var i; - - values = [ - [], - [ abs, abs ], - [ abs, abs, abs ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var fcns = [ unary ]; - dispatch( fcns, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the fourth argument is incompatible with the number of input and output ndarrays', function test( t ) { - var values; - var i; - - values = [ - 0, - 1, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of specified input and output ndarrays is zero', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var types = [ 'float64' ]; - dispatch( fill( 3 ), types, null, 1, 0, 0 ); - } -}); - -tape( 'the function returns an ndarray function interface', function test( t ) { - var types; - var data; - var f; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - f = dispatch( unary, types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ unary ], types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( fill( 3 ), types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ fill( 3 ) ], types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.two_arrays.js b/test/test.two_arrays.js deleted file mode 100644 index 071500e..0000000 --- a/test/test.two_arrays.js +++ /dev/null @@ -1,808 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var dtype = require( '@stdlib/ndarray-base-buffer-dtype' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var forEach = require( './fixtures/foreach.js' ); -var map1N = require( './fixtures/map1n.js' ); -var fill = require( './fixtures/fill.js' ); -var sum = require( './fixtures/sum.js' ); - - -// TESTS // - -tape( 'the function returns a function which throws an error if not provided an ndarray for the first argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var ybuf = new Float64Array( 10 ); - var y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( value, y ); - }; - } -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the second argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var xbuf = new Float64Array( 10 ); - var x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( x, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided insufficient arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var f; - var x; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [], - [ x ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided too many arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var ybuf; - var f; - var x; - var y; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [ x, y, y ], - [ x, y, y, y ], - [ x, y, y, y, y ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if unable to resolve a ndarray function supporting the provided array argument data types', function test( t ) { - var values; - var types; - var data; - var xbuf; - var fcn; - var x; - var i; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ abs, abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 4 ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - values = [ - new Uint8Array( 4 ), - new Int32Array( 4 ), - [ 0, 0, 0, 0 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided an array having data type: ' + dtype( values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var y = ndarray( dtype( value ), value, [ value.length ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - }; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only input arrays)', function test( t ) { - var types; - var xbuf; - var ybuf; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only output arrays)', function test( t ) { - var expected; - var types; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only input arrays)', function test( t ) { - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var ctx; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcns = [ - sum( ctx ), - sum( ctx ) - ]; - fcn = dispatch( fcns, types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only output arrays)', function test( t ) { - var expected; - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcns = [ - fill( 3.0 ), - fill( 4.0 ) - ]; - fcn = dispatch( fcns, types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - - fcn = dispatch( forEach, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - - fcn = dispatch( map1N, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - fcns = [ - forEach, - forEach - ]; - fcn = dispatch( fcns, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - fcns = [ - map1N, - map1N - ]; - fcn = dispatch( fcns, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - fcns = [ - unary, - unary - ]; - fcn = dispatch( fcns, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which returns one or more output arrays, if one or more output arrays is specified, and otherwise returns `undefined`', function test( t ) { - var types; - var data; - var xbuf; - var ybuf; - var out; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - // No output arrays... - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, void 0, 'returns expected value' ); - - // One output array... - data = [ - abs, - abs - ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - fcn = dispatch( fill( 3.0 ), types, null, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - // Two output arrays... - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.end(); -}); From b8e68e8596363fdbfad52a631b5832c69b5c7b12 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 03:52:24 +0000 Subject: [PATCH 011/109] Transform error messages --- lib/main.js | 28 ++++++++++++++-------------- package.json | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/main.js b/lib/main.js index 3d28781..c8218ef 100644 --- a/lib/main.js +++ b/lib/main.js @@ -27,7 +27,7 @@ var isFunctionArray = require( '@stdlib/assert-is-function-array' ); var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var indexOfTypes = require( './index_of_types.js' ); @@ -89,43 +89,43 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { if ( isFunction( fcns ) ) { fcn = fcns; } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) ); + throw new TypeError( format( '0Mq5s', fcns ) ); } if ( !isCollection( types ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) ); + throw new TypeError( format( '0Mq3A', types ) ); } if ( !isCollection( data ) && data !== null ) { throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); } if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) ); + throw new TypeError( format( '0Mq5u', nargs ) ); } if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) ); + throw new TypeError( format( '0Mq5v', nin ) ); } if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) ); + throw new TypeError( format( '0Mq5w', nout ) ); } narrays = nin + nout; if ( narrays === 0 ) { - throw new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' ); + throw new Error( format( '0Mq0h' ) ); } if ( nargs !== narrays ) { - throw new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' ); + throw new Error( format( '0Mq0i' ) ); } if ( fcn ) { nfcns = types.length / narrays; if ( !isInteger( nfcns ) ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format( '0Mq0j' ) ); } } else { nfcns = fcns.length; if ( types.length !== nfcns*narrays ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format( '0Mq0j' ) ); } } if ( data && data.length !== nfcns ) { - throw new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' ); + throw new Error( format( '0Mq0k' ) ); } return dispatcher; @@ -154,9 +154,9 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { argc = arguments.length; if ( argc !== nargs ) { if ( argc < nargs ) { - throw new Error( 'invalid invocation. Insufficient arguments.' ); + throw new Error( format( '0Mq0l' ) ); } - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format( '0Mq0m' ) ); } arrays = []; dtypes = []; @@ -177,7 +177,7 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { // Check whether we were able to successfully resolve an ndarray function: if ( idx < 0 ) { - throw new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' ); + throw new TypeError( format( '0Mq0p' ) ); } // Retrieve the ndarray function: if ( fcn ) { diff --git a/package.json b/package.json index 014d480..9569eb2 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-ndarray-like": "^0.0.x", "@stdlib/assert-is-nonnegative-integer": "^0.0.x", "@stdlib/assert-is-positive-integer": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From 0055bf5c4a121b89a559f1e2058c2502d9291556 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 17:53:14 +0000 Subject: [PATCH 012/109] Remove files --- index.d.ts | 334 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 3028 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index e8f79c8..0000000 --- a/index.d.ts +++ /dev/null @@ -1,334 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* ndarray function. -* -* @param arrays - array containing input and output ndarrays -* @param data - ndarray function data (e.g., a callback) -* -* @example -* var numel = require( `@stdlib/ndarray/base/numel` ); -* var ind2sub = require( `@stdlib/ndarray/ind2sub` ); -* -* function ndarrayFcn( arrays, fcn ) { -* var xord; -* var yord; -* var opts; -* var sub; -* var sh; -* var N; -* var x; -* var y; -* var v; -* var i; -* -* x = arrays[ 0 ]; -* y = arrays[ 1 ]; -* sh = x.shape; -* N = numel( sh ); -* if ( N <= 0 ) { -* return; -* } -* xord = x.order; -* yord = y.order; -* opts = {}; -* opts.order = xord; -* for ( i = 0; i < N; i++ ) { -* // Convert a linear index to subscripts: -* opts.order = xord; -* sub = ind2sub( sh, i, opts ); -* -* // Retrieve an element from `x`: -* v = x.get.apply( x, sub ); -* -* // Convert a linear index to subscripts: -* opts.order = yord; -* sub = ind2sub( sh, i, opts ); -* -* // Append the result of applying the callback: -* sub.push( fcn( v ) ); -* -* // Assign the result to an element in `y`: -* y.set.apply( y, sub ); -* } -* } -*/ -type ndarrayFcn = ( arrays: Array, data?: any ) => void; - -/** -* Interface describing an ndarray function dispatcher. -*/ -interface Dispatcher { - /** - * Invokes an ndarray function based on the provided array data type(s). - * - * @param x - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array - * - * @example - * var nullary = require( `@stdlib/ndarray/base/nullary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function value() { - * return 3.14; - * } - * - * var types = [ 'float64' ]; - * var data = [ value ]; - * - * var fcn = dispatch( nullary, types, data, 1, 0, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( 5 ); - * var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x ); - * // xbuf => [ 3.14, 3.14, 3.14, 3.14, 3.14 ] - */ - ( x: ndarray ): ndarray | void; - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var unary = require( `@stdlib/ndarray/base/unary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * var abs = require( `@stdlib/math/base/special/abs` ); - * - * var types = [ 'float64', 'float64' ]; - * var data = [ abs ]; - * - * var fcn = dispatch( unary, types, data, 2, 1, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - * var ybuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y ); - * // ybuf => [ 1.0, 2.0, 3.0 ] - */ - ( x: ndarray, y: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var ternary = require( `@stdlib/ndarray/base/ternary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add2( x, y ) { - * return x + y; - * } - * - * var types = [ 'float64', 'float64', 'float64' ]; - * var data = [ add2 ]; - * - * var fcn = dispatch( ternary, types, data, 3, 2, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z ); - * // zbuf => [ 2.0, 4.0, 6.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quaternary = require( `@stdlib/ndarray/base/quaternary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add3( x, y, z ) { - * return x + y + z; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add3 ]; - * - * var fcn = dispatch( quaternary, types, data, 4, 3, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w ); - * // wbuf => [ 3.0, 6.0, 9.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @param args - ndarray arguments - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quinary = require( `@stdlib/ndarray/base/quinary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add4( x, y, z, w ) { - * return x + y + z + w; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add4 ]; - * - * var fcn = dispatch( quinary, types, data, 5, 4, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ubuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var u = ndarray( 'float64', ubuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w, u ); - * // ubuf => [ 4.0, 8.0, 12.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray, ...args: Array ): ndarray | void; // tslint:disable-line:max-line-length unified-signatures -} - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param fcns - list of ndarray functions -* @param types - one-dimensional list of ndarray argument data types -* @param data - ndarray function data (e.g., callbacks) -* @param nargs - total number of ndarray function interface arguments -* @param nin - number of input ndarrays -* @param nout - number of output ndarrays -* @throws first argument must be either a function or an array of functions -* @throws second argument must be an array-like object -* @throws third argument must be an array-like object or `null` -* @throws third and first arguments must have the same number of elements -* @throws fourth argument must be a positive integer -* @throws fifth argument must be a nonnegative integer -* @throws sixth argument must be a nonnegative integer -* @throws fourth argument must equal the specified number of input and output arrays -* @throws number of types must match the number of functions times the total number of array arguments for each function -* @throws interface must accept at least one input and/or output ndarray -* @returns ndarray function interface -* -* @example -* var unary = require( `@stdlib/ndarray/base/unary` ); -* var abs = require( `@stdlib/math/base/special/abs` ); -* var Float64Array = require( `@stdlib/array/float64` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var fcn = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* fcn( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function dispatch( fcns: ndarrayFcn | ArrayLike, types: ArrayLike, data: ArrayLike | null, nargs: number, nin: number, nout: number ): Dispatcher; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = dispatch; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 3bf42ba..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";function m(r,e,t,i,s,n,o,l,m){var d,a,h,f;for(d=n,h=0;h [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0Mq5s', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0Mq3A', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0Mq5u', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0Mq5v', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0Mq5w', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format( '0Mq0h' ) );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format( '0Mq0i' ) );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format( '0Mq0k' ) );\n\t}\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format( '0Mq0l' ) );\n\t\t\t}\n\t\t\tthrow new Error( format( '0Mq0m' ) );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( v.dtype );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format( '0Mq0p' ) );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n"],"names":["indexOfTypes","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","i","j","dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","push","dtype","slice"],"mappings":";;gvBA6EA,SAASA,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,KAAgBE,EAAGI,GADdE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,EAEP,OAAQ,EChBT,SAASU,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,sFAAuFV,IAErH,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAQ,UAE1B,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAQ,UAE1B,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAQ,eAI1B,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAQ,UAG3B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAQ,UAE1B,OAeA,WACC,IAAIO,EACAC,EACAC,EACAC,EACAC,EACAC,EACA3B,EAGJ,IADAwB,EAAOI,UAAUR,UACHd,EAAQ,CACrB,GAAKkB,EAAOlB,EACX,MAAM,IAAIa,MAAOJ,EAAQ,UAE1B,MAAM,IAAII,MAAOJ,EAAQ,UAI1B,IAFAO,EAAS,GACTC,EAAS,GACHvB,EAAI,EAAGA,EAAIM,EAAON,IAAM,CAE7B,IAAM6B,EADNH,EAAIE,UAAW5B,IAEd,MAAKA,EAAIO,EACF,IAAIO,UAAWC,EAAQ,6EAA8EW,IAErG,IAAIZ,UAAWC,EAAQ,8EAA+EW,IAG9GJ,EAAOQ,KAAMJ,GACbH,EAAOO,KAAMJ,EAAEK,OAMhB,IAHAN,EAAMrC,EAAcsB,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGc,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAIT,UAAWC,EAAQ,UAI7BY,EADIhB,GAGAR,EAAMsB,GAGNpB,EACJsB,EAAGL,EAAQjB,EAAMoB,IAEjBE,EAAGL,GAEJ,GAAc,IAATd,EACJ,OAAOc,EAAQb,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOc,EAAOU,MAAOzB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index fb8a991..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From ebc40f961b8e23f52da71a5ab46ce0f9b954aa20 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 17:54:16 +0000 Subject: [PATCH 013/109] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 33 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 760 ------ .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 59 +- benchmark/benchmark.dispatch_size.js | 156 -- benchmark/benchmark.js | 81 - branches.md | 53 - docs/repl.txt | 87 - docs/types/test.ts | 641 ----- examples/add.js | 121 - examples/sin.js | 142 -- examples/unary.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/index_of_types.js | 106 - lib/main.js | 207 -- package.json | 76 +- stats.html | 2689 +++++++++++++++++++++ test/fixtures/binary.js | 38 - test/fixtures/fill.js | 76 - test/fixtures/foreach.js | 72 - test/fixtures/map1n.js | 74 - test/fixtures/nullary.js | 36 - test/fixtures/quaternary.js | 40 - test/fixtures/quinary.js | 41 - test/fixtures/sum.js | 98 - test/fixtures/ternary.js | 39 - test/test.js | 363 --- test/test.two_arrays.js | 808 ------- 51 files changed, 2723 insertions(+), 6380 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.dispatch_size.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/add.js delete mode 100644 examples/sin.js delete mode 100644 examples/unary.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/index_of_types.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/fixtures/binary.js delete mode 100644 test/fixtures/fill.js delete mode 100644 test/fixtures/foreach.js delete mode 100644 test/fixtures/map1n.js delete mode 100644 test/fixtures/nullary.js delete mode 100644 test/fixtures/quaternary.js delete mode 100644 test/fixtures/quinary.js delete mode 100644 test/fixtures/sum.js delete mode 100644 test/fixtures/ternary.js delete mode 100644 test/test.js delete mode 100644 test/test.two_arrays.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 7212d81..0000000 --- a/.gitattributes +++ /dev/null @@ -1,33 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index adc3d27..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-08-01T01:35:01.330Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ac0b7cd..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a7a7f51..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.9.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 920b304..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 39b1613..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 7ca169c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 8 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "::set-output name=package_name::$name" - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "::set-output name=data::$data" - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v2 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v2 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 5094681..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,760 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -291,7 +284,7 @@ console.log( ybuf ); ## 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. +This package is part of [stdlib][stdlib], a standard library 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]. @@ -353,11 +346,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm diff --git a/benchmark/benchmark.dispatch_size.js b/benchmark/benchmark.dispatch_size.js deleted file mode 100644 index 3bd0418..0000000 --- a/benchmark/benchmark.dispatch_size.js +++ /dev/null @@ -1,156 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib/main.js' ); - - -// FUNCTIONS // - -/** -* Evaluates the identity function. -* -* @private -* @param {*} v - value -* @returns {*} input value -*/ -function identity( v ) { - return v; -} - -/** -* Dummy function which throws an error. -* -* @private -* @throws {Error} unexpected error -*/ -function throwError() { - throw new Error( 'unexpected error' ); -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} size - dispatch size -* @returns {Function} benchmark function -*/ -function createBenchmark( size ) { - var types; - var data; - var fcn; - var x; - var y; - var t; - var i; - - types = []; - - // Create dummy types... - for ( i = 0; i < (size-1)*2; i += 2 ) { - t = 'foo' + i; - types.push( t ); - types.push( t ); - } - // Append test types: - types.push( 'float64' ); - types.push( 'float64' ); - - // Define a list of callbacks: - data = []; - for ( i = 0; i < size-1; i++ ) { - data.push( throwError ); - } - // Append a test callback: - data.push( identity ); - - // Create the dispatcher: - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - // Create sample arrays: - x = new Float64Array( 1 ); - y = new Float64Array( x.length ); - - x = ndarray( 'float64', x, [ 1 ], [ 1 ], 0, 'row-major' ); - y = ndarray( 'float64', y, [ 1 ], [ 1 ], 0, 'row-major' ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var z; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x.data[ 0 ] = i; - z = fcn( x, y ); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var size; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - size = pow( 2, i ); - f = createBenchmark( size ); - bench( pkg+':size='+size, f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index a70dc5c..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::fcns_array', function benchmark( b ) { - var types; - var fcns; - var data; - var out; - var i; - - fcns = [ unary ]; - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( fcns, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::fcn_arg', function benchmark( b ) { - var types; - var data; - var out; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( unary, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index d04d051..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch" -click B href "https://github.com/stdlib-js/ndarray-dispatch/tree/main" -click C href "https://github.com/stdlib-js/ndarray-dispatch/tree/production" -click D href "https://github.com/stdlib-js/ndarray-dispatch/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-dispatch/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-dispatch/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch -[production-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 02fe150..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,87 +0,0 @@ - -{{alias}}( fcns, types, data, nargs, nin, nout ) - Returns an ndarray function interface which performs multiple dispatch. - - An ndarray function interface has the following signature: - - f( x, y, ... ) - - where - - - x: ndarray. - - y: ndarray. - - ...: additional ndarrays. - - The number of parameters is derived from `nargs`, the number of input - ndarrays is derived from `nin`, and the number of output ndarrays is derived - from `nout`. - - Parameters - ---------- - fcns: Function|ArrayLikeObject - List of ndarray functions. An ndarray function should have the following - signature: - - f( arrays, data ) - - where - - - arrays: array containing input and output ndarrays. - - data: ndarray function data (e.g., a callback). - - For convenience, a single ndarray function may be provided which will be - invoked whenever the ndarray argument data types match a sequence of - types in `types`. Providing a single ndarray function is particularly - convenient for the case where, regardless of array data types, - traversing arrays remains the same, but the ndarray function `data` - differs (e.g., callbacks which differ based on the array data types). - - types: ArrayLikeObject - One-dimensional list of ndarray argument data types. - - data: ArrayLikeObject|null - ndarray function data (e.g., callbacks). If `null`, a returned ndarray - function interface does **not** provide a `data` argument to an invoked - ndarray function. - - nargs: integer - Total number of ndarray function interface arguments. - - nin: integer - Number of input ndarrays. - - nout: integer - Number of output ndarrays. - - Returns - ------- - fcn: Function - ndarray function interface. - - Examples - -------- - // Define ndarray argument data types: - > var t = [ 'float64', 'float64', 'float32', 'float32' ]; - - // Define a list of ndarray function data (callbacks): - > var d = [ {{alias:@stdlib/math/base/special/abs}}, {{alias:@stdlib/math/base/special/absf}} ]; - - // Create an ndarray function interface for applying unary callbacks: - > var f = {{alias}}( {{alias:@stdlib/ndarray/base/unary}}, t, d, 2, 1, 1 ); - - // Create an input ndarray: - > var xbuf = new {{alias:@stdlib/array/float64}}( [ -1.0, -2.0, -3.0, -4.0 ] ); - > var x = {{alias:@stdlib/ndarray/ctor}}( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Create an output ndarray: - > var ybuf = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 0.0, 0.0 ] ); - > var y = {{alias:@stdlib/ndarray/ctor}}( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Compute the element-wise absolute value: - > f( x, y ); - > ybuf - [ 1.0, 2.0, 3.0, 4.0 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 397185e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,641 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// tslint:disable:max-file-line-count - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import dispatch = require( './index' ); - - -// FUNCTIONS // - -/** -* Nullary callback. -* -* @return input value -*/ -function nullary(): any { - return 5.0; -} - -/** -* Unary callback. -* -* @param x - input value -* @return input value -*/ -function unary( x: any ): any { - return x; -} - -/** -* Binary callback. -* -* @param x - input value -* @param y - input value -* @return output value -*/ -function binary( x: number, y: number ): number { - return x + y; -} - -/** -* Ternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @return output value -*/ -function ternary( x: number, y: number, z: number ): number { - return x + y + z; -} - -/** -* Quaternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @param w - input value -* @return output value -*/ -function quaternary( x: number, y: number, z: number, w: number ): number { - return x + y + z + w; -} - -/** -* Mock `ind2sub` function. -* -* @param shape - dimensions -* @param idx - linear index -* @param opts - options -* @return subscripts -*/ -function ind2sub( shape: ArrayLike, idx: number, opts?: any ): Array { // tslint:disable-line:max-line-length - let out; - let i; - - out = []; - if ( typeof opts === 'object' && opts !== null && opts.order === 'row-major' ) { // tslint:disable-line:max-line-length no-unsafe-any - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } else { - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } - return out; -} - -/** -* Mock ndarray function. -* -* @param arrays - ndarrays -* @param fcn - callback -*/ -function ndarrayFcn( arrays: Array, fcn: ( x: any ) => any ): void { - let xord; - let yord; - let opts; - let sub; - let sh; - let N; - let x; - let y; - let v; - let i; - - x = arrays[ 0 ]; - y = arrays[ 1 ]; - sh = x.shape; - if ( sh.length === 0 ) { - return; - } - N = 1; - for ( i = 0; i < sh.length; i += 1 ) { - N *= sh[ i ]; - } - xord = x.order; - yord = y.order; - opts = { - 'order': '' - }; - opts.order = xord; - for ( i = 0; i < N; i += 1 ) { - // Convert a linear index to subscripts: - opts.order = xord; - sub = ind2sub( sh, i, opts ); - - // Retrieve an element from `x`: - v = x.get.apply( x, sub ); - - // Convert a linear index to subscripts: - opts.order = yord; - sub = ind2sub( sh, i, opts ); - - // Append the result of applying the callback: - sub[ sub.length ] = fcn( v ) as number; - - // Assign the result to an element in `y`: - y.set.apply( y, sub ); - } -} - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a dispatch function... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, 1 ); // $ExpectType Dispatcher - dispatch( [ ndarrayFcn ], types, data, 2, 1, 1 ); // $ExpectType Dispatcher -} - -// The compiler throws an error if the function is provided a first argument which is not either an ndarray function or an array-like object containing ndarray functions... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( '10', types, data, 2, 1, 1 ); // $ExpectError - dispatch( 10, types, data, 2, 1, 1 ); // $ExpectError - dispatch( true, types, data, 2, 1, 1 ); // $ExpectError - dispatch( false, types, data, 2, 1, 1 ); // $ExpectError - dispatch( null, types, data, 2, 1, 1 ); // $ExpectError - dispatch( undefined, types, data, 2, 1, 1 ); // $ExpectError - dispatch( [ '1' ], types, data, 2, 1, 1 ); // $ExpectError - dispatch( {}, types, data, 2, 1, 1 ); // $ExpectError - dispatch( ( x: number ): number => x, types, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object... -{ - const data = [ unary ]; - - dispatch( ndarrayFcn, 10, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, true, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, false, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, null, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, undefined, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, {}, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object or null... -{ - const types = [ 'float64', 'float64' ]; - - dispatch( ndarrayFcn, types, 10, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, true, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, false, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, undefined, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, {}, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, '10', 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, true, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, false, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, null, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, undefined, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, [ '1' ], 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, {}, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, ( x: number ): number => x, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, '10', 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, true, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, false, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, null, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, undefined, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, [ '1' ], 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, {}, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, ( x: number ): number => x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, '10' ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, true ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, false ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, null ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, undefined ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, [ '1' ] ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, {} ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch(); // $ExpectError - dispatch( ndarrayFcn ); // $ExpectError - dispatch( ndarrayFcn, types ); // $ExpectError - dispatch( ndarrayFcn, types, data ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, 1, 0 ); // $ExpectError -} - -// The function returns a dispatch function... -{ - const x = array(); - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const t1 = [ 'float64' ]; - const d1 = [ nullary ]; - const f1 = dispatch( ndarrayFcn, t1, d1, 1, 1, 0 ); - f1( x ); // $ExpectType void | ndarray - - const t2 = [ 'float64', 'float64' ]; - const d2 = [ unary ]; - const f2 = dispatch( ndarrayFcn, t2, d2, 2, 1, 1 ); - f2( x, y ); // $ExpectType void | ndarray - - const t3 = [ 'float64', 'float64', 'float64' ]; - const d3 = [ binary ]; - const f3 = dispatch( ndarrayFcn, t3, d3, 3, 2, 1 ); - f3( x, y, z ); // $ExpectType void | ndarray - - const t4 = [ 'float64', 'float64', 'float64', 'float64' ]; - const d4 = [ ternary ]; - const f4 = dispatch( ndarrayFcn, t4, d4, 4, 3, 1 ); - f4( x, y, z, w ); // $ExpectType void | ndarray - - const t5 = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const d5 = [ quaternary ]; - const f5 = dispatch( ndarrayFcn, t5, d5, 5, 4, 1 ); - f5( x, y, z, w, u ); // $ExpectType void | ndarray -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (1 ndarray)... -{ - const types = [ 'float64' ]; - const data = [ nullary ]; - - const f = dispatch( ndarrayFcn, types, data, 1, 0, 1 ); - f( '10' ); // $ExpectError - f( 10 ); // $ExpectError - f( true ); // $ExpectError - f( false ); // $ExpectError - f( null ); // $ExpectError - f( undefined ); // $ExpectError - f( [ '1' ] ); // $ExpectError - f( {} ); // $ExpectError - f( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( 10, y ); // $ExpectError - f( '10', y ); // $ExpectError - f( true, y ); // $ExpectError - f( false, y ); // $ExpectError - f( null, y ); // $ExpectError - f( undefined, y ); // $ExpectError - f( [ '1' ], y ); // $ExpectError - f( {}, y ); // $ExpectError - f( ( x: number ): number => x, y ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const x = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( x, 10 ); // $ExpectError - f( x, '10' ); // $ExpectError - f( x, true ); // $ExpectError - f( x, false ); // $ExpectError - f( x, null ); // $ExpectError - f( x, undefined ); // $ExpectError - f( x, [ '1' ] ); // $ExpectError - f( x, {} ); // $ExpectError - f( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( 10, y, z ); // $ExpectError - f( '10', y, z ); // $ExpectError - f( true, y, z ); // $ExpectError - f( false, y, z ); // $ExpectError - f( null, y, z ); // $ExpectError - f( undefined, y, z ); // $ExpectError - f( [ '1' ], y, z ); // $ExpectError - f( {}, y, z ); // $ExpectError - f( ( x: number ): number => x, y, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, 10, z ); // $ExpectError - f( x, '10', z ); // $ExpectError - f( x, true, z ); // $ExpectError - f( x, false, z ); // $ExpectError - f( x, null, z ); // $ExpectError - f( x, undefined, z ); // $ExpectError - f( x, [ '1' ], z ); // $ExpectError - f( x, {}, z ); // $ExpectError - f( x, ( x: number ): number => x, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, y, '10' ); // $ExpectError - f( x, y, true ); // $ExpectError - f( x, y, false ); // $ExpectError - f( x, y, null ); // $ExpectError - f( x, y, undefined ); // $ExpectError - f( x, y, [ '1' ] ); // $ExpectError - f( x, y, {} ); // $ExpectError - f( x, y, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( 10, y, z, w ); // $ExpectError - f( '10', y, z, w ); // $ExpectError - f( true, y, z, w ); // $ExpectError - f( false, y, z, w ); // $ExpectError - f( null, y, z, w ); // $ExpectError - f( undefined, y, z, w ); // $ExpectError - f( [ '1' ], y, z, w ); // $ExpectError - f( {}, y, z, w ); // $ExpectError - f( ( x: number ): number => x, y, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, 10, z, w ); // $ExpectError - f( x, '10', z, w ); // $ExpectError - f( x, true, z, w ); // $ExpectError - f( x, false, z, w ); // $ExpectError - f( x, null, z, w ); // $ExpectError - f( x, undefined, z, w ); // $ExpectError - f( x, [ '1' ], z, w ); // $ExpectError - f( x, {}, z, w ); // $ExpectError - f( x, ( x: number ): number => x, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, 10, w ); // $ExpectError - f( x, y, '10', w ); // $ExpectError - f( x, y, true, w ); // $ExpectError - f( x, y, false, w ); // $ExpectError - f( x, y, null, w ); // $ExpectError - f( x, y, undefined, w ); // $ExpectError - f( x, y, [ '1' ], w ); // $ExpectError - f( x, y, {}, w ); // $ExpectError - f( x, y, ( x: number ): number => x, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, z, 10 ); // $ExpectError - f( x, y, z, '10' ); // $ExpectError - f( x, y, z, true ); // $ExpectError - f( x, y, z, false ); // $ExpectError - f( x, y, z, null ); // $ExpectError - f( x, y, z, undefined ); // $ExpectError - f( x, y, z, [ '1' ] ); // $ExpectError - f( x, y, z, {} ); // $ExpectError - f( x, y, z, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( 10, y, z, w, u ); // $ExpectError - f( '10', y, z, w, u ); // $ExpectError - f( true, y, z, w, u ); // $ExpectError - f( false, y, z, w, u ); // $ExpectError - f( null, y, z, w, u ); // $ExpectError - f( undefined, y, z, w, u ); // $ExpectError - f( [ '1' ], y, z, w, u ); // $ExpectError - f( {}, y, z, w, u ); // $ExpectError - f( ( x: number ): number => x, y, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, 10, z, w, u ); // $ExpectError - f( x, '10', z, w, u ); // $ExpectError - f( x, true, z, w, u ); // $ExpectError - f( x, false, z, w, u ); // $ExpectError - f( x, null, z, w, u ); // $ExpectError - f( x, undefined, z, w, u ); // $ExpectError - f( x, [ '1' ], z, w, u ); // $ExpectError - f( x, {}, z, w, u ); // $ExpectError - f( x, ( x: number ): number => x, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, 10, w, u ); // $ExpectError - f( x, y, '10', w, u ); // $ExpectError - f( x, y, true, w, u ); // $ExpectError - f( x, y, false, w, u ); // $ExpectError - f( x, y, null, w, u ); // $ExpectError - f( x, y, undefined, w, u ); // $ExpectError - f( x, y, [ '1' ], w, u ); // $ExpectError - f( x, y, {}, w, u ); // $ExpectError - f( x, y, ( x: number ): number => x, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, 10, u ); // $ExpectError - f( x, y, z, '10', u ); // $ExpectError - f( x, y, z, true, u ); // $ExpectError - f( x, y, z, false, u ); // $ExpectError - f( x, y, z, null, u ); // $ExpectError - f( x, y, z, undefined, u ); // $ExpectError - f( x, y, z, [ '1' ], u ); // $ExpectError - f( x, y, z, {}, u ); // $ExpectError - f( x, y, z, ( x: number ): number => x, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fifth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, w, 10 ); // $ExpectError - f( x, y, z, w, '10' ); // $ExpectError - f( x, y, z, w, true ); // $ExpectError - f( x, y, z, w, false ); // $ExpectError - f( x, y, z, w, null ); // $ExpectError - f( x, y, z, w, undefined ); // $ExpectError - f( x, y, z, w, [ '1' ] ); // $ExpectError - f( x, y, z, w, {} ); // $ExpectError - f( x, y, z, w, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/add.js b/examples/add.js deleted file mode 100644 index 775b711..0000000 --- a/examples/add.js +++ /dev/null @@ -1,121 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var dispatch = require( './../lib' ); - -function add2( arrays ) { - var opts; - var xo; - var yo; - var zo; - var sx; - var sy; - var sz; - var sh; - var N; - var x; - var y; - var z; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - z = arrays[ 2 ]; - xo = x.order; - yo = y.order; - zo = z.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - opts.order = yo; - sy = ind2sub( sh, i, opts ); - v = x.get.apply( x, sx ) + y.get.apply( y, sy ); - - opts.order = zo; - sz = ind2sub( sh, i, opts ); - sz.push( v ); - z.set.apply( z, sz ); - } -} - -var fcns = [ - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2 -]; - -var types = [ - dtypes.float64, dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.int32, dtypes.int32, - dtypes.uint32, dtypes.uint32, dtypes.uint32, - dtypes.int16, dtypes.int16, dtypes.int16, - dtypes.uint16, dtypes.uint16, dtypes.uint16, - dtypes.int8, dtypes.int8, dtypes.int8, - dtypes.uint8, dtypes.uint8, dtypes.uint8, - dtypes.uint8c, dtypes.uint8c, dtypes.uint8c -]; - -var add = dispatch( fcns, types, null, 3, 2, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var zbuf = new Float64Array( xbuf.length ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var z = ndarray( 'float64', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); - -xbuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -ybuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -zbuf = new Int32Array( xbuf.length ); - -x = ndarray( 'int32', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'int32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -z = ndarray( 'int32', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); diff --git a/examples/sin.js b/examples/sin.js deleted file mode 100644 index 8cd4871..0000000 --- a/examples/sin.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int8Array = require( '@stdlib/array-int8' ); -var sin = require( '@stdlib/math-base-special-sin' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/strided-dtypes' ); -var dispatch = require( './../lib' ); - -function apply( arrays, fcn ) { - var opts; - var xo; - var yo; - var sx; - var sy; - var sh; - var N; - var x; - var y; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - xo = x.order; - yo = y.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - v = fcn( x.get.apply( x, sx ) ); - - opts.order = yo; - sy = ind2sub( sh, i, opts ); - sy.push( v ); - y.set.apply( y, sy ); - } -} - -var fcns = [ - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply -]; - -var types = [ - dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float64, - dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.float64, - dtypes.uint32, dtypes.float64, - dtypes.int16, dtypes.float64, - dtypes.int16, dtypes.float32, - dtypes.uint16, dtypes.float64, - dtypes.uint16, dtypes.float32, - dtypes.int8, dtypes.float64, - dtypes.int8, dtypes.float32, - dtypes.uint8, dtypes.float64, - dtypes.uint8, dtypes.float32, - dtypes.uint8c, dtypes.float64, - dtypes.uint8c, dtypes.float32 -]; - -var data = [ - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin -]; - -var sine = dispatch( fcns, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); - -xbuf = new Int8Array( [ 1, 2, 3, 4, 5 ] ); -ybuf = new Float32Array( xbuf.length ); - -x = ndarray( 'int8', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'float32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); diff --git a/examples/unary.js b/examples/unary.js deleted file mode 100644 index e9c3fb4..0000000 --- a/examples/unary.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -var unary = require( '@stdlib/ndarray-base-unary' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var dispatch = require( './../lib' ); - -var types = [ 'float64', 'float64' ]; - -var data = [ - abs -]; - -var absolute = dispatch( unary, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -absolute( x, y ); -console.log( ybuf ); -// => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 610167d..e8f79c8 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..f48c2d5 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function m(r,e,t,i,s,n,o,l,m){var d,a,h,f;for(d=n,h=0;h [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0Mq5s', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0Mq3A', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0Mq5u', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0Mq5v', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0Mq5w', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format( '0Mq0h' ) );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format( '0Mq0i' ) );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format( '0Mq0k' ) );\n\t}\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format( '0Mq0l' ) );\n\t\t\t}\n\t\t\tthrow new Error( format( '0Mq0m' ) );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( v.dtype );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format( '0Mq0p' ) );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n"],"names":["indexOfTypes","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","i","j","dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","push","dtype","slice"],"mappings":";;uvBA6EA,SAASA,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,KAAgBE,EAAGI,GADdE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,EAEP,OAAQ,EChBT,SAASU,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,sFAAuFV,IAErH,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAQ,UAE1B,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAQ,UAE1B,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAQ,eAI1B,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAQ,UAG3B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAQ,UAE1B,OAeA,WACC,IAAIO,EACAC,EACAC,EACAC,EACAC,EACAC,EACA3B,EAGJ,IADAwB,EAAOI,UAAUR,UACHd,EAAQ,CACrB,GAAKkB,EAAOlB,EACX,MAAM,IAAIa,MAAOJ,EAAQ,UAE1B,MAAM,IAAII,MAAOJ,EAAQ,UAI1B,IAFAO,EAAS,GACTC,EAAS,GACHvB,EAAI,EAAGA,EAAIM,EAAON,IAAM,CAE7B,IAAM6B,EADNH,EAAIE,UAAW5B,IAEd,MAAKA,EAAIO,EACF,IAAIO,UAAWC,EAAQ,6EAA8EW,IAErG,IAAIZ,UAAWC,EAAQ,8EAA+EW,IAG9GJ,EAAOQ,KAAMJ,GACbH,EAAOO,KAAMJ,EAAEK,OAMhB,IAHAN,EAAMrC,EAAcsB,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGc,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAIT,UAAWC,EAAQ,UAI7BY,EADIhB,GAGAR,EAAMsB,GAGNpB,EACJsB,EAAGL,EAAQjB,EAAMoB,IAEjBE,EAAGL,GAEJ,GAAc,IAATd,EACJ,OAAOc,EAAQb,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOc,EAAOU,MAAOzB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f9d8aef..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Create an ndarray function interface which performs multiple dispatch. -* -* @module @stdlib/ndarray-dispatch -* -* @example -* var dispatch = require( '@stdlib/ndarray-dispatch' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// MODULES // - -var dispatch = require( './main.js' ); - - -// EXPORTS // - -module.exports = dispatch; diff --git a/lib/index_of_types.js b/lib/index_of_types.js deleted file mode 100644 index fda2297..0000000 --- a/lib/index_of_types.js +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found). -* -* ## Notes -* -* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types). -* - The function assumes that `x` is stored in row-major order. -* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`. -* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value. -* -* @private -* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension) -* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension) -* @param {ArrayLikeObject} x - input two-dimensional reference array -* @param {integer} strideX1 - `x` stride length along first dimension -* @param {integer} strideX2 - `x` stride length along second dimension -* @param {NonNegativeInteger} offsetX - `x` starting index -* @param {ArrayLikeObject} y - search array -* @param {integer} strideY - `y` stride length -* @param {NonNegativeInteger} offsetY - `y` starting index -* @returns {integer} row index (if found) and `-1` otherwise -* -* @example -* // Define a reference array to search: -* var types = [ -* 'float64', 'float64', 'float64', -* 'float32', 'float32', 'float32', -* 'uint32', 'uint32', 'float64', -* 'int32', 'int32', 'float64', -* 'uint16', 'uint16', 'float64', -* 'int16', 'int16', 'float64', -* 'uint8', 'uint8', 'float64', -* 'int8', 'int8', 'float64' -* ]; -* -* // Define reference array dimensions: -* var N = 8; // rows -* var M = 3; // columns -* -* // Define a search array: -* y1 = [ -* 'float32', 'float32', 'float32', -* ]; -* -* // Find the list of types: -* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 ); -* // returns 1 -* -// Define a search array: -* y2 = [ -* 'float32', 'float32', 'float64', -* ]; -* -* // Find the list of types: -* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 ); -* // returns -1 -*/ -function indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len - var ix; - var iy; - var i; - var j; - - // Search for the first row which matches `y`... - ix = offsetX; - for ( i = 0; i < N; i++ ) { - iy = offsetY; - for ( j = 0; j < M; j++ ) { - if ( x[ ix+(j*strideX2) ] !== y[ iy ] ) { - break; - } - iy += strideY; - } - // If we successfully iterated over all columns, then that means we've found a match... - if ( j === M ) { - return i; - } - ix += strideX1; - } - return -1; -} - - -// EXPORTS // - -module.exports = indexOfTypes; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c8218ef..0000000 --- a/lib/main.js +++ /dev/null @@ -1,207 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isFunctionArray = require( '@stdlib/assert-is-function-array' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var indexOfTypes = require( './index_of_types.js' ); - - -// MAIN // - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param {(FunctionArray|Function)} fcns - list of ndarray functions -* @param {Collection} types - one-dimensional list of ndarray argument data types -* @param {(Collection|null)} data - ndarray function data (e.g., callbacks) -* @param {PositiveInteger} nargs - total number of ndarray function interface arguments -* @param {NonNegativeInteger} nin - number of input ndarrays -* @param {NonNegativeInteger} nout - number of output ndarrays -* @throws {TypeError} first argument must be either a function or an array of functions -* @throws {TypeError} second argument must be an array-like object -* @throws {TypeError} third argument must be an array-like object or `null` -* @throws {Error} third and first arguments must have the same number of elements -* @throws {TypeError} fourth argument must be a positive integer -* @throws {TypeError} fifth argument must be a nonnegative integer -* @throws {TypeError} sixth argument must be a nonnegative integer -* @throws {Error} fourth argument must equal the specified number of input and output arrays -* @throws {Error} number of types must match the number of functions times the total number of array arguments for each function -* @throws {Error} interface must accept at least one input and/or output ndarray -* @returns {Function} ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function dispatch( fcns, types, data, nargs, nin, nout ) { - var narrays; - var nfcns; - var fcn; - - if ( isFunction( fcns ) ) { - fcn = fcns; - } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( '0Mq5s', fcns ) ); - } - if ( !isCollection( types ) ) { - throw new TypeError( format( '0Mq3A', types ) ); - } - if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); - } - if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( '0Mq5u', nargs ) ); - } - if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( '0Mq5v', nin ) ); - } - if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( '0Mq5w', nout ) ); - } - narrays = nin + nout; - if ( narrays === 0 ) { - throw new Error( format( '0Mq0h' ) ); - } - if ( nargs !== narrays ) { - throw new Error( format( '0Mq0i' ) ); - } - if ( fcn ) { - nfcns = types.length / narrays; - if ( !isInteger( nfcns ) ) { - throw new Error( format( '0Mq0j' ) ); - } - } else { - nfcns = fcns.length; - if ( types.length !== nfcns*narrays ) { - throw new Error( format( '0Mq0j' ) ); - } - } - if ( data && data.length !== nfcns ) { - throw new Error( format( '0Mq0k' ) ); - } - return dispatcher; - - /** - * ndarray function interface which performs multiple dispatch. - * - * @private - * @param {ndarrayLike} x - ndarray - * @param {...ndarrayLike} args - ndarray arguments - * @throws {Error} insufficient arguments - * @throws {Error} too many arguments - * @throws {TypeError} input array arguments must be ndarray-like objects - * @throws {TypeError} output array arguments must be ndarray-like objects - * @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types - * @returns {(ndarrayLike|Array|void)} destination array(s) - */ - function dispatcher() { - var arrays; - var dtypes; - var argc; - var idx; - var v; - var f; - var i; - - argc = arguments.length; - if ( argc !== nargs ) { - if ( argc < nargs ) { - throw new Error( format( '0Mq0l' ) ); - } - throw new Error( format( '0Mq0m' ) ); - } - arrays = []; - dtypes = []; - for ( i = 0; i < nargs; i++ ) { - v = arguments[ i ]; - if ( !isndarrayLike( v ) ) { - if ( i < nin ) { - throw new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) ); - } else { - throw new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) ); - } - } - arrays.push( v ); - dtypes.push( v.dtype ); - } - // Resolve the ndarray function satisfying the input array types: - idx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len - - // Check whether we were able to successfully resolve an ndarray function: - if ( idx < 0 ) { - throw new TypeError( format( '0Mq0p' ) ); - } - // Retrieve the ndarray function: - if ( fcn ) { - f = fcn; - } else { - f = fcns[ idx ]; - } - // Evaluate the ndarray function: - if ( data ) { - f( arrays, data[ idx ] ); - } else { - f( arrays ); - } - if ( nout === 1 ) { - return arrays[ narrays-1 ]; - } - if ( nout === 0 ) { - return; - } - return arrays.slice( nin ); - } -} - - -// EXPORTS // - -module.exports = dispatch; diff --git a/package.json b/package.json index 9569eb2..aab393c 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Create an ndarray function interface which performs multiple dispatch.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@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-ndarray-like": "^0.0.x", - "@stdlib/assert-is-nonnegative-integer": "^0.0.x", - "@stdlib/assert-is-positive-integer": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/array-int32": "^0.0.x", - "@stdlib/array-int8": "^0.0.x", - "@stdlib/array-uint8": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/math-base-assert-is-nan": "^0.0.x", - "@stdlib/math-base-special-abs": "^0.0.x", - "@stdlib/math-base-special-pow": "^0.0.x", - "@stdlib/math-base-special-sin": "^0.0.x", - "@stdlib/ndarray-base-buffer-dtype": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/ndarray-base-unary": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/ndarray-dtypes": "^0.0.x", - "@stdlib/ndarray-ind2sub": "^0.0.x", - "@stdlib/strided-dtypes": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "ndarray", @@ -97,7 +26,6 @@ "multimethod", "multimethods" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..49ef45c --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/fixtures/binary.js b/test/fixtures/binary.js deleted file mode 100644 index a60dfa2..0000000 --- a/test/fixtures/binary.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Binary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @returns {number} sum -*/ -function binary( x, y ) { - return x + y; -} - - -// EXPORTS // - -module.exports = binary; diff --git a/test/fixtures/fill.js b/test/fixtures/fill.js deleted file mode 100644 index 41b2958..0000000 --- a/test/fixtures/fill.js +++ /dev/null @@ -1,76 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which fills one or more ndarrays. -* -* @private -* @param {*} value - fill value -* @returns {Function} ndarray function -*/ -function fill( value ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - */ - function ndarrayFcn( arrays ) { - var opts; - var sub; - var arr; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - opts = { - 'order': '' - }; - for ( j = 0; j < M; j++ ) { - arr = arrays[ j ]; - opts.order = arrays[ j ].order; - for ( i = 0; i < N; i++ ) { - sub = ind2sub( sh, i, opts ); - sub.push( value ); - arr.set.apply( arr, sub ); - } - } - } -} - - -// EXPORTS // - -module.exports = fill; diff --git a/test/fixtures/foreach.js b/test/fixtures/foreach.js deleted file mode 100644 index a426290..0000000 --- a/test/fixtures/foreach.js +++ /dev/null @@ -1,72 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function forEach( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - fcn.apply( null, args ); - } -} - - -// EXPORTS // - -module.exports = forEach; diff --git a/test/fixtures/map1n.js b/test/fixtures/map1n.js deleted file mode 100644 index 614196b..0000000 --- a/test/fixtures/map1n.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function which maps the return value of a callback to `N` arrays. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function map1N( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var v; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - v = fcn(); - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - sub.push( v ); - arrays[ j ].set.apply( arrays[ j ], sub ); - } - } -} - - -// EXPORTS // - -module.exports = map1N; diff --git a/test/fixtures/nullary.js b/test/fixtures/nullary.js deleted file mode 100644 index 4f22126..0000000 --- a/test/fixtures/nullary.js +++ /dev/null @@ -1,36 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Nullary callback. -* -* @private -* @returns {number} value -*/ -function nullary() { - return 3.0; -} - - -// EXPORTS // - -module.exports = nullary; diff --git a/test/fixtures/quaternary.js b/test/fixtures/quaternary.js deleted file mode 100644 index 548437b..0000000 --- a/test/fixtures/quaternary.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quaternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @returns {number} sum -*/ -function quaternary( x, y, z, w ) { - return x + y + z + w; -} - - -// EXPORTS // - -module.exports = quaternary; diff --git a/test/fixtures/quinary.js b/test/fixtures/quinary.js deleted file mode 100644 index 36068de..0000000 --- a/test/fixtures/quinary.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quinary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @param {number} u - input value -* @returns {number} sum -*/ -function quinary( x, y, z, w, u ) { - return x + y + z + w + u; -} - - -// EXPORTS // - -module.exports = quinary; diff --git a/test/fixtures/sum.js b/test/fixtures/sum.js deleted file mode 100644 index efdbb1b..0000000 --- a/test/fixtures/sum.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which computes the sum across one or more ndarrays. -* -* @private -* @param {Object} ctx - context -* @param {number} ctx.sum - initial sum -* @returns {Function} ndarray function -*/ -function wrapper( ctx ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - * @param {Function} [fcn] - callback - */ - function ndarrayFcn( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var f; - var i; - var j; - - if ( arguments.length > 1 ) { - f = fcn; - } - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - if ( f ) { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - ctx.sum += f.apply( null, args ); - } - } else { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - ctx.sum += arrays[ j ].get.apply( arrays[ j ], sub ); - } - } - } - } -} - - -// EXPORTS // - -module.exports = wrapper; diff --git a/test/fixtures/ternary.js b/test/fixtures/ternary.js deleted file mode 100644 index 0595d5f..0000000 --- a/test/fixtures/ternary.js +++ /dev/null @@ -1,39 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Ternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @returns {number} sum -*/ -function ternary( x, y, z ) { - return x + y + z; -} - - -// EXPORTS // - -module.exports = ternary; diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d6c2c8e..0000000 --- a/test/test.js +++ /dev/null @@ -1,363 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var fill = require( './fixtures/fill.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either a function or an array of functions as a first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( value, types, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object as a second argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided either an array-like object or `null` as a third argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - dispatch( unary, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a positive integer for a fourth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 0, - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a fifth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, value, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a sixth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, 1, value ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function array)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var fcns = [ unary, unary, unary ]; - var data = [ abs, abs, abs ]; - dispatch( fcns, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function argument)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs, abs, abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the length of `data` argument does not match the number of ndarray functions', function test( t ) { - var values; - var i; - - values = [ - [], - [ abs, abs ], - [ abs, abs, abs ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var fcns = [ unary ]; - dispatch( fcns, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the fourth argument is incompatible with the number of input and output ndarrays', function test( t ) { - var values; - var i; - - values = [ - 0, - 1, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of specified input and output ndarrays is zero', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var types = [ 'float64' ]; - dispatch( fill( 3 ), types, null, 1, 0, 0 ); - } -}); - -tape( 'the function returns an ndarray function interface', function test( t ) { - var types; - var data; - var f; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - f = dispatch( unary, types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ unary ], types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( fill( 3 ), types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ fill( 3 ) ], types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.two_arrays.js b/test/test.two_arrays.js deleted file mode 100644 index 071500e..0000000 --- a/test/test.two_arrays.js +++ /dev/null @@ -1,808 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var dtype = require( '@stdlib/ndarray-base-buffer-dtype' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var forEach = require( './fixtures/foreach.js' ); -var map1N = require( './fixtures/map1n.js' ); -var fill = require( './fixtures/fill.js' ); -var sum = require( './fixtures/sum.js' ); - - -// TESTS // - -tape( 'the function returns a function which throws an error if not provided an ndarray for the first argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var ybuf = new Float64Array( 10 ); - var y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( value, y ); - }; - } -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the second argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var xbuf = new Float64Array( 10 ); - var x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( x, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided insufficient arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var f; - var x; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [], - [ x ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided too many arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var ybuf; - var f; - var x; - var y; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [ x, y, y ], - [ x, y, y, y ], - [ x, y, y, y, y ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if unable to resolve a ndarray function supporting the provided array argument data types', function test( t ) { - var values; - var types; - var data; - var xbuf; - var fcn; - var x; - var i; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ abs, abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 4 ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - values = [ - new Uint8Array( 4 ), - new Int32Array( 4 ), - [ 0, 0, 0, 0 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided an array having data type: ' + dtype( values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var y = ndarray( dtype( value ), value, [ value.length ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - }; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only input arrays)', function test( t ) { - var types; - var xbuf; - var ybuf; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only output arrays)', function test( t ) { - var expected; - var types; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only input arrays)', function test( t ) { - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var ctx; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcns = [ - sum( ctx ), - sum( ctx ) - ]; - fcn = dispatch( fcns, types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only output arrays)', function test( t ) { - var expected; - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcns = [ - fill( 3.0 ), - fill( 4.0 ) - ]; - fcn = dispatch( fcns, types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - - fcn = dispatch( forEach, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - - fcn = dispatch( map1N, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - fcns = [ - forEach, - forEach - ]; - fcn = dispatch( fcns, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - fcns = [ - map1N, - map1N - ]; - fcn = dispatch( fcns, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - fcns = [ - unary, - unary - ]; - fcn = dispatch( fcns, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which returns one or more output arrays, if one or more output arrays is specified, and otherwise returns `undefined`', function test( t ) { - var types; - var data; - var xbuf; - var ybuf; - var out; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - // No output arrays... - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, void 0, 'returns expected value' ); - - // One output array... - data = [ - abs, - abs - ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - fcn = dispatch( fill( 3.0 ), types, null, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - // Two output arrays... - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.end(); -}); From d57c0ebd0e3c04731a8444b566be9fd00acedac3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 03:43:45 +0000 Subject: [PATCH 014/109] Transform error messages --- lib/main.js | 28 ++++++++++++++-------------- package.json | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/main.js b/lib/main.js index 3d28781..c8218ef 100644 --- a/lib/main.js +++ b/lib/main.js @@ -27,7 +27,7 @@ var isFunctionArray = require( '@stdlib/assert-is-function-array' ); var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var indexOfTypes = require( './index_of_types.js' ); @@ -89,43 +89,43 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { if ( isFunction( fcns ) ) { fcn = fcns; } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) ); + throw new TypeError( format( '0Mq5s', fcns ) ); } if ( !isCollection( types ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) ); + throw new TypeError( format( '0Mq3A', types ) ); } if ( !isCollection( data ) && data !== null ) { throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); } if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) ); + throw new TypeError( format( '0Mq5u', nargs ) ); } if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) ); + throw new TypeError( format( '0Mq5v', nin ) ); } if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) ); + throw new TypeError( format( '0Mq5w', nout ) ); } narrays = nin + nout; if ( narrays === 0 ) { - throw new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' ); + throw new Error( format( '0Mq0h' ) ); } if ( nargs !== narrays ) { - throw new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' ); + throw new Error( format( '0Mq0i' ) ); } if ( fcn ) { nfcns = types.length / narrays; if ( !isInteger( nfcns ) ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format( '0Mq0j' ) ); } } else { nfcns = fcns.length; if ( types.length !== nfcns*narrays ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format( '0Mq0j' ) ); } } if ( data && data.length !== nfcns ) { - throw new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' ); + throw new Error( format( '0Mq0k' ) ); } return dispatcher; @@ -154,9 +154,9 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { argc = arguments.length; if ( argc !== nargs ) { if ( argc < nargs ) { - throw new Error( 'invalid invocation. Insufficient arguments.' ); + throw new Error( format( '0Mq0l' ) ); } - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format( '0Mq0m' ) ); } arrays = []; dtypes = []; @@ -177,7 +177,7 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { // Check whether we were able to successfully resolve an ndarray function: if ( idx < 0 ) { - throw new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' ); + throw new TypeError( format( '0Mq0p' ) ); } // Retrieve the ndarray function: if ( fcn ) { diff --git a/package.json b/package.json index 014d480..9569eb2 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-ndarray-like": "^0.0.x", "@stdlib/assert-is-nonnegative-integer": "^0.0.x", "@stdlib/assert-is-positive-integer": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From f06d30c8a475ade6de3dc7d1cb5f56e499920599 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 11:05:05 +0000 Subject: [PATCH 015/109] Remove files --- index.d.ts | 334 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 3028 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index e8f79c8..0000000 --- a/index.d.ts +++ /dev/null @@ -1,334 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* ndarray function. -* -* @param arrays - array containing input and output ndarrays -* @param data - ndarray function data (e.g., a callback) -* -* @example -* var numel = require( `@stdlib/ndarray/base/numel` ); -* var ind2sub = require( `@stdlib/ndarray/ind2sub` ); -* -* function ndarrayFcn( arrays, fcn ) { -* var xord; -* var yord; -* var opts; -* var sub; -* var sh; -* var N; -* var x; -* var y; -* var v; -* var i; -* -* x = arrays[ 0 ]; -* y = arrays[ 1 ]; -* sh = x.shape; -* N = numel( sh ); -* if ( N <= 0 ) { -* return; -* } -* xord = x.order; -* yord = y.order; -* opts = {}; -* opts.order = xord; -* for ( i = 0; i < N; i++ ) { -* // Convert a linear index to subscripts: -* opts.order = xord; -* sub = ind2sub( sh, i, opts ); -* -* // Retrieve an element from `x`: -* v = x.get.apply( x, sub ); -* -* // Convert a linear index to subscripts: -* opts.order = yord; -* sub = ind2sub( sh, i, opts ); -* -* // Append the result of applying the callback: -* sub.push( fcn( v ) ); -* -* // Assign the result to an element in `y`: -* y.set.apply( y, sub ); -* } -* } -*/ -type ndarrayFcn = ( arrays: Array, data?: any ) => void; - -/** -* Interface describing an ndarray function dispatcher. -*/ -interface Dispatcher { - /** - * Invokes an ndarray function based on the provided array data type(s). - * - * @param x - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array - * - * @example - * var nullary = require( `@stdlib/ndarray/base/nullary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function value() { - * return 3.14; - * } - * - * var types = [ 'float64' ]; - * var data = [ value ]; - * - * var fcn = dispatch( nullary, types, data, 1, 0, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( 5 ); - * var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x ); - * // xbuf => [ 3.14, 3.14, 3.14, 3.14, 3.14 ] - */ - ( x: ndarray ): ndarray | void; - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var unary = require( `@stdlib/ndarray/base/unary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * var abs = require( `@stdlib/math/base/special/abs` ); - * - * var types = [ 'float64', 'float64' ]; - * var data = [ abs ]; - * - * var fcn = dispatch( unary, types, data, 2, 1, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - * var ybuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y ); - * // ybuf => [ 1.0, 2.0, 3.0 ] - */ - ( x: ndarray, y: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var ternary = require( `@stdlib/ndarray/base/ternary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add2( x, y ) { - * return x + y; - * } - * - * var types = [ 'float64', 'float64', 'float64' ]; - * var data = [ add2 ]; - * - * var fcn = dispatch( ternary, types, data, 3, 2, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z ); - * // zbuf => [ 2.0, 4.0, 6.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quaternary = require( `@stdlib/ndarray/base/quaternary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add3( x, y, z ) { - * return x + y + z; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add3 ]; - * - * var fcn = dispatch( quaternary, types, data, 4, 3, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w ); - * // wbuf => [ 3.0, 6.0, 9.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @param args - ndarray arguments - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quinary = require( `@stdlib/ndarray/base/quinary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add4( x, y, z, w ) { - * return x + y + z + w; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add4 ]; - * - * var fcn = dispatch( quinary, types, data, 5, 4, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ubuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var u = ndarray( 'float64', ubuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w, u ); - * // ubuf => [ 4.0, 8.0, 12.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray, ...args: Array ): ndarray | void; // tslint:disable-line:max-line-length unified-signatures -} - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param fcns - list of ndarray functions -* @param types - one-dimensional list of ndarray argument data types -* @param data - ndarray function data (e.g., callbacks) -* @param nargs - total number of ndarray function interface arguments -* @param nin - number of input ndarrays -* @param nout - number of output ndarrays -* @throws first argument must be either a function or an array of functions -* @throws second argument must be an array-like object -* @throws third argument must be an array-like object or `null` -* @throws third and first arguments must have the same number of elements -* @throws fourth argument must be a positive integer -* @throws fifth argument must be a nonnegative integer -* @throws sixth argument must be a nonnegative integer -* @throws fourth argument must equal the specified number of input and output arrays -* @throws number of types must match the number of functions times the total number of array arguments for each function -* @throws interface must accept at least one input and/or output ndarray -* @returns ndarray function interface -* -* @example -* var unary = require( `@stdlib/ndarray/base/unary` ); -* var abs = require( `@stdlib/math/base/special/abs` ); -* var Float64Array = require( `@stdlib/array/float64` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var fcn = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* fcn( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function dispatch( fcns: ndarrayFcn | ArrayLike, types: ArrayLike, data: ArrayLike | null, nargs: number, nin: number, nout: number ): Dispatcher; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = dispatch; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index f48c2d5..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function m(r,e,t,i,s,n,o,l,m){var d,a,h,f;for(d=n,h=0;h [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0Mq5s', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0Mq3A', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0Mq5u', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0Mq5v', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0Mq5w', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format( '0Mq0h' ) );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format( '0Mq0i' ) );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format( '0Mq0k' ) );\n\t}\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format( '0Mq0l' ) );\n\t\t\t}\n\t\t\tthrow new Error( format( '0Mq0m' ) );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( v.dtype );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format( '0Mq0p' ) );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n"],"names":["indexOfTypes","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","i","j","dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","push","dtype","slice"],"mappings":";;uvBA6EA,SAASA,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,KAAgBE,EAAGI,GADdE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,EAEP,OAAQ,EChBT,SAASU,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,sFAAuFV,IAErH,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAQ,UAE1B,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAQ,UAE1B,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAQ,eAI1B,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAQ,UAG3B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAQ,UAE1B,OAeA,WACC,IAAIO,EACAC,EACAC,EACAC,EACAC,EACAC,EACA3B,EAGJ,IADAwB,EAAOI,UAAUR,UACHd,EAAQ,CACrB,GAAKkB,EAAOlB,EACX,MAAM,IAAIa,MAAOJ,EAAQ,UAE1B,MAAM,IAAII,MAAOJ,EAAQ,UAI1B,IAFAO,EAAS,GACTC,EAAS,GACHvB,EAAI,EAAGA,EAAIM,EAAON,IAAM,CAE7B,IAAM6B,EADNH,EAAIE,UAAW5B,IAEd,MAAKA,EAAIO,EACF,IAAIO,UAAWC,EAAQ,6EAA8EW,IAErG,IAAIZ,UAAWC,EAAQ,8EAA+EW,IAG9GJ,EAAOQ,KAAMJ,GACbH,EAAOO,KAAMJ,EAAEK,OAMhB,IAHAN,EAAMrC,EAAcsB,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGc,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAIT,UAAWC,EAAQ,UAI7BY,EADIhB,GAGAR,EAAMsB,GAGNpB,EACJsB,EAAGL,EAAQjB,EAAMoB,IAEjBE,EAAGL,GAEJ,GAAc,IAATd,EACJ,OAAOc,EAAQb,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOc,EAAOU,MAAOzB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 49ef45c..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From de5a6cfddce3ec76fe5150c5371b575fecde84e4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 11:05:58 +0000 Subject: [PATCH 016/109] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 760 ------ .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 59 +- benchmark/benchmark.dispatch_size.js | 156 -- benchmark/benchmark.js | 81 - branches.md | 53 - docs/repl.txt | 87 - docs/types/test.ts | 641 ----- examples/add.js | 121 - examples/sin.js | 142 -- examples/unary.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/index_of_types.js | 106 - lib/main.js | 207 -- package.json | 76 +- stats.html | 2689 +++++++++++++++++++++ test/fixtures/binary.js | 38 - test/fixtures/fill.js | 76 - test/fixtures/foreach.js | 72 - test/fixtures/map1n.js | 74 - test/fixtures/nullary.js | 36 - test/fixtures/quaternary.js | 40 - test/fixtures/quinary.js | 41 - test/fixtures/sum.js | 98 - test/fixtures/ternary.js | 39 - test/test.js | 363 --- test/test.two_arrays.js | 808 ------- 51 files changed, 2723 insertions(+), 6396 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.dispatch_size.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/add.js delete mode 100644 examples/sin.js delete mode 100644 examples/unary.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/index_of_types.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/fixtures/binary.js delete mode 100644 test/fixtures/fill.js delete mode 100644 test/fixtures/foreach.js delete mode 100644 test/fixtures/map1n.js delete mode 100644 test/fixtures/nullary.js delete mode 100644 test/fixtures/quaternary.js delete mode 100644 test/fixtures/quinary.js delete mode 100644 test/fixtures/sum.js delete mode 100644 test/fixtures/ternary.js delete mode 100644 test/test.js delete mode 100644 test/test.two_arrays.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index e5177a9..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-09-01T01:34:15.621Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ac0b7cd..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a7a7f51..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.9.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 920b304..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 39b1613..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 7ca169c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 8 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "::set-output name=package_name::$name" - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "::set-output name=data::$data" - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v2 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v2 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 5094681..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,760 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -291,7 +284,7 @@ console.log( ybuf ); ## 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. +This package is part of [stdlib][stdlib], a standard library 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]. @@ -353,11 +346,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm diff --git a/benchmark/benchmark.dispatch_size.js b/benchmark/benchmark.dispatch_size.js deleted file mode 100644 index 3bd0418..0000000 --- a/benchmark/benchmark.dispatch_size.js +++ /dev/null @@ -1,156 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib/main.js' ); - - -// FUNCTIONS // - -/** -* Evaluates the identity function. -* -* @private -* @param {*} v - value -* @returns {*} input value -*/ -function identity( v ) { - return v; -} - -/** -* Dummy function which throws an error. -* -* @private -* @throws {Error} unexpected error -*/ -function throwError() { - throw new Error( 'unexpected error' ); -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} size - dispatch size -* @returns {Function} benchmark function -*/ -function createBenchmark( size ) { - var types; - var data; - var fcn; - var x; - var y; - var t; - var i; - - types = []; - - // Create dummy types... - for ( i = 0; i < (size-1)*2; i += 2 ) { - t = 'foo' + i; - types.push( t ); - types.push( t ); - } - // Append test types: - types.push( 'float64' ); - types.push( 'float64' ); - - // Define a list of callbacks: - data = []; - for ( i = 0; i < size-1; i++ ) { - data.push( throwError ); - } - // Append a test callback: - data.push( identity ); - - // Create the dispatcher: - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - // Create sample arrays: - x = new Float64Array( 1 ); - y = new Float64Array( x.length ); - - x = ndarray( 'float64', x, [ 1 ], [ 1 ], 0, 'row-major' ); - y = ndarray( 'float64', y, [ 1 ], [ 1 ], 0, 'row-major' ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var z; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x.data[ 0 ] = i; - z = fcn( x, y ); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var size; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - size = pow( 2, i ); - f = createBenchmark( size ); - bench( pkg+':size='+size, f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index a70dc5c..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::fcns_array', function benchmark( b ) { - var types; - var fcns; - var data; - var out; - var i; - - fcns = [ unary ]; - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( fcns, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::fcn_arg', function benchmark( b ) { - var types; - var data; - var out; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( unary, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index d04d051..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch" -click B href "https://github.com/stdlib-js/ndarray-dispatch/tree/main" -click C href "https://github.com/stdlib-js/ndarray-dispatch/tree/production" -click D href "https://github.com/stdlib-js/ndarray-dispatch/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-dispatch/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-dispatch/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch -[production-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 02fe150..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,87 +0,0 @@ - -{{alias}}( fcns, types, data, nargs, nin, nout ) - Returns an ndarray function interface which performs multiple dispatch. - - An ndarray function interface has the following signature: - - f( x, y, ... ) - - where - - - x: ndarray. - - y: ndarray. - - ...: additional ndarrays. - - The number of parameters is derived from `nargs`, the number of input - ndarrays is derived from `nin`, and the number of output ndarrays is derived - from `nout`. - - Parameters - ---------- - fcns: Function|ArrayLikeObject - List of ndarray functions. An ndarray function should have the following - signature: - - f( arrays, data ) - - where - - - arrays: array containing input and output ndarrays. - - data: ndarray function data (e.g., a callback). - - For convenience, a single ndarray function may be provided which will be - invoked whenever the ndarray argument data types match a sequence of - types in `types`. Providing a single ndarray function is particularly - convenient for the case where, regardless of array data types, - traversing arrays remains the same, but the ndarray function `data` - differs (e.g., callbacks which differ based on the array data types). - - types: ArrayLikeObject - One-dimensional list of ndarray argument data types. - - data: ArrayLikeObject|null - ndarray function data (e.g., callbacks). If `null`, a returned ndarray - function interface does **not** provide a `data` argument to an invoked - ndarray function. - - nargs: integer - Total number of ndarray function interface arguments. - - nin: integer - Number of input ndarrays. - - nout: integer - Number of output ndarrays. - - Returns - ------- - fcn: Function - ndarray function interface. - - Examples - -------- - // Define ndarray argument data types: - > var t = [ 'float64', 'float64', 'float32', 'float32' ]; - - // Define a list of ndarray function data (callbacks): - > var d = [ {{alias:@stdlib/math/base/special/abs}}, {{alias:@stdlib/math/base/special/absf}} ]; - - // Create an ndarray function interface for applying unary callbacks: - > var f = {{alias}}( {{alias:@stdlib/ndarray/base/unary}}, t, d, 2, 1, 1 ); - - // Create an input ndarray: - > var xbuf = new {{alias:@stdlib/array/float64}}( [ -1.0, -2.0, -3.0, -4.0 ] ); - > var x = {{alias:@stdlib/ndarray/ctor}}( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Create an output ndarray: - > var ybuf = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 0.0, 0.0 ] ); - > var y = {{alias:@stdlib/ndarray/ctor}}( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Compute the element-wise absolute value: - > f( x, y ); - > ybuf - [ 1.0, 2.0, 3.0, 4.0 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 397185e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,641 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// tslint:disable:max-file-line-count - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import dispatch = require( './index' ); - - -// FUNCTIONS // - -/** -* Nullary callback. -* -* @return input value -*/ -function nullary(): any { - return 5.0; -} - -/** -* Unary callback. -* -* @param x - input value -* @return input value -*/ -function unary( x: any ): any { - return x; -} - -/** -* Binary callback. -* -* @param x - input value -* @param y - input value -* @return output value -*/ -function binary( x: number, y: number ): number { - return x + y; -} - -/** -* Ternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @return output value -*/ -function ternary( x: number, y: number, z: number ): number { - return x + y + z; -} - -/** -* Quaternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @param w - input value -* @return output value -*/ -function quaternary( x: number, y: number, z: number, w: number ): number { - return x + y + z + w; -} - -/** -* Mock `ind2sub` function. -* -* @param shape - dimensions -* @param idx - linear index -* @param opts - options -* @return subscripts -*/ -function ind2sub( shape: ArrayLike, idx: number, opts?: any ): Array { // tslint:disable-line:max-line-length - let out; - let i; - - out = []; - if ( typeof opts === 'object' && opts !== null && opts.order === 'row-major' ) { // tslint:disable-line:max-line-length no-unsafe-any - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } else { - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } - return out; -} - -/** -* Mock ndarray function. -* -* @param arrays - ndarrays -* @param fcn - callback -*/ -function ndarrayFcn( arrays: Array, fcn: ( x: any ) => any ): void { - let xord; - let yord; - let opts; - let sub; - let sh; - let N; - let x; - let y; - let v; - let i; - - x = arrays[ 0 ]; - y = arrays[ 1 ]; - sh = x.shape; - if ( sh.length === 0 ) { - return; - } - N = 1; - for ( i = 0; i < sh.length; i += 1 ) { - N *= sh[ i ]; - } - xord = x.order; - yord = y.order; - opts = { - 'order': '' - }; - opts.order = xord; - for ( i = 0; i < N; i += 1 ) { - // Convert a linear index to subscripts: - opts.order = xord; - sub = ind2sub( sh, i, opts ); - - // Retrieve an element from `x`: - v = x.get.apply( x, sub ); - - // Convert a linear index to subscripts: - opts.order = yord; - sub = ind2sub( sh, i, opts ); - - // Append the result of applying the callback: - sub[ sub.length ] = fcn( v ) as number; - - // Assign the result to an element in `y`: - y.set.apply( y, sub ); - } -} - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a dispatch function... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, 1 ); // $ExpectType Dispatcher - dispatch( [ ndarrayFcn ], types, data, 2, 1, 1 ); // $ExpectType Dispatcher -} - -// The compiler throws an error if the function is provided a first argument which is not either an ndarray function or an array-like object containing ndarray functions... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( '10', types, data, 2, 1, 1 ); // $ExpectError - dispatch( 10, types, data, 2, 1, 1 ); // $ExpectError - dispatch( true, types, data, 2, 1, 1 ); // $ExpectError - dispatch( false, types, data, 2, 1, 1 ); // $ExpectError - dispatch( null, types, data, 2, 1, 1 ); // $ExpectError - dispatch( undefined, types, data, 2, 1, 1 ); // $ExpectError - dispatch( [ '1' ], types, data, 2, 1, 1 ); // $ExpectError - dispatch( {}, types, data, 2, 1, 1 ); // $ExpectError - dispatch( ( x: number ): number => x, types, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object... -{ - const data = [ unary ]; - - dispatch( ndarrayFcn, 10, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, true, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, false, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, null, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, undefined, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, {}, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object or null... -{ - const types = [ 'float64', 'float64' ]; - - dispatch( ndarrayFcn, types, 10, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, true, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, false, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, undefined, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, {}, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, '10', 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, true, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, false, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, null, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, undefined, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, [ '1' ], 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, {}, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, ( x: number ): number => x, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, '10', 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, true, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, false, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, null, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, undefined, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, [ '1' ], 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, {}, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, ( x: number ): number => x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, '10' ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, true ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, false ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, null ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, undefined ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, [ '1' ] ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, {} ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch(); // $ExpectError - dispatch( ndarrayFcn ); // $ExpectError - dispatch( ndarrayFcn, types ); // $ExpectError - dispatch( ndarrayFcn, types, data ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, 1, 0 ); // $ExpectError -} - -// The function returns a dispatch function... -{ - const x = array(); - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const t1 = [ 'float64' ]; - const d1 = [ nullary ]; - const f1 = dispatch( ndarrayFcn, t1, d1, 1, 1, 0 ); - f1( x ); // $ExpectType void | ndarray - - const t2 = [ 'float64', 'float64' ]; - const d2 = [ unary ]; - const f2 = dispatch( ndarrayFcn, t2, d2, 2, 1, 1 ); - f2( x, y ); // $ExpectType void | ndarray - - const t3 = [ 'float64', 'float64', 'float64' ]; - const d3 = [ binary ]; - const f3 = dispatch( ndarrayFcn, t3, d3, 3, 2, 1 ); - f3( x, y, z ); // $ExpectType void | ndarray - - const t4 = [ 'float64', 'float64', 'float64', 'float64' ]; - const d4 = [ ternary ]; - const f4 = dispatch( ndarrayFcn, t4, d4, 4, 3, 1 ); - f4( x, y, z, w ); // $ExpectType void | ndarray - - const t5 = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const d5 = [ quaternary ]; - const f5 = dispatch( ndarrayFcn, t5, d5, 5, 4, 1 ); - f5( x, y, z, w, u ); // $ExpectType void | ndarray -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (1 ndarray)... -{ - const types = [ 'float64' ]; - const data = [ nullary ]; - - const f = dispatch( ndarrayFcn, types, data, 1, 0, 1 ); - f( '10' ); // $ExpectError - f( 10 ); // $ExpectError - f( true ); // $ExpectError - f( false ); // $ExpectError - f( null ); // $ExpectError - f( undefined ); // $ExpectError - f( [ '1' ] ); // $ExpectError - f( {} ); // $ExpectError - f( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( 10, y ); // $ExpectError - f( '10', y ); // $ExpectError - f( true, y ); // $ExpectError - f( false, y ); // $ExpectError - f( null, y ); // $ExpectError - f( undefined, y ); // $ExpectError - f( [ '1' ], y ); // $ExpectError - f( {}, y ); // $ExpectError - f( ( x: number ): number => x, y ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const x = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( x, 10 ); // $ExpectError - f( x, '10' ); // $ExpectError - f( x, true ); // $ExpectError - f( x, false ); // $ExpectError - f( x, null ); // $ExpectError - f( x, undefined ); // $ExpectError - f( x, [ '1' ] ); // $ExpectError - f( x, {} ); // $ExpectError - f( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( 10, y, z ); // $ExpectError - f( '10', y, z ); // $ExpectError - f( true, y, z ); // $ExpectError - f( false, y, z ); // $ExpectError - f( null, y, z ); // $ExpectError - f( undefined, y, z ); // $ExpectError - f( [ '1' ], y, z ); // $ExpectError - f( {}, y, z ); // $ExpectError - f( ( x: number ): number => x, y, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, 10, z ); // $ExpectError - f( x, '10', z ); // $ExpectError - f( x, true, z ); // $ExpectError - f( x, false, z ); // $ExpectError - f( x, null, z ); // $ExpectError - f( x, undefined, z ); // $ExpectError - f( x, [ '1' ], z ); // $ExpectError - f( x, {}, z ); // $ExpectError - f( x, ( x: number ): number => x, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, y, '10' ); // $ExpectError - f( x, y, true ); // $ExpectError - f( x, y, false ); // $ExpectError - f( x, y, null ); // $ExpectError - f( x, y, undefined ); // $ExpectError - f( x, y, [ '1' ] ); // $ExpectError - f( x, y, {} ); // $ExpectError - f( x, y, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( 10, y, z, w ); // $ExpectError - f( '10', y, z, w ); // $ExpectError - f( true, y, z, w ); // $ExpectError - f( false, y, z, w ); // $ExpectError - f( null, y, z, w ); // $ExpectError - f( undefined, y, z, w ); // $ExpectError - f( [ '1' ], y, z, w ); // $ExpectError - f( {}, y, z, w ); // $ExpectError - f( ( x: number ): number => x, y, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, 10, z, w ); // $ExpectError - f( x, '10', z, w ); // $ExpectError - f( x, true, z, w ); // $ExpectError - f( x, false, z, w ); // $ExpectError - f( x, null, z, w ); // $ExpectError - f( x, undefined, z, w ); // $ExpectError - f( x, [ '1' ], z, w ); // $ExpectError - f( x, {}, z, w ); // $ExpectError - f( x, ( x: number ): number => x, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, 10, w ); // $ExpectError - f( x, y, '10', w ); // $ExpectError - f( x, y, true, w ); // $ExpectError - f( x, y, false, w ); // $ExpectError - f( x, y, null, w ); // $ExpectError - f( x, y, undefined, w ); // $ExpectError - f( x, y, [ '1' ], w ); // $ExpectError - f( x, y, {}, w ); // $ExpectError - f( x, y, ( x: number ): number => x, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, z, 10 ); // $ExpectError - f( x, y, z, '10' ); // $ExpectError - f( x, y, z, true ); // $ExpectError - f( x, y, z, false ); // $ExpectError - f( x, y, z, null ); // $ExpectError - f( x, y, z, undefined ); // $ExpectError - f( x, y, z, [ '1' ] ); // $ExpectError - f( x, y, z, {} ); // $ExpectError - f( x, y, z, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( 10, y, z, w, u ); // $ExpectError - f( '10', y, z, w, u ); // $ExpectError - f( true, y, z, w, u ); // $ExpectError - f( false, y, z, w, u ); // $ExpectError - f( null, y, z, w, u ); // $ExpectError - f( undefined, y, z, w, u ); // $ExpectError - f( [ '1' ], y, z, w, u ); // $ExpectError - f( {}, y, z, w, u ); // $ExpectError - f( ( x: number ): number => x, y, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, 10, z, w, u ); // $ExpectError - f( x, '10', z, w, u ); // $ExpectError - f( x, true, z, w, u ); // $ExpectError - f( x, false, z, w, u ); // $ExpectError - f( x, null, z, w, u ); // $ExpectError - f( x, undefined, z, w, u ); // $ExpectError - f( x, [ '1' ], z, w, u ); // $ExpectError - f( x, {}, z, w, u ); // $ExpectError - f( x, ( x: number ): number => x, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, 10, w, u ); // $ExpectError - f( x, y, '10', w, u ); // $ExpectError - f( x, y, true, w, u ); // $ExpectError - f( x, y, false, w, u ); // $ExpectError - f( x, y, null, w, u ); // $ExpectError - f( x, y, undefined, w, u ); // $ExpectError - f( x, y, [ '1' ], w, u ); // $ExpectError - f( x, y, {}, w, u ); // $ExpectError - f( x, y, ( x: number ): number => x, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, 10, u ); // $ExpectError - f( x, y, z, '10', u ); // $ExpectError - f( x, y, z, true, u ); // $ExpectError - f( x, y, z, false, u ); // $ExpectError - f( x, y, z, null, u ); // $ExpectError - f( x, y, z, undefined, u ); // $ExpectError - f( x, y, z, [ '1' ], u ); // $ExpectError - f( x, y, z, {}, u ); // $ExpectError - f( x, y, z, ( x: number ): number => x, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fifth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, w, 10 ); // $ExpectError - f( x, y, z, w, '10' ); // $ExpectError - f( x, y, z, w, true ); // $ExpectError - f( x, y, z, w, false ); // $ExpectError - f( x, y, z, w, null ); // $ExpectError - f( x, y, z, w, undefined ); // $ExpectError - f( x, y, z, w, [ '1' ] ); // $ExpectError - f( x, y, z, w, {} ); // $ExpectError - f( x, y, z, w, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/add.js b/examples/add.js deleted file mode 100644 index 775b711..0000000 --- a/examples/add.js +++ /dev/null @@ -1,121 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var dispatch = require( './../lib' ); - -function add2( arrays ) { - var opts; - var xo; - var yo; - var zo; - var sx; - var sy; - var sz; - var sh; - var N; - var x; - var y; - var z; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - z = arrays[ 2 ]; - xo = x.order; - yo = y.order; - zo = z.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - opts.order = yo; - sy = ind2sub( sh, i, opts ); - v = x.get.apply( x, sx ) + y.get.apply( y, sy ); - - opts.order = zo; - sz = ind2sub( sh, i, opts ); - sz.push( v ); - z.set.apply( z, sz ); - } -} - -var fcns = [ - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2 -]; - -var types = [ - dtypes.float64, dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.int32, dtypes.int32, - dtypes.uint32, dtypes.uint32, dtypes.uint32, - dtypes.int16, dtypes.int16, dtypes.int16, - dtypes.uint16, dtypes.uint16, dtypes.uint16, - dtypes.int8, dtypes.int8, dtypes.int8, - dtypes.uint8, dtypes.uint8, dtypes.uint8, - dtypes.uint8c, dtypes.uint8c, dtypes.uint8c -]; - -var add = dispatch( fcns, types, null, 3, 2, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var zbuf = new Float64Array( xbuf.length ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var z = ndarray( 'float64', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); - -xbuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -ybuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -zbuf = new Int32Array( xbuf.length ); - -x = ndarray( 'int32', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'int32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -z = ndarray( 'int32', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); diff --git a/examples/sin.js b/examples/sin.js deleted file mode 100644 index 8cd4871..0000000 --- a/examples/sin.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int8Array = require( '@stdlib/array-int8' ); -var sin = require( '@stdlib/math-base-special-sin' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/strided-dtypes' ); -var dispatch = require( './../lib' ); - -function apply( arrays, fcn ) { - var opts; - var xo; - var yo; - var sx; - var sy; - var sh; - var N; - var x; - var y; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - xo = x.order; - yo = y.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - v = fcn( x.get.apply( x, sx ) ); - - opts.order = yo; - sy = ind2sub( sh, i, opts ); - sy.push( v ); - y.set.apply( y, sy ); - } -} - -var fcns = [ - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply -]; - -var types = [ - dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float64, - dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.float64, - dtypes.uint32, dtypes.float64, - dtypes.int16, dtypes.float64, - dtypes.int16, dtypes.float32, - dtypes.uint16, dtypes.float64, - dtypes.uint16, dtypes.float32, - dtypes.int8, dtypes.float64, - dtypes.int8, dtypes.float32, - dtypes.uint8, dtypes.float64, - dtypes.uint8, dtypes.float32, - dtypes.uint8c, dtypes.float64, - dtypes.uint8c, dtypes.float32 -]; - -var data = [ - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin -]; - -var sine = dispatch( fcns, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); - -xbuf = new Int8Array( [ 1, 2, 3, 4, 5 ] ); -ybuf = new Float32Array( xbuf.length ); - -x = ndarray( 'int8', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'float32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); diff --git a/examples/unary.js b/examples/unary.js deleted file mode 100644 index e9c3fb4..0000000 --- a/examples/unary.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -var unary = require( '@stdlib/ndarray-base-unary' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var dispatch = require( './../lib' ); - -var types = [ 'float64', 'float64' ]; - -var data = [ - abs -]; - -var absolute = dispatch( unary, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -absolute( x, y ); -console.log( ybuf ); -// => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 610167d..e8f79c8 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..f48c2d5 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function m(r,e,t,i,s,n,o,l,m){var d,a,h,f;for(d=n,h=0;h [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0Mq5s', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0Mq3A', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0Mq5u', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0Mq5v', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0Mq5w', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format( '0Mq0h' ) );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format( '0Mq0i' ) );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format( '0Mq0k' ) );\n\t}\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format( '0Mq0l' ) );\n\t\t\t}\n\t\t\tthrow new Error( format( '0Mq0m' ) );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( v.dtype );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format( '0Mq0p' ) );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n"],"names":["indexOfTypes","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","i","j","dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","push","dtype","slice"],"mappings":";;uvBA6EA,SAASA,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,KAAgBE,EAAGI,GADdE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,EAEP,OAAQ,EChBT,SAASU,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,sFAAuFV,IAErH,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAQ,UAE1B,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAQ,UAE1B,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAQ,eAI1B,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAQ,UAG3B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAQ,UAE1B,OAeA,WACC,IAAIO,EACAC,EACAC,EACAC,EACAC,EACAC,EACA3B,EAGJ,IADAwB,EAAOI,UAAUR,UACHd,EAAQ,CACrB,GAAKkB,EAAOlB,EACX,MAAM,IAAIa,MAAOJ,EAAQ,UAE1B,MAAM,IAAII,MAAOJ,EAAQ,UAI1B,IAFAO,EAAS,GACTC,EAAS,GACHvB,EAAI,EAAGA,EAAIM,EAAON,IAAM,CAE7B,IAAM6B,EADNH,EAAIE,UAAW5B,IAEd,MAAKA,EAAIO,EACF,IAAIO,UAAWC,EAAQ,6EAA8EW,IAErG,IAAIZ,UAAWC,EAAQ,8EAA+EW,IAG9GJ,EAAOQ,KAAMJ,GACbH,EAAOO,KAAMJ,EAAEK,OAMhB,IAHAN,EAAMrC,EAAcsB,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGc,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAIT,UAAWC,EAAQ,UAI7BY,EADIhB,GAGAR,EAAMsB,GAGNpB,EACJsB,EAAGL,EAAQjB,EAAMoB,IAEjBE,EAAGL,GAEJ,GAAc,IAATd,EACJ,OAAOc,EAAQb,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOc,EAAOU,MAAOzB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index f9d8aef..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Create an ndarray function interface which performs multiple dispatch. -* -* @module @stdlib/ndarray-dispatch -* -* @example -* var dispatch = require( '@stdlib/ndarray-dispatch' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// MODULES // - -var dispatch = require( './main.js' ); - - -// EXPORTS // - -module.exports = dispatch; diff --git a/lib/index_of_types.js b/lib/index_of_types.js deleted file mode 100644 index fda2297..0000000 --- a/lib/index_of_types.js +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found). -* -* ## Notes -* -* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types). -* - The function assumes that `x` is stored in row-major order. -* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`. -* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value. -* -* @private -* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension) -* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension) -* @param {ArrayLikeObject} x - input two-dimensional reference array -* @param {integer} strideX1 - `x` stride length along first dimension -* @param {integer} strideX2 - `x` stride length along second dimension -* @param {NonNegativeInteger} offsetX - `x` starting index -* @param {ArrayLikeObject} y - search array -* @param {integer} strideY - `y` stride length -* @param {NonNegativeInteger} offsetY - `y` starting index -* @returns {integer} row index (if found) and `-1` otherwise -* -* @example -* // Define a reference array to search: -* var types = [ -* 'float64', 'float64', 'float64', -* 'float32', 'float32', 'float32', -* 'uint32', 'uint32', 'float64', -* 'int32', 'int32', 'float64', -* 'uint16', 'uint16', 'float64', -* 'int16', 'int16', 'float64', -* 'uint8', 'uint8', 'float64', -* 'int8', 'int8', 'float64' -* ]; -* -* // Define reference array dimensions: -* var N = 8; // rows -* var M = 3; // columns -* -* // Define a search array: -* y1 = [ -* 'float32', 'float32', 'float32', -* ]; -* -* // Find the list of types: -* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 ); -* // returns 1 -* -// Define a search array: -* y2 = [ -* 'float32', 'float32', 'float64', -* ]; -* -* // Find the list of types: -* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 ); -* // returns -1 -*/ -function indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len - var ix; - var iy; - var i; - var j; - - // Search for the first row which matches `y`... - ix = offsetX; - for ( i = 0; i < N; i++ ) { - iy = offsetY; - for ( j = 0; j < M; j++ ) { - if ( x[ ix+(j*strideX2) ] !== y[ iy ] ) { - break; - } - iy += strideY; - } - // If we successfully iterated over all columns, then that means we've found a match... - if ( j === M ) { - return i; - } - ix += strideX1; - } - return -1; -} - - -// EXPORTS // - -module.exports = indexOfTypes; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c8218ef..0000000 --- a/lib/main.js +++ /dev/null @@ -1,207 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isFunctionArray = require( '@stdlib/assert-is-function-array' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var indexOfTypes = require( './index_of_types.js' ); - - -// MAIN // - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param {(FunctionArray|Function)} fcns - list of ndarray functions -* @param {Collection} types - one-dimensional list of ndarray argument data types -* @param {(Collection|null)} data - ndarray function data (e.g., callbacks) -* @param {PositiveInteger} nargs - total number of ndarray function interface arguments -* @param {NonNegativeInteger} nin - number of input ndarrays -* @param {NonNegativeInteger} nout - number of output ndarrays -* @throws {TypeError} first argument must be either a function or an array of functions -* @throws {TypeError} second argument must be an array-like object -* @throws {TypeError} third argument must be an array-like object or `null` -* @throws {Error} third and first arguments must have the same number of elements -* @throws {TypeError} fourth argument must be a positive integer -* @throws {TypeError} fifth argument must be a nonnegative integer -* @throws {TypeError} sixth argument must be a nonnegative integer -* @throws {Error} fourth argument must equal the specified number of input and output arrays -* @throws {Error} number of types must match the number of functions times the total number of array arguments for each function -* @throws {Error} interface must accept at least one input and/or output ndarray -* @returns {Function} ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function dispatch( fcns, types, data, nargs, nin, nout ) { - var narrays; - var nfcns; - var fcn; - - if ( isFunction( fcns ) ) { - fcn = fcns; - } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( '0Mq5s', fcns ) ); - } - if ( !isCollection( types ) ) { - throw new TypeError( format( '0Mq3A', types ) ); - } - if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); - } - if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( '0Mq5u', nargs ) ); - } - if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( '0Mq5v', nin ) ); - } - if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( '0Mq5w', nout ) ); - } - narrays = nin + nout; - if ( narrays === 0 ) { - throw new Error( format( '0Mq0h' ) ); - } - if ( nargs !== narrays ) { - throw new Error( format( '0Mq0i' ) ); - } - if ( fcn ) { - nfcns = types.length / narrays; - if ( !isInteger( nfcns ) ) { - throw new Error( format( '0Mq0j' ) ); - } - } else { - nfcns = fcns.length; - if ( types.length !== nfcns*narrays ) { - throw new Error( format( '0Mq0j' ) ); - } - } - if ( data && data.length !== nfcns ) { - throw new Error( format( '0Mq0k' ) ); - } - return dispatcher; - - /** - * ndarray function interface which performs multiple dispatch. - * - * @private - * @param {ndarrayLike} x - ndarray - * @param {...ndarrayLike} args - ndarray arguments - * @throws {Error} insufficient arguments - * @throws {Error} too many arguments - * @throws {TypeError} input array arguments must be ndarray-like objects - * @throws {TypeError} output array arguments must be ndarray-like objects - * @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types - * @returns {(ndarrayLike|Array|void)} destination array(s) - */ - function dispatcher() { - var arrays; - var dtypes; - var argc; - var idx; - var v; - var f; - var i; - - argc = arguments.length; - if ( argc !== nargs ) { - if ( argc < nargs ) { - throw new Error( format( '0Mq0l' ) ); - } - throw new Error( format( '0Mq0m' ) ); - } - arrays = []; - dtypes = []; - for ( i = 0; i < nargs; i++ ) { - v = arguments[ i ]; - if ( !isndarrayLike( v ) ) { - if ( i < nin ) { - throw new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) ); - } else { - throw new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) ); - } - } - arrays.push( v ); - dtypes.push( v.dtype ); - } - // Resolve the ndarray function satisfying the input array types: - idx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len - - // Check whether we were able to successfully resolve an ndarray function: - if ( idx < 0 ) { - throw new TypeError( format( '0Mq0p' ) ); - } - // Retrieve the ndarray function: - if ( fcn ) { - f = fcn; - } else { - f = fcns[ idx ]; - } - // Evaluate the ndarray function: - if ( data ) { - f( arrays, data[ idx ] ); - } else { - f( arrays ); - } - if ( nout === 1 ) { - return arrays[ narrays-1 ]; - } - if ( nout === 0 ) { - return; - } - return arrays.slice( nin ); - } -} - - -// EXPORTS // - -module.exports = dispatch; diff --git a/package.json b/package.json index 9569eb2..aab393c 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Create an ndarray function interface which performs multiple dispatch.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@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-ndarray-like": "^0.0.x", - "@stdlib/assert-is-nonnegative-integer": "^0.0.x", - "@stdlib/assert-is-positive-integer": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/array-int32": "^0.0.x", - "@stdlib/array-int8": "^0.0.x", - "@stdlib/array-uint8": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/math-base-assert-is-nan": "^0.0.x", - "@stdlib/math-base-special-abs": "^0.0.x", - "@stdlib/math-base-special-pow": "^0.0.x", - "@stdlib/math-base-special-sin": "^0.0.x", - "@stdlib/ndarray-base-buffer-dtype": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/ndarray-base-unary": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/ndarray-dtypes": "^0.0.x", - "@stdlib/ndarray-ind2sub": "^0.0.x", - "@stdlib/strided-dtypes": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "ndarray", @@ -97,7 +26,6 @@ "multimethod", "multimethods" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..ba024b7 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/fixtures/binary.js b/test/fixtures/binary.js deleted file mode 100644 index a60dfa2..0000000 --- a/test/fixtures/binary.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Binary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @returns {number} sum -*/ -function binary( x, y ) { - return x + y; -} - - -// EXPORTS // - -module.exports = binary; diff --git a/test/fixtures/fill.js b/test/fixtures/fill.js deleted file mode 100644 index 41b2958..0000000 --- a/test/fixtures/fill.js +++ /dev/null @@ -1,76 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which fills one or more ndarrays. -* -* @private -* @param {*} value - fill value -* @returns {Function} ndarray function -*/ -function fill( value ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - */ - function ndarrayFcn( arrays ) { - var opts; - var sub; - var arr; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - opts = { - 'order': '' - }; - for ( j = 0; j < M; j++ ) { - arr = arrays[ j ]; - opts.order = arrays[ j ].order; - for ( i = 0; i < N; i++ ) { - sub = ind2sub( sh, i, opts ); - sub.push( value ); - arr.set.apply( arr, sub ); - } - } - } -} - - -// EXPORTS // - -module.exports = fill; diff --git a/test/fixtures/foreach.js b/test/fixtures/foreach.js deleted file mode 100644 index a426290..0000000 --- a/test/fixtures/foreach.js +++ /dev/null @@ -1,72 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function forEach( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - fcn.apply( null, args ); - } -} - - -// EXPORTS // - -module.exports = forEach; diff --git a/test/fixtures/map1n.js b/test/fixtures/map1n.js deleted file mode 100644 index 614196b..0000000 --- a/test/fixtures/map1n.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function which maps the return value of a callback to `N` arrays. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function map1N( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var v; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - v = fcn(); - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - sub.push( v ); - arrays[ j ].set.apply( arrays[ j ], sub ); - } - } -} - - -// EXPORTS // - -module.exports = map1N; diff --git a/test/fixtures/nullary.js b/test/fixtures/nullary.js deleted file mode 100644 index 4f22126..0000000 --- a/test/fixtures/nullary.js +++ /dev/null @@ -1,36 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Nullary callback. -* -* @private -* @returns {number} value -*/ -function nullary() { - return 3.0; -} - - -// EXPORTS // - -module.exports = nullary; diff --git a/test/fixtures/quaternary.js b/test/fixtures/quaternary.js deleted file mode 100644 index 548437b..0000000 --- a/test/fixtures/quaternary.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quaternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @returns {number} sum -*/ -function quaternary( x, y, z, w ) { - return x + y + z + w; -} - - -// EXPORTS // - -module.exports = quaternary; diff --git a/test/fixtures/quinary.js b/test/fixtures/quinary.js deleted file mode 100644 index 36068de..0000000 --- a/test/fixtures/quinary.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quinary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @param {number} u - input value -* @returns {number} sum -*/ -function quinary( x, y, z, w, u ) { - return x + y + z + w + u; -} - - -// EXPORTS // - -module.exports = quinary; diff --git a/test/fixtures/sum.js b/test/fixtures/sum.js deleted file mode 100644 index efdbb1b..0000000 --- a/test/fixtures/sum.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which computes the sum across one or more ndarrays. -* -* @private -* @param {Object} ctx - context -* @param {number} ctx.sum - initial sum -* @returns {Function} ndarray function -*/ -function wrapper( ctx ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - * @param {Function} [fcn] - callback - */ - function ndarrayFcn( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var f; - var i; - var j; - - if ( arguments.length > 1 ) { - f = fcn; - } - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - if ( f ) { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - ctx.sum += f.apply( null, args ); - } - } else { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - ctx.sum += arrays[ j ].get.apply( arrays[ j ], sub ); - } - } - } - } -} - - -// EXPORTS // - -module.exports = wrapper; diff --git a/test/fixtures/ternary.js b/test/fixtures/ternary.js deleted file mode 100644 index 0595d5f..0000000 --- a/test/fixtures/ternary.js +++ /dev/null @@ -1,39 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Ternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @returns {number} sum -*/ -function ternary( x, y, z ) { - return x + y + z; -} - - -// EXPORTS // - -module.exports = ternary; diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d6c2c8e..0000000 --- a/test/test.js +++ /dev/null @@ -1,363 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var fill = require( './fixtures/fill.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either a function or an array of functions as a first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( value, types, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object as a second argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided either an array-like object or `null` as a third argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - dispatch( unary, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a positive integer for a fourth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 0, - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a fifth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, value, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a sixth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, 1, value ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function array)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var fcns = [ unary, unary, unary ]; - var data = [ abs, abs, abs ]; - dispatch( fcns, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function argument)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs, abs, abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the length of `data` argument does not match the number of ndarray functions', function test( t ) { - var values; - var i; - - values = [ - [], - [ abs, abs ], - [ abs, abs, abs ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var fcns = [ unary ]; - dispatch( fcns, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the fourth argument is incompatible with the number of input and output ndarrays', function test( t ) { - var values; - var i; - - values = [ - 0, - 1, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of specified input and output ndarrays is zero', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var types = [ 'float64' ]; - dispatch( fill( 3 ), types, null, 1, 0, 0 ); - } -}); - -tape( 'the function returns an ndarray function interface', function test( t ) { - var types; - var data; - var f; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - f = dispatch( unary, types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ unary ], types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( fill( 3 ), types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ fill( 3 ) ], types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.two_arrays.js b/test/test.two_arrays.js deleted file mode 100644 index 071500e..0000000 --- a/test/test.two_arrays.js +++ /dev/null @@ -1,808 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var dtype = require( '@stdlib/ndarray-base-buffer-dtype' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var forEach = require( './fixtures/foreach.js' ); -var map1N = require( './fixtures/map1n.js' ); -var fill = require( './fixtures/fill.js' ); -var sum = require( './fixtures/sum.js' ); - - -// TESTS // - -tape( 'the function returns a function which throws an error if not provided an ndarray for the first argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var ybuf = new Float64Array( 10 ); - var y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( value, y ); - }; - } -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the second argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var xbuf = new Float64Array( 10 ); - var x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( x, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided insufficient arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var f; - var x; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [], - [ x ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided too many arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var ybuf; - var f; - var x; - var y; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [ x, y, y ], - [ x, y, y, y ], - [ x, y, y, y, y ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if unable to resolve a ndarray function supporting the provided array argument data types', function test( t ) { - var values; - var types; - var data; - var xbuf; - var fcn; - var x; - var i; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ abs, abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 4 ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - values = [ - new Uint8Array( 4 ), - new Int32Array( 4 ), - [ 0, 0, 0, 0 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided an array having data type: ' + dtype( values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var y = ndarray( dtype( value ), value, [ value.length ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - }; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only input arrays)', function test( t ) { - var types; - var xbuf; - var ybuf; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only output arrays)', function test( t ) { - var expected; - var types; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only input arrays)', function test( t ) { - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var ctx; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcns = [ - sum( ctx ), - sum( ctx ) - ]; - fcn = dispatch( fcns, types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only output arrays)', function test( t ) { - var expected; - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcns = [ - fill( 3.0 ), - fill( 4.0 ) - ]; - fcn = dispatch( fcns, types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - - fcn = dispatch( forEach, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - - fcn = dispatch( map1N, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - fcns = [ - forEach, - forEach - ]; - fcn = dispatch( fcns, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - fcns = [ - map1N, - map1N - ]; - fcn = dispatch( fcns, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - fcns = [ - unary, - unary - ]; - fcn = dispatch( fcns, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which returns one or more output arrays, if one or more output arrays is specified, and otherwise returns `undefined`', function test( t ) { - var types; - var data; - var xbuf; - var ybuf; - var out; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - // No output arrays... - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, void 0, 'returns expected value' ); - - // One output array... - data = [ - abs, - abs - ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - fcn = dispatch( fill( 3.0 ), types, null, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - // Two output arrays... - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.end(); -}); From 1efac0a0ee60e6a006405a21922a3e9920daebe3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 04:11:41 +0000 Subject: [PATCH 017/109] Transform error messages --- lib/main.js | 28 ++++++++++++++-------------- package.json | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/main.js b/lib/main.js index 3d28781..c8218ef 100644 --- a/lib/main.js +++ b/lib/main.js @@ -27,7 +27,7 @@ var isFunctionArray = require( '@stdlib/assert-is-function-array' ); var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var indexOfTypes = require( './index_of_types.js' ); @@ -89,43 +89,43 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { if ( isFunction( fcns ) ) { fcn = fcns; } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) ); + throw new TypeError( format( '0Mq5s', fcns ) ); } if ( !isCollection( types ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) ); + throw new TypeError( format( '0Mq3A', types ) ); } if ( !isCollection( data ) && data !== null ) { throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); } if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) ); + throw new TypeError( format( '0Mq5u', nargs ) ); } if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) ); + throw new TypeError( format( '0Mq5v', nin ) ); } if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) ); + throw new TypeError( format( '0Mq5w', nout ) ); } narrays = nin + nout; if ( narrays === 0 ) { - throw new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' ); + throw new Error( format( '0Mq0h' ) ); } if ( nargs !== narrays ) { - throw new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' ); + throw new Error( format( '0Mq0i' ) ); } if ( fcn ) { nfcns = types.length / narrays; if ( !isInteger( nfcns ) ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format( '0Mq0j' ) ); } } else { nfcns = fcns.length; if ( types.length !== nfcns*narrays ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format( '0Mq0j' ) ); } } if ( data && data.length !== nfcns ) { - throw new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' ); + throw new Error( format( '0Mq0k' ) ); } return dispatcher; @@ -154,9 +154,9 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { argc = arguments.length; if ( argc !== nargs ) { if ( argc < nargs ) { - throw new Error( 'invalid invocation. Insufficient arguments.' ); + throw new Error( format( '0Mq0l' ) ); } - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format( '0Mq0m' ) ); } arrays = []; dtypes = []; @@ -177,7 +177,7 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { // Check whether we were able to successfully resolve an ndarray function: if ( idx < 0 ) { - throw new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' ); + throw new TypeError( format( '0Mq0p' ) ); } // Retrieve the ndarray function: if ( fcn ) { diff --git a/package.json b/package.json index 014d480..9569eb2 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-ndarray-like": "^0.0.x", "@stdlib/assert-is-nonnegative-integer": "^0.0.x", "@stdlib/assert-is-positive-integer": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From c6b201dae0d1356f7bea216a13c18c9aeefb38a8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 21:03:26 +0000 Subject: [PATCH 018/109] Remove files --- index.d.ts | 334 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 3028 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index e8f79c8..0000000 --- a/index.d.ts +++ /dev/null @@ -1,334 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* ndarray function. -* -* @param arrays - array containing input and output ndarrays -* @param data - ndarray function data (e.g., a callback) -* -* @example -* var numel = require( `@stdlib/ndarray/base/numel` ); -* var ind2sub = require( `@stdlib/ndarray/ind2sub` ); -* -* function ndarrayFcn( arrays, fcn ) { -* var xord; -* var yord; -* var opts; -* var sub; -* var sh; -* var N; -* var x; -* var y; -* var v; -* var i; -* -* x = arrays[ 0 ]; -* y = arrays[ 1 ]; -* sh = x.shape; -* N = numel( sh ); -* if ( N <= 0 ) { -* return; -* } -* xord = x.order; -* yord = y.order; -* opts = {}; -* opts.order = xord; -* for ( i = 0; i < N; i++ ) { -* // Convert a linear index to subscripts: -* opts.order = xord; -* sub = ind2sub( sh, i, opts ); -* -* // Retrieve an element from `x`: -* v = x.get.apply( x, sub ); -* -* // Convert a linear index to subscripts: -* opts.order = yord; -* sub = ind2sub( sh, i, opts ); -* -* // Append the result of applying the callback: -* sub.push( fcn( v ) ); -* -* // Assign the result to an element in `y`: -* y.set.apply( y, sub ); -* } -* } -*/ -type ndarrayFcn = ( arrays: Array, data?: any ) => void; - -/** -* Interface describing an ndarray function dispatcher. -*/ -interface Dispatcher { - /** - * Invokes an ndarray function based on the provided array data type(s). - * - * @param x - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array - * - * @example - * var nullary = require( `@stdlib/ndarray/base/nullary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function value() { - * return 3.14; - * } - * - * var types = [ 'float64' ]; - * var data = [ value ]; - * - * var fcn = dispatch( nullary, types, data, 1, 0, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( 5 ); - * var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x ); - * // xbuf => [ 3.14, 3.14, 3.14, 3.14, 3.14 ] - */ - ( x: ndarray ): ndarray | void; - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var unary = require( `@stdlib/ndarray/base/unary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * var abs = require( `@stdlib/math/base/special/abs` ); - * - * var types = [ 'float64', 'float64' ]; - * var data = [ abs ]; - * - * var fcn = dispatch( unary, types, data, 2, 1, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - * var ybuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y ); - * // ybuf => [ 1.0, 2.0, 3.0 ] - */ - ( x: ndarray, y: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var ternary = require( `@stdlib/ndarray/base/ternary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add2( x, y ) { - * return x + y; - * } - * - * var types = [ 'float64', 'float64', 'float64' ]; - * var data = [ add2 ]; - * - * var fcn = dispatch( ternary, types, data, 3, 2, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z ); - * // zbuf => [ 2.0, 4.0, 6.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quaternary = require( `@stdlib/ndarray/base/quaternary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add3( x, y, z ) { - * return x + y + z; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add3 ]; - * - * var fcn = dispatch( quaternary, types, data, 4, 3, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w ); - * // wbuf => [ 3.0, 6.0, 9.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @param args - ndarray arguments - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quinary = require( `@stdlib/ndarray/base/quinary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add4( x, y, z, w ) { - * return x + y + z + w; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add4 ]; - * - * var fcn = dispatch( quinary, types, data, 5, 4, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ubuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var u = ndarray( 'float64', ubuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w, u ); - * // ubuf => [ 4.0, 8.0, 12.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray, ...args: Array ): ndarray | void; // tslint:disable-line:max-line-length unified-signatures -} - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param fcns - list of ndarray functions -* @param types - one-dimensional list of ndarray argument data types -* @param data - ndarray function data (e.g., callbacks) -* @param nargs - total number of ndarray function interface arguments -* @param nin - number of input ndarrays -* @param nout - number of output ndarrays -* @throws first argument must be either a function or an array of functions -* @throws second argument must be an array-like object -* @throws third argument must be an array-like object or `null` -* @throws third and first arguments must have the same number of elements -* @throws fourth argument must be a positive integer -* @throws fifth argument must be a nonnegative integer -* @throws sixth argument must be a nonnegative integer -* @throws fourth argument must equal the specified number of input and output arrays -* @throws number of types must match the number of functions times the total number of array arguments for each function -* @throws interface must accept at least one input and/or output ndarray -* @returns ndarray function interface -* -* @example -* var unary = require( `@stdlib/ndarray/base/unary` ); -* var abs = require( `@stdlib/math/base/special/abs` ); -* var Float64Array = require( `@stdlib/array/float64` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var fcn = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* fcn( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function dispatch( fcns: ndarrayFcn | ArrayLike, types: ArrayLike, data: ArrayLike | null, nargs: number, nin: number, nout: number ): Dispatcher; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = dispatch; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index f48c2d5..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function m(r,e,t,i,s,n,o,l,m){var d,a,h,f;for(d=n,h=0;h [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0Mq5s', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0Mq3A', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0Mq5u', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0Mq5v', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0Mq5w', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format( '0Mq0h' ) );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format( '0Mq0i' ) );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format( '0Mq0k' ) );\n\t}\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format( '0Mq0l' ) );\n\t\t\t}\n\t\t\tthrow new Error( format( '0Mq0m' ) );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( v.dtype );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format( '0Mq0p' ) );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n"],"names":["indexOfTypes","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","i","j","dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","push","dtype","slice"],"mappings":";;uvBA6EA,SAASA,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,KAAgBE,EAAGI,GADdE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,EAEP,OAAQ,EChBT,SAASU,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,sFAAuFV,IAErH,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAQ,UAE1B,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAQ,UAE1B,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAQ,eAI1B,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAQ,UAG3B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAQ,UAE1B,OAeA,WACC,IAAIO,EACAC,EACAC,EACAC,EACAC,EACAC,EACA3B,EAGJ,IADAwB,EAAOI,UAAUR,UACHd,EAAQ,CACrB,GAAKkB,EAAOlB,EACX,MAAM,IAAIa,MAAOJ,EAAQ,UAE1B,MAAM,IAAII,MAAOJ,EAAQ,UAI1B,IAFAO,EAAS,GACTC,EAAS,GACHvB,EAAI,EAAGA,EAAIM,EAAON,IAAM,CAE7B,IAAM6B,EADNH,EAAIE,UAAW5B,IAEd,MAAKA,EAAIO,EACF,IAAIO,UAAWC,EAAQ,6EAA8EW,IAErG,IAAIZ,UAAWC,EAAQ,8EAA+EW,IAG9GJ,EAAOQ,KAAMJ,GACbH,EAAOO,KAAMJ,EAAEK,OAMhB,IAHAN,EAAMrC,EAAcsB,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGc,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAIT,UAAWC,EAAQ,UAI7BY,EADIhB,GAGAR,EAAMsB,GAGNpB,EACJsB,EAAGL,EAAQjB,EAAMoB,IAEjBE,EAAGL,GAEJ,GAAc,IAATd,EACJ,OAAOc,EAAQb,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOc,EAAOU,MAAOzB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index ba024b7..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From aaedc251d41ba39ff107bec882bdfde1f1b42cf5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 21:04:29 +0000 Subject: [PATCH 019/109] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 760 ------ .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 59 +- benchmark/benchmark.dispatch_size.js | 156 -- benchmark/benchmark.js | 81 - branches.md | 53 - docs/repl.txt | 87 - docs/types/test.ts | 641 ----- examples/add.js | 121 - examples/sin.js | 142 -- examples/unary.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/index_of_types.js | 106 - lib/main.js | 207 -- package.json | 76 +- stats.html | 2689 +++++++++++++++++++++ test/fixtures/binary.js | 38 - test/fixtures/fill.js | 76 - test/fixtures/foreach.js | 72 - test/fixtures/map1n.js | 74 - test/fixtures/nullary.js | 36 - test/fixtures/quaternary.js | 40 - test/fixtures/quinary.js | 41 - test/fixtures/sum.js | 98 - test/fixtures/ternary.js | 39 - test/test.js | 363 --- test/test.two_arrays.js | 808 ------- 51 files changed, 2723 insertions(+), 6396 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.dispatch_size.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/add.js delete mode 100644 examples/sin.js delete mode 100644 examples/unary.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/index_of_types.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/fixtures/binary.js delete mode 100644 test/fixtures/fill.js delete mode 100644 test/fixtures/foreach.js delete mode 100644 test/fixtures/map1n.js delete mode 100644 test/fixtures/nullary.js delete mode 100644 test/fixtures/quaternary.js delete mode 100644 test/fixtures/quinary.js delete mode 100644 test/fixtures/sum.js delete mode 100644 test/fixtures/ternary.js delete mode 100644 test/test.js delete mode 100644 test/test.two_arrays.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 6ae20f4..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-10-01T02:01:19.352Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ac0b7cd..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a7a7f51..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.9.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 920b304..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 39b1613..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 7ca169c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 8 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "::set-output name=package_name::$name" - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "::set-output name=data::$data" - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v2 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v2 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 5094681..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,760 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -291,7 +284,7 @@ console.log( ybuf ); ## 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. +This package is part of [stdlib][stdlib], a standard library 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]. @@ -353,11 +346,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm diff --git a/benchmark/benchmark.dispatch_size.js b/benchmark/benchmark.dispatch_size.js deleted file mode 100644 index 3bd0418..0000000 --- a/benchmark/benchmark.dispatch_size.js +++ /dev/null @@ -1,156 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib/main.js' ); - - -// FUNCTIONS // - -/** -* Evaluates the identity function. -* -* @private -* @param {*} v - value -* @returns {*} input value -*/ -function identity( v ) { - return v; -} - -/** -* Dummy function which throws an error. -* -* @private -* @throws {Error} unexpected error -*/ -function throwError() { - throw new Error( 'unexpected error' ); -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} size - dispatch size -* @returns {Function} benchmark function -*/ -function createBenchmark( size ) { - var types; - var data; - var fcn; - var x; - var y; - var t; - var i; - - types = []; - - // Create dummy types... - for ( i = 0; i < (size-1)*2; i += 2 ) { - t = 'foo' + i; - types.push( t ); - types.push( t ); - } - // Append test types: - types.push( 'float64' ); - types.push( 'float64' ); - - // Define a list of callbacks: - data = []; - for ( i = 0; i < size-1; i++ ) { - data.push( throwError ); - } - // Append a test callback: - data.push( identity ); - - // Create the dispatcher: - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - // Create sample arrays: - x = new Float64Array( 1 ); - y = new Float64Array( x.length ); - - x = ndarray( 'float64', x, [ 1 ], [ 1 ], 0, 'row-major' ); - y = ndarray( 'float64', y, [ 1 ], [ 1 ], 0, 'row-major' ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var z; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x.data[ 0 ] = i; - z = fcn( x, y ); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var size; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - size = pow( 2, i ); - f = createBenchmark( size ); - bench( pkg+':size='+size, f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index a70dc5c..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::fcns_array', function benchmark( b ) { - var types; - var fcns; - var data; - var out; - var i; - - fcns = [ unary ]; - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( fcns, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::fcn_arg', function benchmark( b ) { - var types; - var data; - var out; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( unary, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index d04d051..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch" -click B href "https://github.com/stdlib-js/ndarray-dispatch/tree/main" -click C href "https://github.com/stdlib-js/ndarray-dispatch/tree/production" -click D href "https://github.com/stdlib-js/ndarray-dispatch/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-dispatch/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-dispatch/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch -[production-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 02fe150..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,87 +0,0 @@ - -{{alias}}( fcns, types, data, nargs, nin, nout ) - Returns an ndarray function interface which performs multiple dispatch. - - An ndarray function interface has the following signature: - - f( x, y, ... ) - - where - - - x: ndarray. - - y: ndarray. - - ...: additional ndarrays. - - The number of parameters is derived from `nargs`, the number of input - ndarrays is derived from `nin`, and the number of output ndarrays is derived - from `nout`. - - Parameters - ---------- - fcns: Function|ArrayLikeObject - List of ndarray functions. An ndarray function should have the following - signature: - - f( arrays, data ) - - where - - - arrays: array containing input and output ndarrays. - - data: ndarray function data (e.g., a callback). - - For convenience, a single ndarray function may be provided which will be - invoked whenever the ndarray argument data types match a sequence of - types in `types`. Providing a single ndarray function is particularly - convenient for the case where, regardless of array data types, - traversing arrays remains the same, but the ndarray function `data` - differs (e.g., callbacks which differ based on the array data types). - - types: ArrayLikeObject - One-dimensional list of ndarray argument data types. - - data: ArrayLikeObject|null - ndarray function data (e.g., callbacks). If `null`, a returned ndarray - function interface does **not** provide a `data` argument to an invoked - ndarray function. - - nargs: integer - Total number of ndarray function interface arguments. - - nin: integer - Number of input ndarrays. - - nout: integer - Number of output ndarrays. - - Returns - ------- - fcn: Function - ndarray function interface. - - Examples - -------- - // Define ndarray argument data types: - > var t = [ 'float64', 'float64', 'float32', 'float32' ]; - - // Define a list of ndarray function data (callbacks): - > var d = [ {{alias:@stdlib/math/base/special/abs}}, {{alias:@stdlib/math/base/special/absf}} ]; - - // Create an ndarray function interface for applying unary callbacks: - > var f = {{alias}}( {{alias:@stdlib/ndarray/base/unary}}, t, d, 2, 1, 1 ); - - // Create an input ndarray: - > var xbuf = new {{alias:@stdlib/array/float64}}( [ -1.0, -2.0, -3.0, -4.0 ] ); - > var x = {{alias:@stdlib/ndarray/ctor}}( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Create an output ndarray: - > var ybuf = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 0.0, 0.0 ] ); - > var y = {{alias:@stdlib/ndarray/ctor}}( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Compute the element-wise absolute value: - > f( x, y ); - > ybuf - [ 1.0, 2.0, 3.0, 4.0 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 397185e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,641 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// tslint:disable:max-file-line-count - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import dispatch = require( './index' ); - - -// FUNCTIONS // - -/** -* Nullary callback. -* -* @return input value -*/ -function nullary(): any { - return 5.0; -} - -/** -* Unary callback. -* -* @param x - input value -* @return input value -*/ -function unary( x: any ): any { - return x; -} - -/** -* Binary callback. -* -* @param x - input value -* @param y - input value -* @return output value -*/ -function binary( x: number, y: number ): number { - return x + y; -} - -/** -* Ternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @return output value -*/ -function ternary( x: number, y: number, z: number ): number { - return x + y + z; -} - -/** -* Quaternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @param w - input value -* @return output value -*/ -function quaternary( x: number, y: number, z: number, w: number ): number { - return x + y + z + w; -} - -/** -* Mock `ind2sub` function. -* -* @param shape - dimensions -* @param idx - linear index -* @param opts - options -* @return subscripts -*/ -function ind2sub( shape: ArrayLike, idx: number, opts?: any ): Array { // tslint:disable-line:max-line-length - let out; - let i; - - out = []; - if ( typeof opts === 'object' && opts !== null && opts.order === 'row-major' ) { // tslint:disable-line:max-line-length no-unsafe-any - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } else { - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } - return out; -} - -/** -* Mock ndarray function. -* -* @param arrays - ndarrays -* @param fcn - callback -*/ -function ndarrayFcn( arrays: Array, fcn: ( x: any ) => any ): void { - let xord; - let yord; - let opts; - let sub; - let sh; - let N; - let x; - let y; - let v; - let i; - - x = arrays[ 0 ]; - y = arrays[ 1 ]; - sh = x.shape; - if ( sh.length === 0 ) { - return; - } - N = 1; - for ( i = 0; i < sh.length; i += 1 ) { - N *= sh[ i ]; - } - xord = x.order; - yord = y.order; - opts = { - 'order': '' - }; - opts.order = xord; - for ( i = 0; i < N; i += 1 ) { - // Convert a linear index to subscripts: - opts.order = xord; - sub = ind2sub( sh, i, opts ); - - // Retrieve an element from `x`: - v = x.get.apply( x, sub ); - - // Convert a linear index to subscripts: - opts.order = yord; - sub = ind2sub( sh, i, opts ); - - // Append the result of applying the callback: - sub[ sub.length ] = fcn( v ) as number; - - // Assign the result to an element in `y`: - y.set.apply( y, sub ); - } -} - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a dispatch function... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, 1 ); // $ExpectType Dispatcher - dispatch( [ ndarrayFcn ], types, data, 2, 1, 1 ); // $ExpectType Dispatcher -} - -// The compiler throws an error if the function is provided a first argument which is not either an ndarray function or an array-like object containing ndarray functions... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( '10', types, data, 2, 1, 1 ); // $ExpectError - dispatch( 10, types, data, 2, 1, 1 ); // $ExpectError - dispatch( true, types, data, 2, 1, 1 ); // $ExpectError - dispatch( false, types, data, 2, 1, 1 ); // $ExpectError - dispatch( null, types, data, 2, 1, 1 ); // $ExpectError - dispatch( undefined, types, data, 2, 1, 1 ); // $ExpectError - dispatch( [ '1' ], types, data, 2, 1, 1 ); // $ExpectError - dispatch( {}, types, data, 2, 1, 1 ); // $ExpectError - dispatch( ( x: number ): number => x, types, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object... -{ - const data = [ unary ]; - - dispatch( ndarrayFcn, 10, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, true, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, false, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, null, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, undefined, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, {}, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object or null... -{ - const types = [ 'float64', 'float64' ]; - - dispatch( ndarrayFcn, types, 10, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, true, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, false, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, undefined, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, {}, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, '10', 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, true, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, false, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, null, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, undefined, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, [ '1' ], 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, {}, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, ( x: number ): number => x, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, '10', 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, true, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, false, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, null, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, undefined, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, [ '1' ], 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, {}, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, ( x: number ): number => x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, '10' ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, true ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, false ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, null ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, undefined ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, [ '1' ] ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, {} ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch(); // $ExpectError - dispatch( ndarrayFcn ); // $ExpectError - dispatch( ndarrayFcn, types ); // $ExpectError - dispatch( ndarrayFcn, types, data ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, 1, 0 ); // $ExpectError -} - -// The function returns a dispatch function... -{ - const x = array(); - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const t1 = [ 'float64' ]; - const d1 = [ nullary ]; - const f1 = dispatch( ndarrayFcn, t1, d1, 1, 1, 0 ); - f1( x ); // $ExpectType void | ndarray - - const t2 = [ 'float64', 'float64' ]; - const d2 = [ unary ]; - const f2 = dispatch( ndarrayFcn, t2, d2, 2, 1, 1 ); - f2( x, y ); // $ExpectType void | ndarray - - const t3 = [ 'float64', 'float64', 'float64' ]; - const d3 = [ binary ]; - const f3 = dispatch( ndarrayFcn, t3, d3, 3, 2, 1 ); - f3( x, y, z ); // $ExpectType void | ndarray - - const t4 = [ 'float64', 'float64', 'float64', 'float64' ]; - const d4 = [ ternary ]; - const f4 = dispatch( ndarrayFcn, t4, d4, 4, 3, 1 ); - f4( x, y, z, w ); // $ExpectType void | ndarray - - const t5 = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const d5 = [ quaternary ]; - const f5 = dispatch( ndarrayFcn, t5, d5, 5, 4, 1 ); - f5( x, y, z, w, u ); // $ExpectType void | ndarray -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (1 ndarray)... -{ - const types = [ 'float64' ]; - const data = [ nullary ]; - - const f = dispatch( ndarrayFcn, types, data, 1, 0, 1 ); - f( '10' ); // $ExpectError - f( 10 ); // $ExpectError - f( true ); // $ExpectError - f( false ); // $ExpectError - f( null ); // $ExpectError - f( undefined ); // $ExpectError - f( [ '1' ] ); // $ExpectError - f( {} ); // $ExpectError - f( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( 10, y ); // $ExpectError - f( '10', y ); // $ExpectError - f( true, y ); // $ExpectError - f( false, y ); // $ExpectError - f( null, y ); // $ExpectError - f( undefined, y ); // $ExpectError - f( [ '1' ], y ); // $ExpectError - f( {}, y ); // $ExpectError - f( ( x: number ): number => x, y ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const x = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( x, 10 ); // $ExpectError - f( x, '10' ); // $ExpectError - f( x, true ); // $ExpectError - f( x, false ); // $ExpectError - f( x, null ); // $ExpectError - f( x, undefined ); // $ExpectError - f( x, [ '1' ] ); // $ExpectError - f( x, {} ); // $ExpectError - f( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( 10, y, z ); // $ExpectError - f( '10', y, z ); // $ExpectError - f( true, y, z ); // $ExpectError - f( false, y, z ); // $ExpectError - f( null, y, z ); // $ExpectError - f( undefined, y, z ); // $ExpectError - f( [ '1' ], y, z ); // $ExpectError - f( {}, y, z ); // $ExpectError - f( ( x: number ): number => x, y, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, 10, z ); // $ExpectError - f( x, '10', z ); // $ExpectError - f( x, true, z ); // $ExpectError - f( x, false, z ); // $ExpectError - f( x, null, z ); // $ExpectError - f( x, undefined, z ); // $ExpectError - f( x, [ '1' ], z ); // $ExpectError - f( x, {}, z ); // $ExpectError - f( x, ( x: number ): number => x, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, y, '10' ); // $ExpectError - f( x, y, true ); // $ExpectError - f( x, y, false ); // $ExpectError - f( x, y, null ); // $ExpectError - f( x, y, undefined ); // $ExpectError - f( x, y, [ '1' ] ); // $ExpectError - f( x, y, {} ); // $ExpectError - f( x, y, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( 10, y, z, w ); // $ExpectError - f( '10', y, z, w ); // $ExpectError - f( true, y, z, w ); // $ExpectError - f( false, y, z, w ); // $ExpectError - f( null, y, z, w ); // $ExpectError - f( undefined, y, z, w ); // $ExpectError - f( [ '1' ], y, z, w ); // $ExpectError - f( {}, y, z, w ); // $ExpectError - f( ( x: number ): number => x, y, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, 10, z, w ); // $ExpectError - f( x, '10', z, w ); // $ExpectError - f( x, true, z, w ); // $ExpectError - f( x, false, z, w ); // $ExpectError - f( x, null, z, w ); // $ExpectError - f( x, undefined, z, w ); // $ExpectError - f( x, [ '1' ], z, w ); // $ExpectError - f( x, {}, z, w ); // $ExpectError - f( x, ( x: number ): number => x, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, 10, w ); // $ExpectError - f( x, y, '10', w ); // $ExpectError - f( x, y, true, w ); // $ExpectError - f( x, y, false, w ); // $ExpectError - f( x, y, null, w ); // $ExpectError - f( x, y, undefined, w ); // $ExpectError - f( x, y, [ '1' ], w ); // $ExpectError - f( x, y, {}, w ); // $ExpectError - f( x, y, ( x: number ): number => x, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, z, 10 ); // $ExpectError - f( x, y, z, '10' ); // $ExpectError - f( x, y, z, true ); // $ExpectError - f( x, y, z, false ); // $ExpectError - f( x, y, z, null ); // $ExpectError - f( x, y, z, undefined ); // $ExpectError - f( x, y, z, [ '1' ] ); // $ExpectError - f( x, y, z, {} ); // $ExpectError - f( x, y, z, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( 10, y, z, w, u ); // $ExpectError - f( '10', y, z, w, u ); // $ExpectError - f( true, y, z, w, u ); // $ExpectError - f( false, y, z, w, u ); // $ExpectError - f( null, y, z, w, u ); // $ExpectError - f( undefined, y, z, w, u ); // $ExpectError - f( [ '1' ], y, z, w, u ); // $ExpectError - f( {}, y, z, w, u ); // $ExpectError - f( ( x: number ): number => x, y, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, 10, z, w, u ); // $ExpectError - f( x, '10', z, w, u ); // $ExpectError - f( x, true, z, w, u ); // $ExpectError - f( x, false, z, w, u ); // $ExpectError - f( x, null, z, w, u ); // $ExpectError - f( x, undefined, z, w, u ); // $ExpectError - f( x, [ '1' ], z, w, u ); // $ExpectError - f( x, {}, z, w, u ); // $ExpectError - f( x, ( x: number ): number => x, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, 10, w, u ); // $ExpectError - f( x, y, '10', w, u ); // $ExpectError - f( x, y, true, w, u ); // $ExpectError - f( x, y, false, w, u ); // $ExpectError - f( x, y, null, w, u ); // $ExpectError - f( x, y, undefined, w, u ); // $ExpectError - f( x, y, [ '1' ], w, u ); // $ExpectError - f( x, y, {}, w, u ); // $ExpectError - f( x, y, ( x: number ): number => x, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, 10, u ); // $ExpectError - f( x, y, z, '10', u ); // $ExpectError - f( x, y, z, true, u ); // $ExpectError - f( x, y, z, false, u ); // $ExpectError - f( x, y, z, null, u ); // $ExpectError - f( x, y, z, undefined, u ); // $ExpectError - f( x, y, z, [ '1' ], u ); // $ExpectError - f( x, y, z, {}, u ); // $ExpectError - f( x, y, z, ( x: number ): number => x, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fifth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, w, 10 ); // $ExpectError - f( x, y, z, w, '10' ); // $ExpectError - f( x, y, z, w, true ); // $ExpectError - f( x, y, z, w, false ); // $ExpectError - f( x, y, z, w, null ); // $ExpectError - f( x, y, z, w, undefined ); // $ExpectError - f( x, y, z, w, [ '1' ] ); // $ExpectError - f( x, y, z, w, {} ); // $ExpectError - f( x, y, z, w, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/add.js b/examples/add.js deleted file mode 100644 index 775b711..0000000 --- a/examples/add.js +++ /dev/null @@ -1,121 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var dispatch = require( './../lib' ); - -function add2( arrays ) { - var opts; - var xo; - var yo; - var zo; - var sx; - var sy; - var sz; - var sh; - var N; - var x; - var y; - var z; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - z = arrays[ 2 ]; - xo = x.order; - yo = y.order; - zo = z.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - opts.order = yo; - sy = ind2sub( sh, i, opts ); - v = x.get.apply( x, sx ) + y.get.apply( y, sy ); - - opts.order = zo; - sz = ind2sub( sh, i, opts ); - sz.push( v ); - z.set.apply( z, sz ); - } -} - -var fcns = [ - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2 -]; - -var types = [ - dtypes.float64, dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.int32, dtypes.int32, - dtypes.uint32, dtypes.uint32, dtypes.uint32, - dtypes.int16, dtypes.int16, dtypes.int16, - dtypes.uint16, dtypes.uint16, dtypes.uint16, - dtypes.int8, dtypes.int8, dtypes.int8, - dtypes.uint8, dtypes.uint8, dtypes.uint8, - dtypes.uint8c, dtypes.uint8c, dtypes.uint8c -]; - -var add = dispatch( fcns, types, null, 3, 2, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var zbuf = new Float64Array( xbuf.length ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var z = ndarray( 'float64', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); - -xbuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -ybuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -zbuf = new Int32Array( xbuf.length ); - -x = ndarray( 'int32', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'int32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -z = ndarray( 'int32', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); diff --git a/examples/sin.js b/examples/sin.js deleted file mode 100644 index 8cd4871..0000000 --- a/examples/sin.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int8Array = require( '@stdlib/array-int8' ); -var sin = require( '@stdlib/math-base-special-sin' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/strided-dtypes' ); -var dispatch = require( './../lib' ); - -function apply( arrays, fcn ) { - var opts; - var xo; - var yo; - var sx; - var sy; - var sh; - var N; - var x; - var y; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - xo = x.order; - yo = y.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - v = fcn( x.get.apply( x, sx ) ); - - opts.order = yo; - sy = ind2sub( sh, i, opts ); - sy.push( v ); - y.set.apply( y, sy ); - } -} - -var fcns = [ - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply -]; - -var types = [ - dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float64, - dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.float64, - dtypes.uint32, dtypes.float64, - dtypes.int16, dtypes.float64, - dtypes.int16, dtypes.float32, - dtypes.uint16, dtypes.float64, - dtypes.uint16, dtypes.float32, - dtypes.int8, dtypes.float64, - dtypes.int8, dtypes.float32, - dtypes.uint8, dtypes.float64, - dtypes.uint8, dtypes.float32, - dtypes.uint8c, dtypes.float64, - dtypes.uint8c, dtypes.float32 -]; - -var data = [ - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin -]; - -var sine = dispatch( fcns, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); - -xbuf = new Int8Array( [ 1, 2, 3, 4, 5 ] ); -ybuf = new Float32Array( xbuf.length ); - -x = ndarray( 'int8', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'float32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); diff --git a/examples/unary.js b/examples/unary.js deleted file mode 100644 index e9c3fb4..0000000 --- a/examples/unary.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -var unary = require( '@stdlib/ndarray-base-unary' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var dispatch = require( './../lib' ); - -var types = [ 'float64', 'float64' ]; - -var data = [ - abs -]; - -var absolute = dispatch( unary, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -absolute( x, y ); -console.log( ybuf ); -// => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 610167d..e8f79c8 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..f48c2d5 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function m(r,e,t,i,s,n,o,l,m){var d,a,h,f;for(d=n,h=0;h [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0Mq5s', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0Mq3A', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0Mq5u', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0Mq5v', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0Mq5w', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format( '0Mq0h' ) );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format( '0Mq0i' ) );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format( '0Mq0k' ) );\n\t}\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format( '0Mq0l' ) );\n\t\t\t}\n\t\t\tthrow new Error( format( '0Mq0m' ) );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( v.dtype );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format( '0Mq0p' ) );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n"],"names":["indexOfTypes","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","i","j","dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","push","dtype","slice"],"mappings":";;uvBA6EA,SAASA,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,KAAgBE,EAAGI,GADdE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,EAEP,OAAQ,EChBT,SAASU,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,sFAAuFV,IAErH,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAQ,UAE1B,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAQ,UAE1B,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAQ,eAI1B,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAQ,UAG3B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAQ,UAE1B,OAeA,WACC,IAAIO,EACAC,EACAC,EACAC,EACAC,EACAC,EACA3B,EAGJ,IADAwB,EAAOI,UAAUR,UACHd,EAAQ,CACrB,GAAKkB,EAAOlB,EACX,MAAM,IAAIa,MAAOJ,EAAQ,UAE1B,MAAM,IAAII,MAAOJ,EAAQ,UAI1B,IAFAO,EAAS,GACTC,EAAS,GACHvB,EAAI,EAAGA,EAAIM,EAAON,IAAM,CAE7B,IAAM6B,EADNH,EAAIE,UAAW5B,IAEd,MAAKA,EAAIO,EACF,IAAIO,UAAWC,EAAQ,6EAA8EW,IAErG,IAAIZ,UAAWC,EAAQ,8EAA+EW,IAG9GJ,EAAOQ,KAAMJ,GACbH,EAAOO,KAAMJ,EAAEK,OAMhB,IAHAN,EAAMrC,EAAcsB,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGc,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAIT,UAAWC,EAAQ,UAI7BY,EADIhB,GAGAR,EAAMsB,GAGNpB,EACJsB,EAAGL,EAAQjB,EAAMoB,IAEjBE,EAAGL,GAEJ,GAAc,IAATd,EACJ,OAAOc,EAAQb,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOc,EAAOU,MAAOzB"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 291641d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Create an ndarray function interface which performs multiple dispatch. -* -* @module @stdlib/ndarray-dispatch -* -* @example -* var dispatch = require( '@stdlib/ndarray-dispatch' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/index_of_types.js b/lib/index_of_types.js deleted file mode 100644 index fda2297..0000000 --- a/lib/index_of_types.js +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found). -* -* ## Notes -* -* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types). -* - The function assumes that `x` is stored in row-major order. -* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`. -* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value. -* -* @private -* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension) -* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension) -* @param {ArrayLikeObject} x - input two-dimensional reference array -* @param {integer} strideX1 - `x` stride length along first dimension -* @param {integer} strideX2 - `x` stride length along second dimension -* @param {NonNegativeInteger} offsetX - `x` starting index -* @param {ArrayLikeObject} y - search array -* @param {integer} strideY - `y` stride length -* @param {NonNegativeInteger} offsetY - `y` starting index -* @returns {integer} row index (if found) and `-1` otherwise -* -* @example -* // Define a reference array to search: -* var types = [ -* 'float64', 'float64', 'float64', -* 'float32', 'float32', 'float32', -* 'uint32', 'uint32', 'float64', -* 'int32', 'int32', 'float64', -* 'uint16', 'uint16', 'float64', -* 'int16', 'int16', 'float64', -* 'uint8', 'uint8', 'float64', -* 'int8', 'int8', 'float64' -* ]; -* -* // Define reference array dimensions: -* var N = 8; // rows -* var M = 3; // columns -* -* // Define a search array: -* y1 = [ -* 'float32', 'float32', 'float32', -* ]; -* -* // Find the list of types: -* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 ); -* // returns 1 -* -// Define a search array: -* y2 = [ -* 'float32', 'float32', 'float64', -* ]; -* -* // Find the list of types: -* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 ); -* // returns -1 -*/ -function indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len - var ix; - var iy; - var i; - var j; - - // Search for the first row which matches `y`... - ix = offsetX; - for ( i = 0; i < N; i++ ) { - iy = offsetY; - for ( j = 0; j < M; j++ ) { - if ( x[ ix+(j*strideX2) ] !== y[ iy ] ) { - break; - } - iy += strideY; - } - // If we successfully iterated over all columns, then that means we've found a match... - if ( j === M ) { - return i; - } - ix += strideX1; - } - return -1; -} - - -// EXPORTS // - -module.exports = indexOfTypes; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c8218ef..0000000 --- a/lib/main.js +++ /dev/null @@ -1,207 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isFunctionArray = require( '@stdlib/assert-is-function-array' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var indexOfTypes = require( './index_of_types.js' ); - - -// MAIN // - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param {(FunctionArray|Function)} fcns - list of ndarray functions -* @param {Collection} types - one-dimensional list of ndarray argument data types -* @param {(Collection|null)} data - ndarray function data (e.g., callbacks) -* @param {PositiveInteger} nargs - total number of ndarray function interface arguments -* @param {NonNegativeInteger} nin - number of input ndarrays -* @param {NonNegativeInteger} nout - number of output ndarrays -* @throws {TypeError} first argument must be either a function or an array of functions -* @throws {TypeError} second argument must be an array-like object -* @throws {TypeError} third argument must be an array-like object or `null` -* @throws {Error} third and first arguments must have the same number of elements -* @throws {TypeError} fourth argument must be a positive integer -* @throws {TypeError} fifth argument must be a nonnegative integer -* @throws {TypeError} sixth argument must be a nonnegative integer -* @throws {Error} fourth argument must equal the specified number of input and output arrays -* @throws {Error} number of types must match the number of functions times the total number of array arguments for each function -* @throws {Error} interface must accept at least one input and/or output ndarray -* @returns {Function} ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function dispatch( fcns, types, data, nargs, nin, nout ) { - var narrays; - var nfcns; - var fcn; - - if ( isFunction( fcns ) ) { - fcn = fcns; - } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( '0Mq5s', fcns ) ); - } - if ( !isCollection( types ) ) { - throw new TypeError( format( '0Mq3A', types ) ); - } - if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); - } - if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( '0Mq5u', nargs ) ); - } - if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( '0Mq5v', nin ) ); - } - if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( '0Mq5w', nout ) ); - } - narrays = nin + nout; - if ( narrays === 0 ) { - throw new Error( format( '0Mq0h' ) ); - } - if ( nargs !== narrays ) { - throw new Error( format( '0Mq0i' ) ); - } - if ( fcn ) { - nfcns = types.length / narrays; - if ( !isInteger( nfcns ) ) { - throw new Error( format( '0Mq0j' ) ); - } - } else { - nfcns = fcns.length; - if ( types.length !== nfcns*narrays ) { - throw new Error( format( '0Mq0j' ) ); - } - } - if ( data && data.length !== nfcns ) { - throw new Error( format( '0Mq0k' ) ); - } - return dispatcher; - - /** - * ndarray function interface which performs multiple dispatch. - * - * @private - * @param {ndarrayLike} x - ndarray - * @param {...ndarrayLike} args - ndarray arguments - * @throws {Error} insufficient arguments - * @throws {Error} too many arguments - * @throws {TypeError} input array arguments must be ndarray-like objects - * @throws {TypeError} output array arguments must be ndarray-like objects - * @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types - * @returns {(ndarrayLike|Array|void)} destination array(s) - */ - function dispatcher() { - var arrays; - var dtypes; - var argc; - var idx; - var v; - var f; - var i; - - argc = arguments.length; - if ( argc !== nargs ) { - if ( argc < nargs ) { - throw new Error( format( '0Mq0l' ) ); - } - throw new Error( format( '0Mq0m' ) ); - } - arrays = []; - dtypes = []; - for ( i = 0; i < nargs; i++ ) { - v = arguments[ i ]; - if ( !isndarrayLike( v ) ) { - if ( i < nin ) { - throw new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) ); - } else { - throw new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) ); - } - } - arrays.push( v ); - dtypes.push( v.dtype ); - } - // Resolve the ndarray function satisfying the input array types: - idx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len - - // Check whether we were able to successfully resolve an ndarray function: - if ( idx < 0 ) { - throw new TypeError( format( '0Mq0p' ) ); - } - // Retrieve the ndarray function: - if ( fcn ) { - f = fcn; - } else { - f = fcns[ idx ]; - } - // Evaluate the ndarray function: - if ( data ) { - f( arrays, data[ idx ] ); - } else { - f( arrays ); - } - if ( nout === 1 ) { - return arrays[ narrays-1 ]; - } - if ( nout === 0 ) { - return; - } - return arrays.slice( nin ); - } -} - - -// EXPORTS // - -module.exports = dispatch; diff --git a/package.json b/package.json index 9569eb2..aab393c 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Create an ndarray function interface which performs multiple dispatch.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@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-ndarray-like": "^0.0.x", - "@stdlib/assert-is-nonnegative-integer": "^0.0.x", - "@stdlib/assert-is-positive-integer": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/array-int32": "^0.0.x", - "@stdlib/array-int8": "^0.0.x", - "@stdlib/array-uint8": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/math-base-assert-is-nan": "^0.0.x", - "@stdlib/math-base-special-abs": "^0.0.x", - "@stdlib/math-base-special-pow": "^0.0.x", - "@stdlib/math-base-special-sin": "^0.0.x", - "@stdlib/ndarray-base-buffer-dtype": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/ndarray-base-unary": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/ndarray-dtypes": "^0.0.x", - "@stdlib/ndarray-ind2sub": "^0.0.x", - "@stdlib/strided-dtypes": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "ndarray", @@ -97,7 +26,6 @@ "multimethod", "multimethods" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..52aee8e --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/fixtures/binary.js b/test/fixtures/binary.js deleted file mode 100644 index a60dfa2..0000000 --- a/test/fixtures/binary.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Binary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @returns {number} sum -*/ -function binary( x, y ) { - return x + y; -} - - -// EXPORTS // - -module.exports = binary; diff --git a/test/fixtures/fill.js b/test/fixtures/fill.js deleted file mode 100644 index 41b2958..0000000 --- a/test/fixtures/fill.js +++ /dev/null @@ -1,76 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which fills one or more ndarrays. -* -* @private -* @param {*} value - fill value -* @returns {Function} ndarray function -*/ -function fill( value ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - */ - function ndarrayFcn( arrays ) { - var opts; - var sub; - var arr; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - opts = { - 'order': '' - }; - for ( j = 0; j < M; j++ ) { - arr = arrays[ j ]; - opts.order = arrays[ j ].order; - for ( i = 0; i < N; i++ ) { - sub = ind2sub( sh, i, opts ); - sub.push( value ); - arr.set.apply( arr, sub ); - } - } - } -} - - -// EXPORTS // - -module.exports = fill; diff --git a/test/fixtures/foreach.js b/test/fixtures/foreach.js deleted file mode 100644 index a426290..0000000 --- a/test/fixtures/foreach.js +++ /dev/null @@ -1,72 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function forEach( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - fcn.apply( null, args ); - } -} - - -// EXPORTS // - -module.exports = forEach; diff --git a/test/fixtures/map1n.js b/test/fixtures/map1n.js deleted file mode 100644 index 614196b..0000000 --- a/test/fixtures/map1n.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function which maps the return value of a callback to `N` arrays. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function map1N( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var v; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - v = fcn(); - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - sub.push( v ); - arrays[ j ].set.apply( arrays[ j ], sub ); - } - } -} - - -// EXPORTS // - -module.exports = map1N; diff --git a/test/fixtures/nullary.js b/test/fixtures/nullary.js deleted file mode 100644 index 4f22126..0000000 --- a/test/fixtures/nullary.js +++ /dev/null @@ -1,36 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Nullary callback. -* -* @private -* @returns {number} value -*/ -function nullary() { - return 3.0; -} - - -// EXPORTS // - -module.exports = nullary; diff --git a/test/fixtures/quaternary.js b/test/fixtures/quaternary.js deleted file mode 100644 index 548437b..0000000 --- a/test/fixtures/quaternary.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quaternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @returns {number} sum -*/ -function quaternary( x, y, z, w ) { - return x + y + z + w; -} - - -// EXPORTS // - -module.exports = quaternary; diff --git a/test/fixtures/quinary.js b/test/fixtures/quinary.js deleted file mode 100644 index 36068de..0000000 --- a/test/fixtures/quinary.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quinary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @param {number} u - input value -* @returns {number} sum -*/ -function quinary( x, y, z, w, u ) { - return x + y + z + w + u; -} - - -// EXPORTS // - -module.exports = quinary; diff --git a/test/fixtures/sum.js b/test/fixtures/sum.js deleted file mode 100644 index efdbb1b..0000000 --- a/test/fixtures/sum.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which computes the sum across one or more ndarrays. -* -* @private -* @param {Object} ctx - context -* @param {number} ctx.sum - initial sum -* @returns {Function} ndarray function -*/ -function wrapper( ctx ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - * @param {Function} [fcn] - callback - */ - function ndarrayFcn( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var f; - var i; - var j; - - if ( arguments.length > 1 ) { - f = fcn; - } - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - if ( f ) { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - ctx.sum += f.apply( null, args ); - } - } else { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - ctx.sum += arrays[ j ].get.apply( arrays[ j ], sub ); - } - } - } - } -} - - -// EXPORTS // - -module.exports = wrapper; diff --git a/test/fixtures/ternary.js b/test/fixtures/ternary.js deleted file mode 100644 index 0595d5f..0000000 --- a/test/fixtures/ternary.js +++ /dev/null @@ -1,39 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Ternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @returns {number} sum -*/ -function ternary( x, y, z ) { - return x + y + z; -} - - -// EXPORTS // - -module.exports = ternary; diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d6c2c8e..0000000 --- a/test/test.js +++ /dev/null @@ -1,363 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var fill = require( './fixtures/fill.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either a function or an array of functions as a first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( value, types, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object as a second argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided either an array-like object or `null` as a third argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - dispatch( unary, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a positive integer for a fourth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 0, - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a fifth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, value, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a sixth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, 1, value ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function array)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var fcns = [ unary, unary, unary ]; - var data = [ abs, abs, abs ]; - dispatch( fcns, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function argument)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs, abs, abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the length of `data` argument does not match the number of ndarray functions', function test( t ) { - var values; - var i; - - values = [ - [], - [ abs, abs ], - [ abs, abs, abs ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var fcns = [ unary ]; - dispatch( fcns, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the fourth argument is incompatible with the number of input and output ndarrays', function test( t ) { - var values; - var i; - - values = [ - 0, - 1, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of specified input and output ndarrays is zero', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var types = [ 'float64' ]; - dispatch( fill( 3 ), types, null, 1, 0, 0 ); - } -}); - -tape( 'the function returns an ndarray function interface', function test( t ) { - var types; - var data; - var f; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - f = dispatch( unary, types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ unary ], types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( fill( 3 ), types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ fill( 3 ) ], types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.two_arrays.js b/test/test.two_arrays.js deleted file mode 100644 index 071500e..0000000 --- a/test/test.two_arrays.js +++ /dev/null @@ -1,808 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var dtype = require( '@stdlib/ndarray-base-buffer-dtype' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var forEach = require( './fixtures/foreach.js' ); -var map1N = require( './fixtures/map1n.js' ); -var fill = require( './fixtures/fill.js' ); -var sum = require( './fixtures/sum.js' ); - - -// TESTS // - -tape( 'the function returns a function which throws an error if not provided an ndarray for the first argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var ybuf = new Float64Array( 10 ); - var y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( value, y ); - }; - } -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the second argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var xbuf = new Float64Array( 10 ); - var x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( x, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided insufficient arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var f; - var x; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [], - [ x ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided too many arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var ybuf; - var f; - var x; - var y; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [ x, y, y ], - [ x, y, y, y ], - [ x, y, y, y, y ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if unable to resolve a ndarray function supporting the provided array argument data types', function test( t ) { - var values; - var types; - var data; - var xbuf; - var fcn; - var x; - var i; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ abs, abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 4 ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - values = [ - new Uint8Array( 4 ), - new Int32Array( 4 ), - [ 0, 0, 0, 0 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided an array having data type: ' + dtype( values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var y = ndarray( dtype( value ), value, [ value.length ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - }; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only input arrays)', function test( t ) { - var types; - var xbuf; - var ybuf; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only output arrays)', function test( t ) { - var expected; - var types; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only input arrays)', function test( t ) { - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var ctx; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcns = [ - sum( ctx ), - sum( ctx ) - ]; - fcn = dispatch( fcns, types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only output arrays)', function test( t ) { - var expected; - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcns = [ - fill( 3.0 ), - fill( 4.0 ) - ]; - fcn = dispatch( fcns, types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - - fcn = dispatch( forEach, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - - fcn = dispatch( map1N, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - fcns = [ - forEach, - forEach - ]; - fcn = dispatch( fcns, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - fcns = [ - map1N, - map1N - ]; - fcn = dispatch( fcns, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - fcns = [ - unary, - unary - ]; - fcn = dispatch( fcns, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which returns one or more output arrays, if one or more output arrays is specified, and otherwise returns `undefined`', function test( t ) { - var types; - var data; - var xbuf; - var ybuf; - var out; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - // No output arrays... - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, void 0, 'returns expected value' ); - - // One output array... - data = [ - abs, - abs - ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - fcn = dispatch( fill( 3.0 ), types, null, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - // Two output arrays... - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.end(); -}); From 2036fa81d3c444bc7ead0de7dd2241466b83bcd7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 03:55:56 +0000 Subject: [PATCH 020/109] Transform error messages --- lib/main.js | 28 ++++++++++++++-------------- package.json | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/main.js b/lib/main.js index 3d28781..c8218ef 100644 --- a/lib/main.js +++ b/lib/main.js @@ -27,7 +27,7 @@ var isFunctionArray = require( '@stdlib/assert-is-function-array' ); var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var indexOfTypes = require( './index_of_types.js' ); @@ -89,43 +89,43 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { if ( isFunction( fcns ) ) { fcn = fcns; } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) ); + throw new TypeError( format( '0Mq5s', fcns ) ); } if ( !isCollection( types ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) ); + throw new TypeError( format( '0Mq3A', types ) ); } if ( !isCollection( data ) && data !== null ) { throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); } if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) ); + throw new TypeError( format( '0Mq5u', nargs ) ); } if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) ); + throw new TypeError( format( '0Mq5v', nin ) ); } if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) ); + throw new TypeError( format( '0Mq5w', nout ) ); } narrays = nin + nout; if ( narrays === 0 ) { - throw new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' ); + throw new Error( format( '0Mq0h' ) ); } if ( nargs !== narrays ) { - throw new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' ); + throw new Error( format( '0Mq0i' ) ); } if ( fcn ) { nfcns = types.length / narrays; if ( !isInteger( nfcns ) ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format( '0Mq0j' ) ); } } else { nfcns = fcns.length; if ( types.length !== nfcns*narrays ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format( '0Mq0j' ) ); } } if ( data && data.length !== nfcns ) { - throw new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' ); + throw new Error( format( '0Mq0k' ) ); } return dispatcher; @@ -154,9 +154,9 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { argc = arguments.length; if ( argc !== nargs ) { if ( argc < nargs ) { - throw new Error( 'invalid invocation. Insufficient arguments.' ); + throw new Error( format( '0Mq0l' ) ); } - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format( '0Mq0m' ) ); } arrays = []; dtypes = []; @@ -177,7 +177,7 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { // Check whether we were able to successfully resolve an ndarray function: if ( idx < 0 ) { - throw new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' ); + throw new TypeError( format( '0Mq0p' ) ); } // Retrieve the ndarray function: if ( fcn ) { diff --git a/package.json b/package.json index 014d480..9569eb2 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-ndarray-like": "^0.0.x", "@stdlib/assert-is-nonnegative-integer": "^0.0.x", "@stdlib/assert-is-positive-integer": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From 77d74bbfec2c6b7f98f764cffa3bab6bede9309f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 14:53:37 +0000 Subject: [PATCH 021/109] Remove files --- index.d.ts | 334 ------ index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 3028 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index e8f79c8..0000000 --- a/index.d.ts +++ /dev/null @@ -1,334 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* ndarray function. -* -* @param arrays - array containing input and output ndarrays -* @param data - ndarray function data (e.g., a callback) -* -* @example -* var numel = require( `@stdlib/ndarray/base/numel` ); -* var ind2sub = require( `@stdlib/ndarray/ind2sub` ); -* -* function ndarrayFcn( arrays, fcn ) { -* var xord; -* var yord; -* var opts; -* var sub; -* var sh; -* var N; -* var x; -* var y; -* var v; -* var i; -* -* x = arrays[ 0 ]; -* y = arrays[ 1 ]; -* sh = x.shape; -* N = numel( sh ); -* if ( N <= 0 ) { -* return; -* } -* xord = x.order; -* yord = y.order; -* opts = {}; -* opts.order = xord; -* for ( i = 0; i < N; i++ ) { -* // Convert a linear index to subscripts: -* opts.order = xord; -* sub = ind2sub( sh, i, opts ); -* -* // Retrieve an element from `x`: -* v = x.get.apply( x, sub ); -* -* // Convert a linear index to subscripts: -* opts.order = yord; -* sub = ind2sub( sh, i, opts ); -* -* // Append the result of applying the callback: -* sub.push( fcn( v ) ); -* -* // Assign the result to an element in `y`: -* y.set.apply( y, sub ); -* } -* } -*/ -type ndarrayFcn = ( arrays: Array, data?: any ) => void; - -/** -* Interface describing an ndarray function dispatcher. -*/ -interface Dispatcher { - /** - * Invokes an ndarray function based on the provided array data type(s). - * - * @param x - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array - * - * @example - * var nullary = require( `@stdlib/ndarray/base/nullary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function value() { - * return 3.14; - * } - * - * var types = [ 'float64' ]; - * var data = [ value ]; - * - * var fcn = dispatch( nullary, types, data, 1, 0, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( 5 ); - * var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x ); - * // xbuf => [ 3.14, 3.14, 3.14, 3.14, 3.14 ] - */ - ( x: ndarray ): ndarray | void; - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var unary = require( `@stdlib/ndarray/base/unary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * var abs = require( `@stdlib/math/base/special/abs` ); - * - * var types = [ 'float64', 'float64' ]; - * var data = [ abs ]; - * - * var fcn = dispatch( unary, types, data, 2, 1, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - * var ybuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y ); - * // ybuf => [ 1.0, 2.0, 3.0 ] - */ - ( x: ndarray, y: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var ternary = require( `@stdlib/ndarray/base/ternary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add2( x, y ) { - * return x + y; - * } - * - * var types = [ 'float64', 'float64', 'float64' ]; - * var data = [ add2 ]; - * - * var fcn = dispatch( ternary, types, data, 3, 2, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z ); - * // zbuf => [ 2.0, 4.0, 6.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quaternary = require( `@stdlib/ndarray/base/quaternary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add3( x, y, z ) { - * return x + y + z; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add3 ]; - * - * var fcn = dispatch( quaternary, types, data, 4, 3, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w ); - * // wbuf => [ 3.0, 6.0, 9.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @param args - ndarray arguments - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quinary = require( `@stdlib/ndarray/base/quinary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add4( x, y, z, w ) { - * return x + y + z + w; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add4 ]; - * - * var fcn = dispatch( quinary, types, data, 5, 4, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ubuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var u = ndarray( 'float64', ubuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w, u ); - * // ubuf => [ 4.0, 8.0, 12.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray, ...args: Array ): ndarray | void; // tslint:disable-line:max-line-length unified-signatures -} - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param fcns - list of ndarray functions -* @param types - one-dimensional list of ndarray argument data types -* @param data - ndarray function data (e.g., callbacks) -* @param nargs - total number of ndarray function interface arguments -* @param nin - number of input ndarrays -* @param nout - number of output ndarrays -* @throws first argument must be either a function or an array of functions -* @throws second argument must be an array-like object -* @throws third argument must be an array-like object or `null` -* @throws third and first arguments must have the same number of elements -* @throws fourth argument must be a positive integer -* @throws fifth argument must be a nonnegative integer -* @throws sixth argument must be a nonnegative integer -* @throws fourth argument must equal the specified number of input and output arrays -* @throws number of types must match the number of functions times the total number of array arguments for each function -* @throws interface must accept at least one input and/or output ndarray -* @returns ndarray function interface -* -* @example -* var unary = require( `@stdlib/ndarray/base/unary` ); -* var abs = require( `@stdlib/math/base/special/abs` ); -* var Float64Array = require( `@stdlib/array/float64` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var fcn = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* fcn( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function dispatch( fcns: ndarrayFcn | ArrayLike, types: ArrayLike, data: ArrayLike | null, nargs: number, nin: number, nout: number ): Dispatcher; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = dispatch; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index f48c2d5..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function m(r,e,t,i,s,n,o,l,m){var d,a,h,f;for(d=n,h=0;h [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0Mq5s', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0Mq3A', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0Mq5u', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0Mq5v', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0Mq5w', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format( '0Mq0h' ) );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format( '0Mq0i' ) );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format( '0Mq0k' ) );\n\t}\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format( '0Mq0l' ) );\n\t\t\t}\n\t\t\tthrow new Error( format( '0Mq0m' ) );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( v.dtype );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format( '0Mq0p' ) );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n"],"names":["indexOfTypes","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","i","j","dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","push","dtype","slice"],"mappings":";;uvBA6EA,SAASA,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,KAAgBE,EAAGI,GADdE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,EAEP,OAAQ,EChBT,SAASU,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,sFAAuFV,IAErH,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAQ,UAE1B,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAQ,UAE1B,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAQ,eAI1B,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAQ,UAG3B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAQ,UAE1B,OAeA,WACC,IAAIO,EACAC,EACAC,EACAC,EACAC,EACAC,EACA3B,EAGJ,IADAwB,EAAOI,UAAUR,UACHd,EAAQ,CACrB,GAAKkB,EAAOlB,EACX,MAAM,IAAIa,MAAOJ,EAAQ,UAE1B,MAAM,IAAII,MAAOJ,EAAQ,UAI1B,IAFAO,EAAS,GACTC,EAAS,GACHvB,EAAI,EAAGA,EAAIM,EAAON,IAAM,CAE7B,IAAM6B,EADNH,EAAIE,UAAW5B,IAEd,MAAKA,EAAIO,EACF,IAAIO,UAAWC,EAAQ,6EAA8EW,IAErG,IAAIZ,UAAWC,EAAQ,8EAA+EW,IAG9GJ,EAAOQ,KAAMJ,GACbH,EAAOO,KAAMJ,EAAEK,OAMhB,IAHAN,EAAMrC,EAAcsB,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGc,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAIT,UAAWC,EAAQ,UAI7BY,EADIhB,GAGAR,EAAMsB,GAGNpB,EACJsB,EAAGL,EAAQjB,EAAMoB,IAEjBE,EAAGL,GAEJ,GAAc,IAATd,EACJ,OAAOc,EAAQb,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOc,EAAOU,MAAOzB"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 52aee8e..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 2f37d26ecbde4183def003e72e730c110a760bd8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 14:54:33 +0000 Subject: [PATCH 022/109] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 760 ---- .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 - .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 59 +- benchmark/benchmark.dispatch_size.js | 156 - benchmark/benchmark.js | 81 - branches.md | 53 - docs/repl.txt | 87 - docs/types/test.ts | 641 ---- examples/add.js | 121 - examples/sin.js | 142 - examples/unary.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/index_of_types.js | 106 - lib/main.js | 207 -- package.json | 76 +- stats.html | 4044 +++++++++++++++++++++ test/fixtures/binary.js | 38 - test/fixtures/fill.js | 76 - test/fixtures/foreach.js | 72 - test/fixtures/map1n.js | 74 - test/fixtures/nullary.js | 36 - test/fixtures/quaternary.js | 40 - test/fixtures/quinary.js | 41 - test/fixtures/sum.js | 98 - test/fixtures/ternary.js | 39 - test/test.js | 363 -- test/test.two_arrays.js | 808 ---- 51 files changed, 4078 insertions(+), 6396 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.dispatch_size.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/add.js delete mode 100644 examples/sin.js delete mode 100644 examples/unary.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/index_of_types.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/fixtures/binary.js delete mode 100644 test/fixtures/fill.js delete mode 100644 test/fixtures/foreach.js delete mode 100644 test/fixtures/map1n.js delete mode 100644 test/fixtures/nullary.js delete mode 100644 test/fixtures/quaternary.js delete mode 100644 test/fixtures/quinary.js delete mode 100644 test/fixtures/sum.js delete mode 100644 test/fixtures/ternary.js delete mode 100644 test/test.js delete mode 100644 test/test.two_arrays.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index eb62ff7..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-11-01T01:47:32.528Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ac0b7cd..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 920b304..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 34e41d6..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '43 7 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9113bfe..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,760 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -291,7 +284,7 @@ console.log( ybuf ); ## 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. +This package is part of [stdlib][stdlib], a standard library 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]. @@ -353,11 +346,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm diff --git a/benchmark/benchmark.dispatch_size.js b/benchmark/benchmark.dispatch_size.js deleted file mode 100644 index 3bd0418..0000000 --- a/benchmark/benchmark.dispatch_size.js +++ /dev/null @@ -1,156 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib/main.js' ); - - -// FUNCTIONS // - -/** -* Evaluates the identity function. -* -* @private -* @param {*} v - value -* @returns {*} input value -*/ -function identity( v ) { - return v; -} - -/** -* Dummy function which throws an error. -* -* @private -* @throws {Error} unexpected error -*/ -function throwError() { - throw new Error( 'unexpected error' ); -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} size - dispatch size -* @returns {Function} benchmark function -*/ -function createBenchmark( size ) { - var types; - var data; - var fcn; - var x; - var y; - var t; - var i; - - types = []; - - // Create dummy types... - for ( i = 0; i < (size-1)*2; i += 2 ) { - t = 'foo' + i; - types.push( t ); - types.push( t ); - } - // Append test types: - types.push( 'float64' ); - types.push( 'float64' ); - - // Define a list of callbacks: - data = []; - for ( i = 0; i < size-1; i++ ) { - data.push( throwError ); - } - // Append a test callback: - data.push( identity ); - - // Create the dispatcher: - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - // Create sample arrays: - x = new Float64Array( 1 ); - y = new Float64Array( x.length ); - - x = ndarray( 'float64', x, [ 1 ], [ 1 ], 0, 'row-major' ); - y = ndarray( 'float64', y, [ 1 ], [ 1 ], 0, 'row-major' ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var z; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x.data[ 0 ] = i; - z = fcn( x, y ); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var size; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - size = pow( 2, i ); - f = createBenchmark( size ); - bench( pkg+':size='+size, f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index a70dc5c..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::fcns_array', function benchmark( b ) { - var types; - var fcns; - var data; - var out; - var i; - - fcns = [ unary ]; - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( fcns, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::fcn_arg', function benchmark( b ) { - var types; - var data; - var out; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( unary, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index d04d051..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch" -click B href "https://github.com/stdlib-js/ndarray-dispatch/tree/main" -click C href "https://github.com/stdlib-js/ndarray-dispatch/tree/production" -click D href "https://github.com/stdlib-js/ndarray-dispatch/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-dispatch/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-dispatch/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch -[production-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 02fe150..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,87 +0,0 @@ - -{{alias}}( fcns, types, data, nargs, nin, nout ) - Returns an ndarray function interface which performs multiple dispatch. - - An ndarray function interface has the following signature: - - f( x, y, ... ) - - where - - - x: ndarray. - - y: ndarray. - - ...: additional ndarrays. - - The number of parameters is derived from `nargs`, the number of input - ndarrays is derived from `nin`, and the number of output ndarrays is derived - from `nout`. - - Parameters - ---------- - fcns: Function|ArrayLikeObject - List of ndarray functions. An ndarray function should have the following - signature: - - f( arrays, data ) - - where - - - arrays: array containing input and output ndarrays. - - data: ndarray function data (e.g., a callback). - - For convenience, a single ndarray function may be provided which will be - invoked whenever the ndarray argument data types match a sequence of - types in `types`. Providing a single ndarray function is particularly - convenient for the case where, regardless of array data types, - traversing arrays remains the same, but the ndarray function `data` - differs (e.g., callbacks which differ based on the array data types). - - types: ArrayLikeObject - One-dimensional list of ndarray argument data types. - - data: ArrayLikeObject|null - ndarray function data (e.g., callbacks). If `null`, a returned ndarray - function interface does **not** provide a `data` argument to an invoked - ndarray function. - - nargs: integer - Total number of ndarray function interface arguments. - - nin: integer - Number of input ndarrays. - - nout: integer - Number of output ndarrays. - - Returns - ------- - fcn: Function - ndarray function interface. - - Examples - -------- - // Define ndarray argument data types: - > var t = [ 'float64', 'float64', 'float32', 'float32' ]; - - // Define a list of ndarray function data (callbacks): - > var d = [ {{alias:@stdlib/math/base/special/abs}}, {{alias:@stdlib/math/base/special/absf}} ]; - - // Create an ndarray function interface for applying unary callbacks: - > var f = {{alias}}( {{alias:@stdlib/ndarray/base/unary}}, t, d, 2, 1, 1 ); - - // Create an input ndarray: - > var xbuf = new {{alias:@stdlib/array/float64}}( [ -1.0, -2.0, -3.0, -4.0 ] ); - > var x = {{alias:@stdlib/ndarray/ctor}}( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Create an output ndarray: - > var ybuf = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 0.0, 0.0 ] ); - > var y = {{alias:@stdlib/ndarray/ctor}}( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Compute the element-wise absolute value: - > f( x, y ); - > ybuf - [ 1.0, 2.0, 3.0, 4.0 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 397185e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,641 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// tslint:disable:max-file-line-count - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import dispatch = require( './index' ); - - -// FUNCTIONS // - -/** -* Nullary callback. -* -* @return input value -*/ -function nullary(): any { - return 5.0; -} - -/** -* Unary callback. -* -* @param x - input value -* @return input value -*/ -function unary( x: any ): any { - return x; -} - -/** -* Binary callback. -* -* @param x - input value -* @param y - input value -* @return output value -*/ -function binary( x: number, y: number ): number { - return x + y; -} - -/** -* Ternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @return output value -*/ -function ternary( x: number, y: number, z: number ): number { - return x + y + z; -} - -/** -* Quaternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @param w - input value -* @return output value -*/ -function quaternary( x: number, y: number, z: number, w: number ): number { - return x + y + z + w; -} - -/** -* Mock `ind2sub` function. -* -* @param shape - dimensions -* @param idx - linear index -* @param opts - options -* @return subscripts -*/ -function ind2sub( shape: ArrayLike, idx: number, opts?: any ): Array { // tslint:disable-line:max-line-length - let out; - let i; - - out = []; - if ( typeof opts === 'object' && opts !== null && opts.order === 'row-major' ) { // tslint:disable-line:max-line-length no-unsafe-any - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } else { - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } - return out; -} - -/** -* Mock ndarray function. -* -* @param arrays - ndarrays -* @param fcn - callback -*/ -function ndarrayFcn( arrays: Array, fcn: ( x: any ) => any ): void { - let xord; - let yord; - let opts; - let sub; - let sh; - let N; - let x; - let y; - let v; - let i; - - x = arrays[ 0 ]; - y = arrays[ 1 ]; - sh = x.shape; - if ( sh.length === 0 ) { - return; - } - N = 1; - for ( i = 0; i < sh.length; i += 1 ) { - N *= sh[ i ]; - } - xord = x.order; - yord = y.order; - opts = { - 'order': '' - }; - opts.order = xord; - for ( i = 0; i < N; i += 1 ) { - // Convert a linear index to subscripts: - opts.order = xord; - sub = ind2sub( sh, i, opts ); - - // Retrieve an element from `x`: - v = x.get.apply( x, sub ); - - // Convert a linear index to subscripts: - opts.order = yord; - sub = ind2sub( sh, i, opts ); - - // Append the result of applying the callback: - sub[ sub.length ] = fcn( v ) as number; - - // Assign the result to an element in `y`: - y.set.apply( y, sub ); - } -} - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a dispatch function... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, 1 ); // $ExpectType Dispatcher - dispatch( [ ndarrayFcn ], types, data, 2, 1, 1 ); // $ExpectType Dispatcher -} - -// The compiler throws an error if the function is provided a first argument which is not either an ndarray function or an array-like object containing ndarray functions... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( '10', types, data, 2, 1, 1 ); // $ExpectError - dispatch( 10, types, data, 2, 1, 1 ); // $ExpectError - dispatch( true, types, data, 2, 1, 1 ); // $ExpectError - dispatch( false, types, data, 2, 1, 1 ); // $ExpectError - dispatch( null, types, data, 2, 1, 1 ); // $ExpectError - dispatch( undefined, types, data, 2, 1, 1 ); // $ExpectError - dispatch( [ '1' ], types, data, 2, 1, 1 ); // $ExpectError - dispatch( {}, types, data, 2, 1, 1 ); // $ExpectError - dispatch( ( x: number ): number => x, types, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object... -{ - const data = [ unary ]; - - dispatch( ndarrayFcn, 10, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, true, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, false, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, null, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, undefined, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, {}, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object or null... -{ - const types = [ 'float64', 'float64' ]; - - dispatch( ndarrayFcn, types, 10, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, true, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, false, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, undefined, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, {}, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, '10', 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, true, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, false, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, null, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, undefined, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, [ '1' ], 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, {}, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, ( x: number ): number => x, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, '10', 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, true, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, false, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, null, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, undefined, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, [ '1' ], 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, {}, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, ( x: number ): number => x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, '10' ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, true ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, false ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, null ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, undefined ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, [ '1' ] ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, {} ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch(); // $ExpectError - dispatch( ndarrayFcn ); // $ExpectError - dispatch( ndarrayFcn, types ); // $ExpectError - dispatch( ndarrayFcn, types, data ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, 1, 0 ); // $ExpectError -} - -// The function returns a dispatch function... -{ - const x = array(); - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const t1 = [ 'float64' ]; - const d1 = [ nullary ]; - const f1 = dispatch( ndarrayFcn, t1, d1, 1, 1, 0 ); - f1( x ); // $ExpectType void | ndarray - - const t2 = [ 'float64', 'float64' ]; - const d2 = [ unary ]; - const f2 = dispatch( ndarrayFcn, t2, d2, 2, 1, 1 ); - f2( x, y ); // $ExpectType void | ndarray - - const t3 = [ 'float64', 'float64', 'float64' ]; - const d3 = [ binary ]; - const f3 = dispatch( ndarrayFcn, t3, d3, 3, 2, 1 ); - f3( x, y, z ); // $ExpectType void | ndarray - - const t4 = [ 'float64', 'float64', 'float64', 'float64' ]; - const d4 = [ ternary ]; - const f4 = dispatch( ndarrayFcn, t4, d4, 4, 3, 1 ); - f4( x, y, z, w ); // $ExpectType void | ndarray - - const t5 = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const d5 = [ quaternary ]; - const f5 = dispatch( ndarrayFcn, t5, d5, 5, 4, 1 ); - f5( x, y, z, w, u ); // $ExpectType void | ndarray -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (1 ndarray)... -{ - const types = [ 'float64' ]; - const data = [ nullary ]; - - const f = dispatch( ndarrayFcn, types, data, 1, 0, 1 ); - f( '10' ); // $ExpectError - f( 10 ); // $ExpectError - f( true ); // $ExpectError - f( false ); // $ExpectError - f( null ); // $ExpectError - f( undefined ); // $ExpectError - f( [ '1' ] ); // $ExpectError - f( {} ); // $ExpectError - f( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( 10, y ); // $ExpectError - f( '10', y ); // $ExpectError - f( true, y ); // $ExpectError - f( false, y ); // $ExpectError - f( null, y ); // $ExpectError - f( undefined, y ); // $ExpectError - f( [ '1' ], y ); // $ExpectError - f( {}, y ); // $ExpectError - f( ( x: number ): number => x, y ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const x = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( x, 10 ); // $ExpectError - f( x, '10' ); // $ExpectError - f( x, true ); // $ExpectError - f( x, false ); // $ExpectError - f( x, null ); // $ExpectError - f( x, undefined ); // $ExpectError - f( x, [ '1' ] ); // $ExpectError - f( x, {} ); // $ExpectError - f( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( 10, y, z ); // $ExpectError - f( '10', y, z ); // $ExpectError - f( true, y, z ); // $ExpectError - f( false, y, z ); // $ExpectError - f( null, y, z ); // $ExpectError - f( undefined, y, z ); // $ExpectError - f( [ '1' ], y, z ); // $ExpectError - f( {}, y, z ); // $ExpectError - f( ( x: number ): number => x, y, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, 10, z ); // $ExpectError - f( x, '10', z ); // $ExpectError - f( x, true, z ); // $ExpectError - f( x, false, z ); // $ExpectError - f( x, null, z ); // $ExpectError - f( x, undefined, z ); // $ExpectError - f( x, [ '1' ], z ); // $ExpectError - f( x, {}, z ); // $ExpectError - f( x, ( x: number ): number => x, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, y, '10' ); // $ExpectError - f( x, y, true ); // $ExpectError - f( x, y, false ); // $ExpectError - f( x, y, null ); // $ExpectError - f( x, y, undefined ); // $ExpectError - f( x, y, [ '1' ] ); // $ExpectError - f( x, y, {} ); // $ExpectError - f( x, y, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( 10, y, z, w ); // $ExpectError - f( '10', y, z, w ); // $ExpectError - f( true, y, z, w ); // $ExpectError - f( false, y, z, w ); // $ExpectError - f( null, y, z, w ); // $ExpectError - f( undefined, y, z, w ); // $ExpectError - f( [ '1' ], y, z, w ); // $ExpectError - f( {}, y, z, w ); // $ExpectError - f( ( x: number ): number => x, y, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, 10, z, w ); // $ExpectError - f( x, '10', z, w ); // $ExpectError - f( x, true, z, w ); // $ExpectError - f( x, false, z, w ); // $ExpectError - f( x, null, z, w ); // $ExpectError - f( x, undefined, z, w ); // $ExpectError - f( x, [ '1' ], z, w ); // $ExpectError - f( x, {}, z, w ); // $ExpectError - f( x, ( x: number ): number => x, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, 10, w ); // $ExpectError - f( x, y, '10', w ); // $ExpectError - f( x, y, true, w ); // $ExpectError - f( x, y, false, w ); // $ExpectError - f( x, y, null, w ); // $ExpectError - f( x, y, undefined, w ); // $ExpectError - f( x, y, [ '1' ], w ); // $ExpectError - f( x, y, {}, w ); // $ExpectError - f( x, y, ( x: number ): number => x, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, z, 10 ); // $ExpectError - f( x, y, z, '10' ); // $ExpectError - f( x, y, z, true ); // $ExpectError - f( x, y, z, false ); // $ExpectError - f( x, y, z, null ); // $ExpectError - f( x, y, z, undefined ); // $ExpectError - f( x, y, z, [ '1' ] ); // $ExpectError - f( x, y, z, {} ); // $ExpectError - f( x, y, z, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( 10, y, z, w, u ); // $ExpectError - f( '10', y, z, w, u ); // $ExpectError - f( true, y, z, w, u ); // $ExpectError - f( false, y, z, w, u ); // $ExpectError - f( null, y, z, w, u ); // $ExpectError - f( undefined, y, z, w, u ); // $ExpectError - f( [ '1' ], y, z, w, u ); // $ExpectError - f( {}, y, z, w, u ); // $ExpectError - f( ( x: number ): number => x, y, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, 10, z, w, u ); // $ExpectError - f( x, '10', z, w, u ); // $ExpectError - f( x, true, z, w, u ); // $ExpectError - f( x, false, z, w, u ); // $ExpectError - f( x, null, z, w, u ); // $ExpectError - f( x, undefined, z, w, u ); // $ExpectError - f( x, [ '1' ], z, w, u ); // $ExpectError - f( x, {}, z, w, u ); // $ExpectError - f( x, ( x: number ): number => x, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, 10, w, u ); // $ExpectError - f( x, y, '10', w, u ); // $ExpectError - f( x, y, true, w, u ); // $ExpectError - f( x, y, false, w, u ); // $ExpectError - f( x, y, null, w, u ); // $ExpectError - f( x, y, undefined, w, u ); // $ExpectError - f( x, y, [ '1' ], w, u ); // $ExpectError - f( x, y, {}, w, u ); // $ExpectError - f( x, y, ( x: number ): number => x, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, 10, u ); // $ExpectError - f( x, y, z, '10', u ); // $ExpectError - f( x, y, z, true, u ); // $ExpectError - f( x, y, z, false, u ); // $ExpectError - f( x, y, z, null, u ); // $ExpectError - f( x, y, z, undefined, u ); // $ExpectError - f( x, y, z, [ '1' ], u ); // $ExpectError - f( x, y, z, {}, u ); // $ExpectError - f( x, y, z, ( x: number ): number => x, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fifth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, w, 10 ); // $ExpectError - f( x, y, z, w, '10' ); // $ExpectError - f( x, y, z, w, true ); // $ExpectError - f( x, y, z, w, false ); // $ExpectError - f( x, y, z, w, null ); // $ExpectError - f( x, y, z, w, undefined ); // $ExpectError - f( x, y, z, w, [ '1' ] ); // $ExpectError - f( x, y, z, w, {} ); // $ExpectError - f( x, y, z, w, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/add.js b/examples/add.js deleted file mode 100644 index 775b711..0000000 --- a/examples/add.js +++ /dev/null @@ -1,121 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var dispatch = require( './../lib' ); - -function add2( arrays ) { - var opts; - var xo; - var yo; - var zo; - var sx; - var sy; - var sz; - var sh; - var N; - var x; - var y; - var z; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - z = arrays[ 2 ]; - xo = x.order; - yo = y.order; - zo = z.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - opts.order = yo; - sy = ind2sub( sh, i, opts ); - v = x.get.apply( x, sx ) + y.get.apply( y, sy ); - - opts.order = zo; - sz = ind2sub( sh, i, opts ); - sz.push( v ); - z.set.apply( z, sz ); - } -} - -var fcns = [ - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2 -]; - -var types = [ - dtypes.float64, dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.int32, dtypes.int32, - dtypes.uint32, dtypes.uint32, dtypes.uint32, - dtypes.int16, dtypes.int16, dtypes.int16, - dtypes.uint16, dtypes.uint16, dtypes.uint16, - dtypes.int8, dtypes.int8, dtypes.int8, - dtypes.uint8, dtypes.uint8, dtypes.uint8, - dtypes.uint8c, dtypes.uint8c, dtypes.uint8c -]; - -var add = dispatch( fcns, types, null, 3, 2, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var zbuf = new Float64Array( xbuf.length ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var z = ndarray( 'float64', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); - -xbuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -ybuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -zbuf = new Int32Array( xbuf.length ); - -x = ndarray( 'int32', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'int32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -z = ndarray( 'int32', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); diff --git a/examples/sin.js b/examples/sin.js deleted file mode 100644 index 8cd4871..0000000 --- a/examples/sin.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int8Array = require( '@stdlib/array-int8' ); -var sin = require( '@stdlib/math-base-special-sin' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/strided-dtypes' ); -var dispatch = require( './../lib' ); - -function apply( arrays, fcn ) { - var opts; - var xo; - var yo; - var sx; - var sy; - var sh; - var N; - var x; - var y; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - xo = x.order; - yo = y.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - v = fcn( x.get.apply( x, sx ) ); - - opts.order = yo; - sy = ind2sub( sh, i, opts ); - sy.push( v ); - y.set.apply( y, sy ); - } -} - -var fcns = [ - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply -]; - -var types = [ - dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float64, - dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.float64, - dtypes.uint32, dtypes.float64, - dtypes.int16, dtypes.float64, - dtypes.int16, dtypes.float32, - dtypes.uint16, dtypes.float64, - dtypes.uint16, dtypes.float32, - dtypes.int8, dtypes.float64, - dtypes.int8, dtypes.float32, - dtypes.uint8, dtypes.float64, - dtypes.uint8, dtypes.float32, - dtypes.uint8c, dtypes.float64, - dtypes.uint8c, dtypes.float32 -]; - -var data = [ - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin -]; - -var sine = dispatch( fcns, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); - -xbuf = new Int8Array( [ 1, 2, 3, 4, 5 ] ); -ybuf = new Float32Array( xbuf.length ); - -x = ndarray( 'int8', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'float32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); diff --git a/examples/unary.js b/examples/unary.js deleted file mode 100644 index e9c3fb4..0000000 --- a/examples/unary.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -var unary = require( '@stdlib/ndarray-base-unary' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var dispatch = require( './../lib' ); - -var types = [ 'float64', 'float64' ]; - -var data = [ - abs -]; - -var absolute = dispatch( unary, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -absolute( x, y ); -console.log( ybuf ); -// => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 610167d..e8f79c8 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..f48c2d5 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function m(r,e,t,i,s,n,o,l,m){var d,a,h,f;for(d=n,h=0;h [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0Mq5s', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0Mq3A', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0Mq5u', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0Mq5v', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0Mq5w', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format( '0Mq0h' ) );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format( '0Mq0i' ) );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format( '0Mq0k' ) );\n\t}\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format( '0Mq0l' ) );\n\t\t\t}\n\t\t\tthrow new Error( format( '0Mq0m' ) );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( v.dtype );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format( '0Mq0p' ) );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n"],"names":["indexOfTypes","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","i","j","dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","push","dtype","slice"],"mappings":";;uvBA6EA,SAASA,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,KAAgBE,EAAGI,GADdE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,CACN,CACD,OAAQ,CACT,CCjBA,SAASU,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,sFAAuFV,IAErH,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAQ,UAE1B,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAQ,UAE1B,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAQ,eAI1B,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAQ,UAG3B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAQ,UAE1B,OAeA,WACC,IAAIO,EACAC,EACAC,EACAC,EACAC,EACAC,EACA3B,EAGJ,IADAwB,EAAOI,UAAUR,UACHd,EAAQ,CACrB,GAAKkB,EAAOlB,EACX,MAAM,IAAIa,MAAOJ,EAAQ,UAE1B,MAAM,IAAII,MAAOJ,EAAQ,SACzB,CAGD,IAFAO,EAAS,GACTC,EAAS,GACHvB,EAAI,EAAGA,EAAIM,EAAON,IAAM,CAE7B,IAAM6B,EADNH,EAAIE,UAAW5B,IAEd,MAAKA,EAAIO,EACF,IAAIO,UAAWC,EAAQ,6EAA8EW,IAErG,IAAIZ,UAAWC,EAAQ,8EAA+EW,IAG9GJ,EAAOQ,KAAMJ,GACbH,EAAOO,KAAMJ,EAAEK,MACf,CAKD,IAHAN,EAAMrC,EAAcsB,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGc,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAIT,UAAWC,EAAQ,UAI7BY,EADIhB,GAGAR,EAAMsB,GAGNpB,EACJsB,EAAGL,EAAQjB,EAAMoB,IAEjBE,EAAGL,GAEJ,GAAc,IAATd,EACJ,OAAOc,EAAQb,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOc,EAAOU,MAAOzB,EACrB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 291641d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Create an ndarray function interface which performs multiple dispatch. -* -* @module @stdlib/ndarray-dispatch -* -* @example -* var dispatch = require( '@stdlib/ndarray-dispatch' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/index_of_types.js b/lib/index_of_types.js deleted file mode 100644 index fda2297..0000000 --- a/lib/index_of_types.js +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found). -* -* ## Notes -* -* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types). -* - The function assumes that `x` is stored in row-major order. -* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`. -* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value. -* -* @private -* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension) -* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension) -* @param {ArrayLikeObject} x - input two-dimensional reference array -* @param {integer} strideX1 - `x` stride length along first dimension -* @param {integer} strideX2 - `x` stride length along second dimension -* @param {NonNegativeInteger} offsetX - `x` starting index -* @param {ArrayLikeObject} y - search array -* @param {integer} strideY - `y` stride length -* @param {NonNegativeInteger} offsetY - `y` starting index -* @returns {integer} row index (if found) and `-1` otherwise -* -* @example -* // Define a reference array to search: -* var types = [ -* 'float64', 'float64', 'float64', -* 'float32', 'float32', 'float32', -* 'uint32', 'uint32', 'float64', -* 'int32', 'int32', 'float64', -* 'uint16', 'uint16', 'float64', -* 'int16', 'int16', 'float64', -* 'uint8', 'uint8', 'float64', -* 'int8', 'int8', 'float64' -* ]; -* -* // Define reference array dimensions: -* var N = 8; // rows -* var M = 3; // columns -* -* // Define a search array: -* y1 = [ -* 'float32', 'float32', 'float32', -* ]; -* -* // Find the list of types: -* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 ); -* // returns 1 -* -// Define a search array: -* y2 = [ -* 'float32', 'float32', 'float64', -* ]; -* -* // Find the list of types: -* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 ); -* // returns -1 -*/ -function indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len - var ix; - var iy; - var i; - var j; - - // Search for the first row which matches `y`... - ix = offsetX; - for ( i = 0; i < N; i++ ) { - iy = offsetY; - for ( j = 0; j < M; j++ ) { - if ( x[ ix+(j*strideX2) ] !== y[ iy ] ) { - break; - } - iy += strideY; - } - // If we successfully iterated over all columns, then that means we've found a match... - if ( j === M ) { - return i; - } - ix += strideX1; - } - return -1; -} - - -// EXPORTS // - -module.exports = indexOfTypes; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c8218ef..0000000 --- a/lib/main.js +++ /dev/null @@ -1,207 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isFunctionArray = require( '@stdlib/assert-is-function-array' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var indexOfTypes = require( './index_of_types.js' ); - - -// MAIN // - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param {(FunctionArray|Function)} fcns - list of ndarray functions -* @param {Collection} types - one-dimensional list of ndarray argument data types -* @param {(Collection|null)} data - ndarray function data (e.g., callbacks) -* @param {PositiveInteger} nargs - total number of ndarray function interface arguments -* @param {NonNegativeInteger} nin - number of input ndarrays -* @param {NonNegativeInteger} nout - number of output ndarrays -* @throws {TypeError} first argument must be either a function or an array of functions -* @throws {TypeError} second argument must be an array-like object -* @throws {TypeError} third argument must be an array-like object or `null` -* @throws {Error} third and first arguments must have the same number of elements -* @throws {TypeError} fourth argument must be a positive integer -* @throws {TypeError} fifth argument must be a nonnegative integer -* @throws {TypeError} sixth argument must be a nonnegative integer -* @throws {Error} fourth argument must equal the specified number of input and output arrays -* @throws {Error} number of types must match the number of functions times the total number of array arguments for each function -* @throws {Error} interface must accept at least one input and/or output ndarray -* @returns {Function} ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function dispatch( fcns, types, data, nargs, nin, nout ) { - var narrays; - var nfcns; - var fcn; - - if ( isFunction( fcns ) ) { - fcn = fcns; - } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( '0Mq5s', fcns ) ); - } - if ( !isCollection( types ) ) { - throw new TypeError( format( '0Mq3A', types ) ); - } - if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); - } - if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( '0Mq5u', nargs ) ); - } - if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( '0Mq5v', nin ) ); - } - if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( '0Mq5w', nout ) ); - } - narrays = nin + nout; - if ( narrays === 0 ) { - throw new Error( format( '0Mq0h' ) ); - } - if ( nargs !== narrays ) { - throw new Error( format( '0Mq0i' ) ); - } - if ( fcn ) { - nfcns = types.length / narrays; - if ( !isInteger( nfcns ) ) { - throw new Error( format( '0Mq0j' ) ); - } - } else { - nfcns = fcns.length; - if ( types.length !== nfcns*narrays ) { - throw new Error( format( '0Mq0j' ) ); - } - } - if ( data && data.length !== nfcns ) { - throw new Error( format( '0Mq0k' ) ); - } - return dispatcher; - - /** - * ndarray function interface which performs multiple dispatch. - * - * @private - * @param {ndarrayLike} x - ndarray - * @param {...ndarrayLike} args - ndarray arguments - * @throws {Error} insufficient arguments - * @throws {Error} too many arguments - * @throws {TypeError} input array arguments must be ndarray-like objects - * @throws {TypeError} output array arguments must be ndarray-like objects - * @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types - * @returns {(ndarrayLike|Array|void)} destination array(s) - */ - function dispatcher() { - var arrays; - var dtypes; - var argc; - var idx; - var v; - var f; - var i; - - argc = arguments.length; - if ( argc !== nargs ) { - if ( argc < nargs ) { - throw new Error( format( '0Mq0l' ) ); - } - throw new Error( format( '0Mq0m' ) ); - } - arrays = []; - dtypes = []; - for ( i = 0; i < nargs; i++ ) { - v = arguments[ i ]; - if ( !isndarrayLike( v ) ) { - if ( i < nin ) { - throw new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) ); - } else { - throw new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) ); - } - } - arrays.push( v ); - dtypes.push( v.dtype ); - } - // Resolve the ndarray function satisfying the input array types: - idx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len - - // Check whether we were able to successfully resolve an ndarray function: - if ( idx < 0 ) { - throw new TypeError( format( '0Mq0p' ) ); - } - // Retrieve the ndarray function: - if ( fcn ) { - f = fcn; - } else { - f = fcns[ idx ]; - } - // Evaluate the ndarray function: - if ( data ) { - f( arrays, data[ idx ] ); - } else { - f( arrays ); - } - if ( nout === 1 ) { - return arrays[ narrays-1 ]; - } - if ( nout === 0 ) { - return; - } - return arrays.slice( nin ); - } -} - - -// EXPORTS // - -module.exports = dispatch; diff --git a/package.json b/package.json index 9569eb2..aab393c 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Create an ndarray function interface which performs multiple dispatch.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@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-ndarray-like": "^0.0.x", - "@stdlib/assert-is-nonnegative-integer": "^0.0.x", - "@stdlib/assert-is-positive-integer": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/array-int32": "^0.0.x", - "@stdlib/array-int8": "^0.0.x", - "@stdlib/array-uint8": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/math-base-assert-is-nan": "^0.0.x", - "@stdlib/math-base-special-abs": "^0.0.x", - "@stdlib/math-base-special-pow": "^0.0.x", - "@stdlib/math-base-special-sin": "^0.0.x", - "@stdlib/ndarray-base-buffer-dtype": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/ndarray-base-unary": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/ndarray-dtypes": "^0.0.x", - "@stdlib/ndarray-ind2sub": "^0.0.x", - "@stdlib/strided-dtypes": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "ndarray", @@ -97,7 +26,6 @@ "multimethod", "multimethods" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..48a293e --- /dev/null +++ b/stats.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/fixtures/binary.js b/test/fixtures/binary.js deleted file mode 100644 index a60dfa2..0000000 --- a/test/fixtures/binary.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Binary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @returns {number} sum -*/ -function binary( x, y ) { - return x + y; -} - - -// EXPORTS // - -module.exports = binary; diff --git a/test/fixtures/fill.js b/test/fixtures/fill.js deleted file mode 100644 index 41b2958..0000000 --- a/test/fixtures/fill.js +++ /dev/null @@ -1,76 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which fills one or more ndarrays. -* -* @private -* @param {*} value - fill value -* @returns {Function} ndarray function -*/ -function fill( value ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - */ - function ndarrayFcn( arrays ) { - var opts; - var sub; - var arr; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - opts = { - 'order': '' - }; - for ( j = 0; j < M; j++ ) { - arr = arrays[ j ]; - opts.order = arrays[ j ].order; - for ( i = 0; i < N; i++ ) { - sub = ind2sub( sh, i, opts ); - sub.push( value ); - arr.set.apply( arr, sub ); - } - } - } -} - - -// EXPORTS // - -module.exports = fill; diff --git a/test/fixtures/foreach.js b/test/fixtures/foreach.js deleted file mode 100644 index a426290..0000000 --- a/test/fixtures/foreach.js +++ /dev/null @@ -1,72 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function forEach( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - fcn.apply( null, args ); - } -} - - -// EXPORTS // - -module.exports = forEach; diff --git a/test/fixtures/map1n.js b/test/fixtures/map1n.js deleted file mode 100644 index 614196b..0000000 --- a/test/fixtures/map1n.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function which maps the return value of a callback to `N` arrays. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function map1N( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var v; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - v = fcn(); - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - sub.push( v ); - arrays[ j ].set.apply( arrays[ j ], sub ); - } - } -} - - -// EXPORTS // - -module.exports = map1N; diff --git a/test/fixtures/nullary.js b/test/fixtures/nullary.js deleted file mode 100644 index 4f22126..0000000 --- a/test/fixtures/nullary.js +++ /dev/null @@ -1,36 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Nullary callback. -* -* @private -* @returns {number} value -*/ -function nullary() { - return 3.0; -} - - -// EXPORTS // - -module.exports = nullary; diff --git a/test/fixtures/quaternary.js b/test/fixtures/quaternary.js deleted file mode 100644 index 548437b..0000000 --- a/test/fixtures/quaternary.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quaternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @returns {number} sum -*/ -function quaternary( x, y, z, w ) { - return x + y + z + w; -} - - -// EXPORTS // - -module.exports = quaternary; diff --git a/test/fixtures/quinary.js b/test/fixtures/quinary.js deleted file mode 100644 index 36068de..0000000 --- a/test/fixtures/quinary.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quinary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @param {number} u - input value -* @returns {number} sum -*/ -function quinary( x, y, z, w, u ) { - return x + y + z + w + u; -} - - -// EXPORTS // - -module.exports = quinary; diff --git a/test/fixtures/sum.js b/test/fixtures/sum.js deleted file mode 100644 index efdbb1b..0000000 --- a/test/fixtures/sum.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which computes the sum across one or more ndarrays. -* -* @private -* @param {Object} ctx - context -* @param {number} ctx.sum - initial sum -* @returns {Function} ndarray function -*/ -function wrapper( ctx ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - * @param {Function} [fcn] - callback - */ - function ndarrayFcn( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var f; - var i; - var j; - - if ( arguments.length > 1 ) { - f = fcn; - } - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - if ( f ) { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - ctx.sum += f.apply( null, args ); - } - } else { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - ctx.sum += arrays[ j ].get.apply( arrays[ j ], sub ); - } - } - } - } -} - - -// EXPORTS // - -module.exports = wrapper; diff --git a/test/fixtures/ternary.js b/test/fixtures/ternary.js deleted file mode 100644 index 0595d5f..0000000 --- a/test/fixtures/ternary.js +++ /dev/null @@ -1,39 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Ternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @returns {number} sum -*/ -function ternary( x, y, z ) { - return x + y + z; -} - - -// EXPORTS // - -module.exports = ternary; diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d6c2c8e..0000000 --- a/test/test.js +++ /dev/null @@ -1,363 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var fill = require( './fixtures/fill.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either a function or an array of functions as a first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( value, types, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object as a second argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided either an array-like object or `null` as a third argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - dispatch( unary, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a positive integer for a fourth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 0, - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a fifth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, value, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a sixth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, 1, value ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function array)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var fcns = [ unary, unary, unary ]; - var data = [ abs, abs, abs ]; - dispatch( fcns, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function argument)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs, abs, abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the length of `data` argument does not match the number of ndarray functions', function test( t ) { - var values; - var i; - - values = [ - [], - [ abs, abs ], - [ abs, abs, abs ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var fcns = [ unary ]; - dispatch( fcns, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the fourth argument is incompatible with the number of input and output ndarrays', function test( t ) { - var values; - var i; - - values = [ - 0, - 1, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of specified input and output ndarrays is zero', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var types = [ 'float64' ]; - dispatch( fill( 3 ), types, null, 1, 0, 0 ); - } -}); - -tape( 'the function returns an ndarray function interface', function test( t ) { - var types; - var data; - var f; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - f = dispatch( unary, types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ unary ], types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( fill( 3 ), types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ fill( 3 ) ], types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.two_arrays.js b/test/test.two_arrays.js deleted file mode 100644 index 071500e..0000000 --- a/test/test.two_arrays.js +++ /dev/null @@ -1,808 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var dtype = require( '@stdlib/ndarray-base-buffer-dtype' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var forEach = require( './fixtures/foreach.js' ); -var map1N = require( './fixtures/map1n.js' ); -var fill = require( './fixtures/fill.js' ); -var sum = require( './fixtures/sum.js' ); - - -// TESTS // - -tape( 'the function returns a function which throws an error if not provided an ndarray for the first argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var ybuf = new Float64Array( 10 ); - var y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( value, y ); - }; - } -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the second argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var xbuf = new Float64Array( 10 ); - var x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( x, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided insufficient arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var f; - var x; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [], - [ x ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided too many arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var ybuf; - var f; - var x; - var y; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [ x, y, y ], - [ x, y, y, y ], - [ x, y, y, y, y ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if unable to resolve a ndarray function supporting the provided array argument data types', function test( t ) { - var values; - var types; - var data; - var xbuf; - var fcn; - var x; - var i; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ abs, abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 4 ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - values = [ - new Uint8Array( 4 ), - new Int32Array( 4 ), - [ 0, 0, 0, 0 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided an array having data type: ' + dtype( values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var y = ndarray( dtype( value ), value, [ value.length ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - }; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only input arrays)', function test( t ) { - var types; - var xbuf; - var ybuf; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only output arrays)', function test( t ) { - var expected; - var types; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only input arrays)', function test( t ) { - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var ctx; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcns = [ - sum( ctx ), - sum( ctx ) - ]; - fcn = dispatch( fcns, types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only output arrays)', function test( t ) { - var expected; - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcns = [ - fill( 3.0 ), - fill( 4.0 ) - ]; - fcn = dispatch( fcns, types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - - fcn = dispatch( forEach, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - - fcn = dispatch( map1N, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - fcns = [ - forEach, - forEach - ]; - fcn = dispatch( fcns, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - fcns = [ - map1N, - map1N - ]; - fcn = dispatch( fcns, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - fcns = [ - unary, - unary - ]; - fcn = dispatch( fcns, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which returns one or more output arrays, if one or more output arrays is specified, and otherwise returns `undefined`', function test( t ) { - var types; - var data; - var xbuf; - var ybuf; - var out; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - // No output arrays... - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, void 0, 'returns expected value' ); - - // One output array... - data = [ - abs, - abs - ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - fcn = dispatch( fill( 3.0 ), types, null, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - // Two output arrays... - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.end(); -}); From 8fc1b5fc0d49d35c000b98ace022df3d2dc38772 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 00:32:01 +0000 Subject: [PATCH 023/109] Transform error messages --- lib/main.js | 28 ++++++++++++++-------------- package.json | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/main.js b/lib/main.js index 3d28781..c8218ef 100644 --- a/lib/main.js +++ b/lib/main.js @@ -27,7 +27,7 @@ var isFunctionArray = require( '@stdlib/assert-is-function-array' ); var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var indexOfTypes = require( './index_of_types.js' ); @@ -89,43 +89,43 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { if ( isFunction( fcns ) ) { fcn = fcns; } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) ); + throw new TypeError( format( '0Mq5s', fcns ) ); } if ( !isCollection( types ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) ); + throw new TypeError( format( '0Mq3A', types ) ); } if ( !isCollection( data ) && data !== null ) { throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); } if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) ); + throw new TypeError( format( '0Mq5u', nargs ) ); } if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) ); + throw new TypeError( format( '0Mq5v', nin ) ); } if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) ); + throw new TypeError( format( '0Mq5w', nout ) ); } narrays = nin + nout; if ( narrays === 0 ) { - throw new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' ); + throw new Error( format( '0Mq0h' ) ); } if ( nargs !== narrays ) { - throw new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' ); + throw new Error( format( '0Mq0i' ) ); } if ( fcn ) { nfcns = types.length / narrays; if ( !isInteger( nfcns ) ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format( '0Mq0j' ) ); } } else { nfcns = fcns.length; if ( types.length !== nfcns*narrays ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format( '0Mq0j' ) ); } } if ( data && data.length !== nfcns ) { - throw new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' ); + throw new Error( format( '0Mq0k' ) ); } return dispatcher; @@ -154,9 +154,9 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { argc = arguments.length; if ( argc !== nargs ) { if ( argc < nargs ) { - throw new Error( 'invalid invocation. Insufficient arguments.' ); + throw new Error( format( '0Mq0l' ) ); } - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format( '0Mq0m' ) ); } arrays = []; dtypes = []; @@ -177,7 +177,7 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { // Check whether we were able to successfully resolve an ndarray function: if ( idx < 0 ) { - throw new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' ); + throw new TypeError( format( '0Mq0p' ) ); } // Retrieve the ndarray function: if ( fcn ) { diff --git a/package.json b/package.json index 014d480..9569eb2 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-ndarray-like": "^0.0.x", "@stdlib/assert-is-nonnegative-integer": "^0.0.x", "@stdlib/assert-is-positive-integer": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From 4ecea995fa3cee370a50659d7c09199b7e1c5f91 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 08:32:32 +0000 Subject: [PATCH 024/109] Remove files --- index.d.ts | 334 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4383 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index e8f79c8..0000000 --- a/index.d.ts +++ /dev/null @@ -1,334 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* ndarray function. -* -* @param arrays - array containing input and output ndarrays -* @param data - ndarray function data (e.g., a callback) -* -* @example -* var numel = require( `@stdlib/ndarray/base/numel` ); -* var ind2sub = require( `@stdlib/ndarray/ind2sub` ); -* -* function ndarrayFcn( arrays, fcn ) { -* var xord; -* var yord; -* var opts; -* var sub; -* var sh; -* var N; -* var x; -* var y; -* var v; -* var i; -* -* x = arrays[ 0 ]; -* y = arrays[ 1 ]; -* sh = x.shape; -* N = numel( sh ); -* if ( N <= 0 ) { -* return; -* } -* xord = x.order; -* yord = y.order; -* opts = {}; -* opts.order = xord; -* for ( i = 0; i < N; i++ ) { -* // Convert a linear index to subscripts: -* opts.order = xord; -* sub = ind2sub( sh, i, opts ); -* -* // Retrieve an element from `x`: -* v = x.get.apply( x, sub ); -* -* // Convert a linear index to subscripts: -* opts.order = yord; -* sub = ind2sub( sh, i, opts ); -* -* // Append the result of applying the callback: -* sub.push( fcn( v ) ); -* -* // Assign the result to an element in `y`: -* y.set.apply( y, sub ); -* } -* } -*/ -type ndarrayFcn = ( arrays: Array, data?: any ) => void; - -/** -* Interface describing an ndarray function dispatcher. -*/ -interface Dispatcher { - /** - * Invokes an ndarray function based on the provided array data type(s). - * - * @param x - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array - * - * @example - * var nullary = require( `@stdlib/ndarray/base/nullary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function value() { - * return 3.14; - * } - * - * var types = [ 'float64' ]; - * var data = [ value ]; - * - * var fcn = dispatch( nullary, types, data, 1, 0, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( 5 ); - * var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x ); - * // xbuf => [ 3.14, 3.14, 3.14, 3.14, 3.14 ] - */ - ( x: ndarray ): ndarray | void; - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var unary = require( `@stdlib/ndarray/base/unary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * var abs = require( `@stdlib/math/base/special/abs` ); - * - * var types = [ 'float64', 'float64' ]; - * var data = [ abs ]; - * - * var fcn = dispatch( unary, types, data, 2, 1, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - * var ybuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y ); - * // ybuf => [ 1.0, 2.0, 3.0 ] - */ - ( x: ndarray, y: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var ternary = require( `@stdlib/ndarray/base/ternary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add2( x, y ) { - * return x + y; - * } - * - * var types = [ 'float64', 'float64', 'float64' ]; - * var data = [ add2 ]; - * - * var fcn = dispatch( ternary, types, data, 3, 2, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z ); - * // zbuf => [ 2.0, 4.0, 6.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quaternary = require( `@stdlib/ndarray/base/quaternary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add3( x, y, z ) { - * return x + y + z; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add3 ]; - * - * var fcn = dispatch( quaternary, types, data, 4, 3, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w ); - * // wbuf => [ 3.0, 6.0, 9.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @param args - ndarray arguments - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quinary = require( `@stdlib/ndarray/base/quinary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add4( x, y, z, w ) { - * return x + y + z + w; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add4 ]; - * - * var fcn = dispatch( quinary, types, data, 5, 4, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ubuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var u = ndarray( 'float64', ubuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w, u ); - * // ubuf => [ 4.0, 8.0, 12.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray, ...args: Array ): ndarray | void; // tslint:disable-line:max-line-length unified-signatures -} - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param fcns - list of ndarray functions -* @param types - one-dimensional list of ndarray argument data types -* @param data - ndarray function data (e.g., callbacks) -* @param nargs - total number of ndarray function interface arguments -* @param nin - number of input ndarrays -* @param nout - number of output ndarrays -* @throws first argument must be either a function or an array of functions -* @throws second argument must be an array-like object -* @throws third argument must be an array-like object or `null` -* @throws third and first arguments must have the same number of elements -* @throws fourth argument must be a positive integer -* @throws fifth argument must be a nonnegative integer -* @throws sixth argument must be a nonnegative integer -* @throws fourth argument must equal the specified number of input and output arrays -* @throws number of types must match the number of functions times the total number of array arguments for each function -* @throws interface must accept at least one input and/or output ndarray -* @returns ndarray function interface -* -* @example -* var unary = require( `@stdlib/ndarray/base/unary` ); -* var abs = require( `@stdlib/math/base/special/abs` ); -* var Float64Array = require( `@stdlib/array/float64` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var fcn = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* fcn( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function dispatch( fcns: ndarrayFcn | ArrayLike, types: ArrayLike, data: ArrayLike | null, nargs: number, nin: number, nout: number ): Dispatcher; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = dispatch; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index f48c2d5..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function m(r,e,t,i,s,n,o,l,m){var d,a,h,f;for(d=n,h=0;h [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0Mq5s', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0Mq3A', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0Mq5u', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0Mq5v', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0Mq5w', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format( '0Mq0h' ) );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format( '0Mq0i' ) );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format( '0Mq0k' ) );\n\t}\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format( '0Mq0l' ) );\n\t\t\t}\n\t\t\tthrow new Error( format( '0Mq0m' ) );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( v.dtype );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format( '0Mq0p' ) );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n"],"names":["indexOfTypes","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","i","j","dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","push","dtype","slice"],"mappings":";;uvBA6EA,SAASA,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,KAAgBE,EAAGI,GADdE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,CACN,CACD,OAAQ,CACT,CCjBA,SAASU,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,sFAAuFV,IAErH,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAQ,UAE1B,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAQ,UAE1B,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAQ,eAI1B,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAQ,UAG3B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAQ,UAE1B,OAeA,WACC,IAAIO,EACAC,EACAC,EACAC,EACAC,EACAC,EACA3B,EAGJ,IADAwB,EAAOI,UAAUR,UACHd,EAAQ,CACrB,GAAKkB,EAAOlB,EACX,MAAM,IAAIa,MAAOJ,EAAQ,UAE1B,MAAM,IAAII,MAAOJ,EAAQ,SACzB,CAGD,IAFAO,EAAS,GACTC,EAAS,GACHvB,EAAI,EAAGA,EAAIM,EAAON,IAAM,CAE7B,IAAM6B,EADNH,EAAIE,UAAW5B,IAEd,MAAKA,EAAIO,EACF,IAAIO,UAAWC,EAAQ,6EAA8EW,IAErG,IAAIZ,UAAWC,EAAQ,8EAA+EW,IAG9GJ,EAAOQ,KAAMJ,GACbH,EAAOO,KAAMJ,EAAEK,MACf,CAKD,IAHAN,EAAMrC,EAAcsB,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGc,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAIT,UAAWC,EAAQ,UAI7BY,EADIhB,GAGAR,EAAMsB,GAGNpB,EACJsB,EAAGL,EAAQjB,EAAMoB,IAEjBE,EAAGL,GAEJ,GAAc,IAATd,EACJ,OAAOc,EAAQb,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOc,EAAOU,MAAOzB,EACrB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 48a293e..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 84dbacab355fc3d3ea1abaf4a7f50c65a465bf63 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 08:33:42 +0000 Subject: [PATCH 025/109] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 781 ---- .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 - .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 59 +- benchmark/benchmark.dispatch_size.js | 156 - benchmark/benchmark.js | 81 - branches.md | 53 - docs/repl.txt | 87 - docs/types/test.ts | 641 ---- examples/add.js | 121 - examples/sin.js | 142 - examples/unary.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/index_of_types.js | 106 - lib/main.js | 207 -- package.json | 76 +- stats.html | 4044 +++++++++++++++++++++ test/fixtures/binary.js | 38 - test/fixtures/fill.js | 76 - test/fixtures/foreach.js | 72 - test/fixtures/map1n.js | 74 - test/fixtures/nullary.js | 36 - test/fixtures/quaternary.js | 40 - test/fixtures/quinary.js | 41 - test/fixtures/sum.js | 98 - test/fixtures/ternary.js | 39 - test/test.js | 363 -- test/test.two_arrays.js | 808 ---- 51 files changed, 4078 insertions(+), 6417 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.dispatch_size.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/add.js delete mode 100644 examples/sin.js delete mode 100644 examples/unary.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/index_of_types.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/fixtures/binary.js delete mode 100644 test/fixtures/fill.js delete mode 100644 test/fixtures/foreach.js delete mode 100644 test/fixtures/map1n.js delete mode 100644 test/fixtures/nullary.js delete mode 100644 test/fixtures/quaternary.js delete mode 100644 test/fixtures/quinary.js delete mode 100644 test/fixtures/sum.js delete mode 100644 test/fixtures/ternary.js delete mode 100644 test/test.js delete mode 100644 test/test.two_arrays.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 6aed6ab..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-11-03T22:41:31.643Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ac0b7cd..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 920b304..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 34e41d6..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '43 7 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 37ddb4f..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,781 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -291,7 +284,7 @@ console.log( ybuf ); ## 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. +This package is part of [stdlib][stdlib], a standard library 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]. @@ -353,11 +346,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm diff --git a/benchmark/benchmark.dispatch_size.js b/benchmark/benchmark.dispatch_size.js deleted file mode 100644 index 3bd0418..0000000 --- a/benchmark/benchmark.dispatch_size.js +++ /dev/null @@ -1,156 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib/main.js' ); - - -// FUNCTIONS // - -/** -* Evaluates the identity function. -* -* @private -* @param {*} v - value -* @returns {*} input value -*/ -function identity( v ) { - return v; -} - -/** -* Dummy function which throws an error. -* -* @private -* @throws {Error} unexpected error -*/ -function throwError() { - throw new Error( 'unexpected error' ); -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} size - dispatch size -* @returns {Function} benchmark function -*/ -function createBenchmark( size ) { - var types; - var data; - var fcn; - var x; - var y; - var t; - var i; - - types = []; - - // Create dummy types... - for ( i = 0; i < (size-1)*2; i += 2 ) { - t = 'foo' + i; - types.push( t ); - types.push( t ); - } - // Append test types: - types.push( 'float64' ); - types.push( 'float64' ); - - // Define a list of callbacks: - data = []; - for ( i = 0; i < size-1; i++ ) { - data.push( throwError ); - } - // Append a test callback: - data.push( identity ); - - // Create the dispatcher: - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - // Create sample arrays: - x = new Float64Array( 1 ); - y = new Float64Array( x.length ); - - x = ndarray( 'float64', x, [ 1 ], [ 1 ], 0, 'row-major' ); - y = ndarray( 'float64', y, [ 1 ], [ 1 ], 0, 'row-major' ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var z; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x.data[ 0 ] = i; - z = fcn( x, y ); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var size; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - size = pow( 2, i ); - f = createBenchmark( size ); - bench( pkg+':size='+size, f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index a70dc5c..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::fcns_array', function benchmark( b ) { - var types; - var fcns; - var data; - var out; - var i; - - fcns = [ unary ]; - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( fcns, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::fcn_arg', function benchmark( b ) { - var types; - var data; - var out; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( unary, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index d04d051..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch" -click B href "https://github.com/stdlib-js/ndarray-dispatch/tree/main" -click C href "https://github.com/stdlib-js/ndarray-dispatch/tree/production" -click D href "https://github.com/stdlib-js/ndarray-dispatch/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-dispatch/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-dispatch/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch -[production-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 02fe150..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,87 +0,0 @@ - -{{alias}}( fcns, types, data, nargs, nin, nout ) - Returns an ndarray function interface which performs multiple dispatch. - - An ndarray function interface has the following signature: - - f( x, y, ... ) - - where - - - x: ndarray. - - y: ndarray. - - ...: additional ndarrays. - - The number of parameters is derived from `nargs`, the number of input - ndarrays is derived from `nin`, and the number of output ndarrays is derived - from `nout`. - - Parameters - ---------- - fcns: Function|ArrayLikeObject - List of ndarray functions. An ndarray function should have the following - signature: - - f( arrays, data ) - - where - - - arrays: array containing input and output ndarrays. - - data: ndarray function data (e.g., a callback). - - For convenience, a single ndarray function may be provided which will be - invoked whenever the ndarray argument data types match a sequence of - types in `types`. Providing a single ndarray function is particularly - convenient for the case where, regardless of array data types, - traversing arrays remains the same, but the ndarray function `data` - differs (e.g., callbacks which differ based on the array data types). - - types: ArrayLikeObject - One-dimensional list of ndarray argument data types. - - data: ArrayLikeObject|null - ndarray function data (e.g., callbacks). If `null`, a returned ndarray - function interface does **not** provide a `data` argument to an invoked - ndarray function. - - nargs: integer - Total number of ndarray function interface arguments. - - nin: integer - Number of input ndarrays. - - nout: integer - Number of output ndarrays. - - Returns - ------- - fcn: Function - ndarray function interface. - - Examples - -------- - // Define ndarray argument data types: - > var t = [ 'float64', 'float64', 'float32', 'float32' ]; - - // Define a list of ndarray function data (callbacks): - > var d = [ {{alias:@stdlib/math/base/special/abs}}, {{alias:@stdlib/math/base/special/absf}} ]; - - // Create an ndarray function interface for applying unary callbacks: - > var f = {{alias}}( {{alias:@stdlib/ndarray/base/unary}}, t, d, 2, 1, 1 ); - - // Create an input ndarray: - > var xbuf = new {{alias:@stdlib/array/float64}}( [ -1.0, -2.0, -3.0, -4.0 ] ); - > var x = {{alias:@stdlib/ndarray/ctor}}( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Create an output ndarray: - > var ybuf = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 0.0, 0.0 ] ); - > var y = {{alias:@stdlib/ndarray/ctor}}( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Compute the element-wise absolute value: - > f( x, y ); - > ybuf - [ 1.0, 2.0, 3.0, 4.0 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 397185e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,641 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// tslint:disable:max-file-line-count - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import dispatch = require( './index' ); - - -// FUNCTIONS // - -/** -* Nullary callback. -* -* @return input value -*/ -function nullary(): any { - return 5.0; -} - -/** -* Unary callback. -* -* @param x - input value -* @return input value -*/ -function unary( x: any ): any { - return x; -} - -/** -* Binary callback. -* -* @param x - input value -* @param y - input value -* @return output value -*/ -function binary( x: number, y: number ): number { - return x + y; -} - -/** -* Ternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @return output value -*/ -function ternary( x: number, y: number, z: number ): number { - return x + y + z; -} - -/** -* Quaternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @param w - input value -* @return output value -*/ -function quaternary( x: number, y: number, z: number, w: number ): number { - return x + y + z + w; -} - -/** -* Mock `ind2sub` function. -* -* @param shape - dimensions -* @param idx - linear index -* @param opts - options -* @return subscripts -*/ -function ind2sub( shape: ArrayLike, idx: number, opts?: any ): Array { // tslint:disable-line:max-line-length - let out; - let i; - - out = []; - if ( typeof opts === 'object' && opts !== null && opts.order === 'row-major' ) { // tslint:disable-line:max-line-length no-unsafe-any - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } else { - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } - return out; -} - -/** -* Mock ndarray function. -* -* @param arrays - ndarrays -* @param fcn - callback -*/ -function ndarrayFcn( arrays: Array, fcn: ( x: any ) => any ): void { - let xord; - let yord; - let opts; - let sub; - let sh; - let N; - let x; - let y; - let v; - let i; - - x = arrays[ 0 ]; - y = arrays[ 1 ]; - sh = x.shape; - if ( sh.length === 0 ) { - return; - } - N = 1; - for ( i = 0; i < sh.length; i += 1 ) { - N *= sh[ i ]; - } - xord = x.order; - yord = y.order; - opts = { - 'order': '' - }; - opts.order = xord; - for ( i = 0; i < N; i += 1 ) { - // Convert a linear index to subscripts: - opts.order = xord; - sub = ind2sub( sh, i, opts ); - - // Retrieve an element from `x`: - v = x.get.apply( x, sub ); - - // Convert a linear index to subscripts: - opts.order = yord; - sub = ind2sub( sh, i, opts ); - - // Append the result of applying the callback: - sub[ sub.length ] = fcn( v ) as number; - - // Assign the result to an element in `y`: - y.set.apply( y, sub ); - } -} - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a dispatch function... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, 1 ); // $ExpectType Dispatcher - dispatch( [ ndarrayFcn ], types, data, 2, 1, 1 ); // $ExpectType Dispatcher -} - -// The compiler throws an error if the function is provided a first argument which is not either an ndarray function or an array-like object containing ndarray functions... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( '10', types, data, 2, 1, 1 ); // $ExpectError - dispatch( 10, types, data, 2, 1, 1 ); // $ExpectError - dispatch( true, types, data, 2, 1, 1 ); // $ExpectError - dispatch( false, types, data, 2, 1, 1 ); // $ExpectError - dispatch( null, types, data, 2, 1, 1 ); // $ExpectError - dispatch( undefined, types, data, 2, 1, 1 ); // $ExpectError - dispatch( [ '1' ], types, data, 2, 1, 1 ); // $ExpectError - dispatch( {}, types, data, 2, 1, 1 ); // $ExpectError - dispatch( ( x: number ): number => x, types, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object... -{ - const data = [ unary ]; - - dispatch( ndarrayFcn, 10, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, true, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, false, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, null, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, undefined, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, {}, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object or null... -{ - const types = [ 'float64', 'float64' ]; - - dispatch( ndarrayFcn, types, 10, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, true, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, false, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, undefined, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, {}, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, '10', 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, true, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, false, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, null, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, undefined, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, [ '1' ], 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, {}, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, ( x: number ): number => x, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, '10', 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, true, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, false, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, null, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, undefined, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, [ '1' ], 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, {}, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, ( x: number ): number => x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, '10' ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, true ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, false ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, null ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, undefined ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, [ '1' ] ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, {} ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch(); // $ExpectError - dispatch( ndarrayFcn ); // $ExpectError - dispatch( ndarrayFcn, types ); // $ExpectError - dispatch( ndarrayFcn, types, data ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, 1, 0 ); // $ExpectError -} - -// The function returns a dispatch function... -{ - const x = array(); - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const t1 = [ 'float64' ]; - const d1 = [ nullary ]; - const f1 = dispatch( ndarrayFcn, t1, d1, 1, 1, 0 ); - f1( x ); // $ExpectType void | ndarray - - const t2 = [ 'float64', 'float64' ]; - const d2 = [ unary ]; - const f2 = dispatch( ndarrayFcn, t2, d2, 2, 1, 1 ); - f2( x, y ); // $ExpectType void | ndarray - - const t3 = [ 'float64', 'float64', 'float64' ]; - const d3 = [ binary ]; - const f3 = dispatch( ndarrayFcn, t3, d3, 3, 2, 1 ); - f3( x, y, z ); // $ExpectType void | ndarray - - const t4 = [ 'float64', 'float64', 'float64', 'float64' ]; - const d4 = [ ternary ]; - const f4 = dispatch( ndarrayFcn, t4, d4, 4, 3, 1 ); - f4( x, y, z, w ); // $ExpectType void | ndarray - - const t5 = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const d5 = [ quaternary ]; - const f5 = dispatch( ndarrayFcn, t5, d5, 5, 4, 1 ); - f5( x, y, z, w, u ); // $ExpectType void | ndarray -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (1 ndarray)... -{ - const types = [ 'float64' ]; - const data = [ nullary ]; - - const f = dispatch( ndarrayFcn, types, data, 1, 0, 1 ); - f( '10' ); // $ExpectError - f( 10 ); // $ExpectError - f( true ); // $ExpectError - f( false ); // $ExpectError - f( null ); // $ExpectError - f( undefined ); // $ExpectError - f( [ '1' ] ); // $ExpectError - f( {} ); // $ExpectError - f( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( 10, y ); // $ExpectError - f( '10', y ); // $ExpectError - f( true, y ); // $ExpectError - f( false, y ); // $ExpectError - f( null, y ); // $ExpectError - f( undefined, y ); // $ExpectError - f( [ '1' ], y ); // $ExpectError - f( {}, y ); // $ExpectError - f( ( x: number ): number => x, y ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const x = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( x, 10 ); // $ExpectError - f( x, '10' ); // $ExpectError - f( x, true ); // $ExpectError - f( x, false ); // $ExpectError - f( x, null ); // $ExpectError - f( x, undefined ); // $ExpectError - f( x, [ '1' ] ); // $ExpectError - f( x, {} ); // $ExpectError - f( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( 10, y, z ); // $ExpectError - f( '10', y, z ); // $ExpectError - f( true, y, z ); // $ExpectError - f( false, y, z ); // $ExpectError - f( null, y, z ); // $ExpectError - f( undefined, y, z ); // $ExpectError - f( [ '1' ], y, z ); // $ExpectError - f( {}, y, z ); // $ExpectError - f( ( x: number ): number => x, y, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, 10, z ); // $ExpectError - f( x, '10', z ); // $ExpectError - f( x, true, z ); // $ExpectError - f( x, false, z ); // $ExpectError - f( x, null, z ); // $ExpectError - f( x, undefined, z ); // $ExpectError - f( x, [ '1' ], z ); // $ExpectError - f( x, {}, z ); // $ExpectError - f( x, ( x: number ): number => x, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, y, '10' ); // $ExpectError - f( x, y, true ); // $ExpectError - f( x, y, false ); // $ExpectError - f( x, y, null ); // $ExpectError - f( x, y, undefined ); // $ExpectError - f( x, y, [ '1' ] ); // $ExpectError - f( x, y, {} ); // $ExpectError - f( x, y, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( 10, y, z, w ); // $ExpectError - f( '10', y, z, w ); // $ExpectError - f( true, y, z, w ); // $ExpectError - f( false, y, z, w ); // $ExpectError - f( null, y, z, w ); // $ExpectError - f( undefined, y, z, w ); // $ExpectError - f( [ '1' ], y, z, w ); // $ExpectError - f( {}, y, z, w ); // $ExpectError - f( ( x: number ): number => x, y, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, 10, z, w ); // $ExpectError - f( x, '10', z, w ); // $ExpectError - f( x, true, z, w ); // $ExpectError - f( x, false, z, w ); // $ExpectError - f( x, null, z, w ); // $ExpectError - f( x, undefined, z, w ); // $ExpectError - f( x, [ '1' ], z, w ); // $ExpectError - f( x, {}, z, w ); // $ExpectError - f( x, ( x: number ): number => x, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, 10, w ); // $ExpectError - f( x, y, '10', w ); // $ExpectError - f( x, y, true, w ); // $ExpectError - f( x, y, false, w ); // $ExpectError - f( x, y, null, w ); // $ExpectError - f( x, y, undefined, w ); // $ExpectError - f( x, y, [ '1' ], w ); // $ExpectError - f( x, y, {}, w ); // $ExpectError - f( x, y, ( x: number ): number => x, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, z, 10 ); // $ExpectError - f( x, y, z, '10' ); // $ExpectError - f( x, y, z, true ); // $ExpectError - f( x, y, z, false ); // $ExpectError - f( x, y, z, null ); // $ExpectError - f( x, y, z, undefined ); // $ExpectError - f( x, y, z, [ '1' ] ); // $ExpectError - f( x, y, z, {} ); // $ExpectError - f( x, y, z, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( 10, y, z, w, u ); // $ExpectError - f( '10', y, z, w, u ); // $ExpectError - f( true, y, z, w, u ); // $ExpectError - f( false, y, z, w, u ); // $ExpectError - f( null, y, z, w, u ); // $ExpectError - f( undefined, y, z, w, u ); // $ExpectError - f( [ '1' ], y, z, w, u ); // $ExpectError - f( {}, y, z, w, u ); // $ExpectError - f( ( x: number ): number => x, y, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, 10, z, w, u ); // $ExpectError - f( x, '10', z, w, u ); // $ExpectError - f( x, true, z, w, u ); // $ExpectError - f( x, false, z, w, u ); // $ExpectError - f( x, null, z, w, u ); // $ExpectError - f( x, undefined, z, w, u ); // $ExpectError - f( x, [ '1' ], z, w, u ); // $ExpectError - f( x, {}, z, w, u ); // $ExpectError - f( x, ( x: number ): number => x, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, 10, w, u ); // $ExpectError - f( x, y, '10', w, u ); // $ExpectError - f( x, y, true, w, u ); // $ExpectError - f( x, y, false, w, u ); // $ExpectError - f( x, y, null, w, u ); // $ExpectError - f( x, y, undefined, w, u ); // $ExpectError - f( x, y, [ '1' ], w, u ); // $ExpectError - f( x, y, {}, w, u ); // $ExpectError - f( x, y, ( x: number ): number => x, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, 10, u ); // $ExpectError - f( x, y, z, '10', u ); // $ExpectError - f( x, y, z, true, u ); // $ExpectError - f( x, y, z, false, u ); // $ExpectError - f( x, y, z, null, u ); // $ExpectError - f( x, y, z, undefined, u ); // $ExpectError - f( x, y, z, [ '1' ], u ); // $ExpectError - f( x, y, z, {}, u ); // $ExpectError - f( x, y, z, ( x: number ): number => x, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fifth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, w, 10 ); // $ExpectError - f( x, y, z, w, '10' ); // $ExpectError - f( x, y, z, w, true ); // $ExpectError - f( x, y, z, w, false ); // $ExpectError - f( x, y, z, w, null ); // $ExpectError - f( x, y, z, w, undefined ); // $ExpectError - f( x, y, z, w, [ '1' ] ); // $ExpectError - f( x, y, z, w, {} ); // $ExpectError - f( x, y, z, w, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/add.js b/examples/add.js deleted file mode 100644 index 775b711..0000000 --- a/examples/add.js +++ /dev/null @@ -1,121 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var dispatch = require( './../lib' ); - -function add2( arrays ) { - var opts; - var xo; - var yo; - var zo; - var sx; - var sy; - var sz; - var sh; - var N; - var x; - var y; - var z; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - z = arrays[ 2 ]; - xo = x.order; - yo = y.order; - zo = z.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - opts.order = yo; - sy = ind2sub( sh, i, opts ); - v = x.get.apply( x, sx ) + y.get.apply( y, sy ); - - opts.order = zo; - sz = ind2sub( sh, i, opts ); - sz.push( v ); - z.set.apply( z, sz ); - } -} - -var fcns = [ - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2 -]; - -var types = [ - dtypes.float64, dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.int32, dtypes.int32, - dtypes.uint32, dtypes.uint32, dtypes.uint32, - dtypes.int16, dtypes.int16, dtypes.int16, - dtypes.uint16, dtypes.uint16, dtypes.uint16, - dtypes.int8, dtypes.int8, dtypes.int8, - dtypes.uint8, dtypes.uint8, dtypes.uint8, - dtypes.uint8c, dtypes.uint8c, dtypes.uint8c -]; - -var add = dispatch( fcns, types, null, 3, 2, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var zbuf = new Float64Array( xbuf.length ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var z = ndarray( 'float64', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); - -xbuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -ybuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -zbuf = new Int32Array( xbuf.length ); - -x = ndarray( 'int32', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'int32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -z = ndarray( 'int32', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); diff --git a/examples/sin.js b/examples/sin.js deleted file mode 100644 index 8cd4871..0000000 --- a/examples/sin.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int8Array = require( '@stdlib/array-int8' ); -var sin = require( '@stdlib/math-base-special-sin' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/strided-dtypes' ); -var dispatch = require( './../lib' ); - -function apply( arrays, fcn ) { - var opts; - var xo; - var yo; - var sx; - var sy; - var sh; - var N; - var x; - var y; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - xo = x.order; - yo = y.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - v = fcn( x.get.apply( x, sx ) ); - - opts.order = yo; - sy = ind2sub( sh, i, opts ); - sy.push( v ); - y.set.apply( y, sy ); - } -} - -var fcns = [ - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply -]; - -var types = [ - dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float64, - dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.float64, - dtypes.uint32, dtypes.float64, - dtypes.int16, dtypes.float64, - dtypes.int16, dtypes.float32, - dtypes.uint16, dtypes.float64, - dtypes.uint16, dtypes.float32, - dtypes.int8, dtypes.float64, - dtypes.int8, dtypes.float32, - dtypes.uint8, dtypes.float64, - dtypes.uint8, dtypes.float32, - dtypes.uint8c, dtypes.float64, - dtypes.uint8c, dtypes.float32 -]; - -var data = [ - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin -]; - -var sine = dispatch( fcns, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); - -xbuf = new Int8Array( [ 1, 2, 3, 4, 5 ] ); -ybuf = new Float32Array( xbuf.length ); - -x = ndarray( 'int8', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'float32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); diff --git a/examples/unary.js b/examples/unary.js deleted file mode 100644 index e9c3fb4..0000000 --- a/examples/unary.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -var unary = require( '@stdlib/ndarray-base-unary' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var dispatch = require( './../lib' ); - -var types = [ 'float64', 'float64' ]; - -var data = [ - abs -]; - -var absolute = dispatch( unary, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -absolute( x, y ); -console.log( ybuf ); -// => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 610167d..e8f79c8 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..f48c2d5 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function m(r,e,t,i,s,n,o,l,m){var d,a,h,f;for(d=n,h=0;h [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0Mq5s', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0Mq3A', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0Mq5u', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0Mq5v', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0Mq5w', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format( '0Mq0h' ) );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format( '0Mq0i' ) );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format( '0Mq0k' ) );\n\t}\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format( '0Mq0l' ) );\n\t\t\t}\n\t\t\tthrow new Error( format( '0Mq0m' ) );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( v.dtype );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format( '0Mq0p' ) );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n"],"names":["indexOfTypes","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","i","j","dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","push","dtype","slice"],"mappings":";;uvBA6EA,SAASA,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,KAAgBE,EAAGI,GADdE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,CACN,CACD,OAAQ,CACT,CCjBA,SAASU,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,sFAAuFV,IAErH,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAQ,UAE1B,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAQ,UAE1B,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAQ,eAI1B,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAQ,UAG3B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAQ,UAE1B,OAeA,WACC,IAAIO,EACAC,EACAC,EACAC,EACAC,EACAC,EACA3B,EAGJ,IADAwB,EAAOI,UAAUR,UACHd,EAAQ,CACrB,GAAKkB,EAAOlB,EACX,MAAM,IAAIa,MAAOJ,EAAQ,UAE1B,MAAM,IAAII,MAAOJ,EAAQ,SACzB,CAGD,IAFAO,EAAS,GACTC,EAAS,GACHvB,EAAI,EAAGA,EAAIM,EAAON,IAAM,CAE7B,IAAM6B,EADNH,EAAIE,UAAW5B,IAEd,MAAKA,EAAIO,EACF,IAAIO,UAAWC,EAAQ,6EAA8EW,IAErG,IAAIZ,UAAWC,EAAQ,8EAA+EW,IAG9GJ,EAAOQ,KAAMJ,GACbH,EAAOO,KAAMJ,EAAEK,MACf,CAKD,IAHAN,EAAMrC,EAAcsB,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGc,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAIT,UAAWC,EAAQ,UAI7BY,EADIhB,GAGAR,EAAMsB,GAGNpB,EACJsB,EAAGL,EAAQjB,EAAMoB,IAEjBE,EAAGL,GAEJ,GAAc,IAATd,EACJ,OAAOc,EAAQb,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOc,EAAOU,MAAOzB,EACrB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 291641d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Create an ndarray function interface which performs multiple dispatch. -* -* @module @stdlib/ndarray-dispatch -* -* @example -* var dispatch = require( '@stdlib/ndarray-dispatch' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/index_of_types.js b/lib/index_of_types.js deleted file mode 100644 index fda2297..0000000 --- a/lib/index_of_types.js +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found). -* -* ## Notes -* -* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types). -* - The function assumes that `x` is stored in row-major order. -* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`. -* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value. -* -* @private -* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension) -* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension) -* @param {ArrayLikeObject} x - input two-dimensional reference array -* @param {integer} strideX1 - `x` stride length along first dimension -* @param {integer} strideX2 - `x` stride length along second dimension -* @param {NonNegativeInteger} offsetX - `x` starting index -* @param {ArrayLikeObject} y - search array -* @param {integer} strideY - `y` stride length -* @param {NonNegativeInteger} offsetY - `y` starting index -* @returns {integer} row index (if found) and `-1` otherwise -* -* @example -* // Define a reference array to search: -* var types = [ -* 'float64', 'float64', 'float64', -* 'float32', 'float32', 'float32', -* 'uint32', 'uint32', 'float64', -* 'int32', 'int32', 'float64', -* 'uint16', 'uint16', 'float64', -* 'int16', 'int16', 'float64', -* 'uint8', 'uint8', 'float64', -* 'int8', 'int8', 'float64' -* ]; -* -* // Define reference array dimensions: -* var N = 8; // rows -* var M = 3; // columns -* -* // Define a search array: -* y1 = [ -* 'float32', 'float32', 'float32', -* ]; -* -* // Find the list of types: -* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 ); -* // returns 1 -* -// Define a search array: -* y2 = [ -* 'float32', 'float32', 'float64', -* ]; -* -* // Find the list of types: -* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 ); -* // returns -1 -*/ -function indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len - var ix; - var iy; - var i; - var j; - - // Search for the first row which matches `y`... - ix = offsetX; - for ( i = 0; i < N; i++ ) { - iy = offsetY; - for ( j = 0; j < M; j++ ) { - if ( x[ ix+(j*strideX2) ] !== y[ iy ] ) { - break; - } - iy += strideY; - } - // If we successfully iterated over all columns, then that means we've found a match... - if ( j === M ) { - return i; - } - ix += strideX1; - } - return -1; -} - - -// EXPORTS // - -module.exports = indexOfTypes; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c8218ef..0000000 --- a/lib/main.js +++ /dev/null @@ -1,207 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isFunctionArray = require( '@stdlib/assert-is-function-array' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var indexOfTypes = require( './index_of_types.js' ); - - -// MAIN // - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param {(FunctionArray|Function)} fcns - list of ndarray functions -* @param {Collection} types - one-dimensional list of ndarray argument data types -* @param {(Collection|null)} data - ndarray function data (e.g., callbacks) -* @param {PositiveInteger} nargs - total number of ndarray function interface arguments -* @param {NonNegativeInteger} nin - number of input ndarrays -* @param {NonNegativeInteger} nout - number of output ndarrays -* @throws {TypeError} first argument must be either a function or an array of functions -* @throws {TypeError} second argument must be an array-like object -* @throws {TypeError} third argument must be an array-like object or `null` -* @throws {Error} third and first arguments must have the same number of elements -* @throws {TypeError} fourth argument must be a positive integer -* @throws {TypeError} fifth argument must be a nonnegative integer -* @throws {TypeError} sixth argument must be a nonnegative integer -* @throws {Error} fourth argument must equal the specified number of input and output arrays -* @throws {Error} number of types must match the number of functions times the total number of array arguments for each function -* @throws {Error} interface must accept at least one input and/or output ndarray -* @returns {Function} ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function dispatch( fcns, types, data, nargs, nin, nout ) { - var narrays; - var nfcns; - var fcn; - - if ( isFunction( fcns ) ) { - fcn = fcns; - } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( '0Mq5s', fcns ) ); - } - if ( !isCollection( types ) ) { - throw new TypeError( format( '0Mq3A', types ) ); - } - if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); - } - if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( '0Mq5u', nargs ) ); - } - if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( '0Mq5v', nin ) ); - } - if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( '0Mq5w', nout ) ); - } - narrays = nin + nout; - if ( narrays === 0 ) { - throw new Error( format( '0Mq0h' ) ); - } - if ( nargs !== narrays ) { - throw new Error( format( '0Mq0i' ) ); - } - if ( fcn ) { - nfcns = types.length / narrays; - if ( !isInteger( nfcns ) ) { - throw new Error( format( '0Mq0j' ) ); - } - } else { - nfcns = fcns.length; - if ( types.length !== nfcns*narrays ) { - throw new Error( format( '0Mq0j' ) ); - } - } - if ( data && data.length !== nfcns ) { - throw new Error( format( '0Mq0k' ) ); - } - return dispatcher; - - /** - * ndarray function interface which performs multiple dispatch. - * - * @private - * @param {ndarrayLike} x - ndarray - * @param {...ndarrayLike} args - ndarray arguments - * @throws {Error} insufficient arguments - * @throws {Error} too many arguments - * @throws {TypeError} input array arguments must be ndarray-like objects - * @throws {TypeError} output array arguments must be ndarray-like objects - * @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types - * @returns {(ndarrayLike|Array|void)} destination array(s) - */ - function dispatcher() { - var arrays; - var dtypes; - var argc; - var idx; - var v; - var f; - var i; - - argc = arguments.length; - if ( argc !== nargs ) { - if ( argc < nargs ) { - throw new Error( format( '0Mq0l' ) ); - } - throw new Error( format( '0Mq0m' ) ); - } - arrays = []; - dtypes = []; - for ( i = 0; i < nargs; i++ ) { - v = arguments[ i ]; - if ( !isndarrayLike( v ) ) { - if ( i < nin ) { - throw new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) ); - } else { - throw new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) ); - } - } - arrays.push( v ); - dtypes.push( v.dtype ); - } - // Resolve the ndarray function satisfying the input array types: - idx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len - - // Check whether we were able to successfully resolve an ndarray function: - if ( idx < 0 ) { - throw new TypeError( format( '0Mq0p' ) ); - } - // Retrieve the ndarray function: - if ( fcn ) { - f = fcn; - } else { - f = fcns[ idx ]; - } - // Evaluate the ndarray function: - if ( data ) { - f( arrays, data[ idx ] ); - } else { - f( arrays ); - } - if ( nout === 1 ) { - return arrays[ narrays-1 ]; - } - if ( nout === 0 ) { - return; - } - return arrays.slice( nin ); - } -} - - -// EXPORTS // - -module.exports = dispatch; diff --git a/package.json b/package.json index 9569eb2..aab393c 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Create an ndarray function interface which performs multiple dispatch.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@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-ndarray-like": "^0.0.x", - "@stdlib/assert-is-nonnegative-integer": "^0.0.x", - "@stdlib/assert-is-positive-integer": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/array-int32": "^0.0.x", - "@stdlib/array-int8": "^0.0.x", - "@stdlib/array-uint8": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/math-base-assert-is-nan": "^0.0.x", - "@stdlib/math-base-special-abs": "^0.0.x", - "@stdlib/math-base-special-pow": "^0.0.x", - "@stdlib/math-base-special-sin": "^0.0.x", - "@stdlib/ndarray-base-buffer-dtype": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/ndarray-base-unary": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/ndarray-dtypes": "^0.0.x", - "@stdlib/ndarray-ind2sub": "^0.0.x", - "@stdlib/strided-dtypes": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "ndarray", @@ -97,7 +26,6 @@ "multimethod", "multimethods" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e73ce4d --- /dev/null +++ b/stats.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/fixtures/binary.js b/test/fixtures/binary.js deleted file mode 100644 index a60dfa2..0000000 --- a/test/fixtures/binary.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Binary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @returns {number} sum -*/ -function binary( x, y ) { - return x + y; -} - - -// EXPORTS // - -module.exports = binary; diff --git a/test/fixtures/fill.js b/test/fixtures/fill.js deleted file mode 100644 index 41b2958..0000000 --- a/test/fixtures/fill.js +++ /dev/null @@ -1,76 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which fills one or more ndarrays. -* -* @private -* @param {*} value - fill value -* @returns {Function} ndarray function -*/ -function fill( value ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - */ - function ndarrayFcn( arrays ) { - var opts; - var sub; - var arr; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - opts = { - 'order': '' - }; - for ( j = 0; j < M; j++ ) { - arr = arrays[ j ]; - opts.order = arrays[ j ].order; - for ( i = 0; i < N; i++ ) { - sub = ind2sub( sh, i, opts ); - sub.push( value ); - arr.set.apply( arr, sub ); - } - } - } -} - - -// EXPORTS // - -module.exports = fill; diff --git a/test/fixtures/foreach.js b/test/fixtures/foreach.js deleted file mode 100644 index a426290..0000000 --- a/test/fixtures/foreach.js +++ /dev/null @@ -1,72 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function forEach( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - fcn.apply( null, args ); - } -} - - -// EXPORTS // - -module.exports = forEach; diff --git a/test/fixtures/map1n.js b/test/fixtures/map1n.js deleted file mode 100644 index 614196b..0000000 --- a/test/fixtures/map1n.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function which maps the return value of a callback to `N` arrays. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function map1N( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var v; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - v = fcn(); - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - sub.push( v ); - arrays[ j ].set.apply( arrays[ j ], sub ); - } - } -} - - -// EXPORTS // - -module.exports = map1N; diff --git a/test/fixtures/nullary.js b/test/fixtures/nullary.js deleted file mode 100644 index 4f22126..0000000 --- a/test/fixtures/nullary.js +++ /dev/null @@ -1,36 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Nullary callback. -* -* @private -* @returns {number} value -*/ -function nullary() { - return 3.0; -} - - -// EXPORTS // - -module.exports = nullary; diff --git a/test/fixtures/quaternary.js b/test/fixtures/quaternary.js deleted file mode 100644 index 548437b..0000000 --- a/test/fixtures/quaternary.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quaternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @returns {number} sum -*/ -function quaternary( x, y, z, w ) { - return x + y + z + w; -} - - -// EXPORTS // - -module.exports = quaternary; diff --git a/test/fixtures/quinary.js b/test/fixtures/quinary.js deleted file mode 100644 index 36068de..0000000 --- a/test/fixtures/quinary.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quinary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @param {number} u - input value -* @returns {number} sum -*/ -function quinary( x, y, z, w, u ) { - return x + y + z + w + u; -} - - -// EXPORTS // - -module.exports = quinary; diff --git a/test/fixtures/sum.js b/test/fixtures/sum.js deleted file mode 100644 index efdbb1b..0000000 --- a/test/fixtures/sum.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which computes the sum across one or more ndarrays. -* -* @private -* @param {Object} ctx - context -* @param {number} ctx.sum - initial sum -* @returns {Function} ndarray function -*/ -function wrapper( ctx ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - * @param {Function} [fcn] - callback - */ - function ndarrayFcn( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var f; - var i; - var j; - - if ( arguments.length > 1 ) { - f = fcn; - } - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - if ( f ) { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - ctx.sum += f.apply( null, args ); - } - } else { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - ctx.sum += arrays[ j ].get.apply( arrays[ j ], sub ); - } - } - } - } -} - - -// EXPORTS // - -module.exports = wrapper; diff --git a/test/fixtures/ternary.js b/test/fixtures/ternary.js deleted file mode 100644 index 0595d5f..0000000 --- a/test/fixtures/ternary.js +++ /dev/null @@ -1,39 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Ternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @returns {number} sum -*/ -function ternary( x, y, z ) { - return x + y + z; -} - - -// EXPORTS // - -module.exports = ternary; diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d6c2c8e..0000000 --- a/test/test.js +++ /dev/null @@ -1,363 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var fill = require( './fixtures/fill.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either a function or an array of functions as a first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( value, types, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object as a second argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided either an array-like object or `null` as a third argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - dispatch( unary, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a positive integer for a fourth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 0, - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a fifth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, value, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a sixth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, 1, value ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function array)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var fcns = [ unary, unary, unary ]; - var data = [ abs, abs, abs ]; - dispatch( fcns, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function argument)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs, abs, abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the length of `data` argument does not match the number of ndarray functions', function test( t ) { - var values; - var i; - - values = [ - [], - [ abs, abs ], - [ abs, abs, abs ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var fcns = [ unary ]; - dispatch( fcns, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the fourth argument is incompatible with the number of input and output ndarrays', function test( t ) { - var values; - var i; - - values = [ - 0, - 1, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of specified input and output ndarrays is zero', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var types = [ 'float64' ]; - dispatch( fill( 3 ), types, null, 1, 0, 0 ); - } -}); - -tape( 'the function returns an ndarray function interface', function test( t ) { - var types; - var data; - var f; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - f = dispatch( unary, types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ unary ], types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( fill( 3 ), types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ fill( 3 ) ], types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.two_arrays.js b/test/test.two_arrays.js deleted file mode 100644 index 071500e..0000000 --- a/test/test.two_arrays.js +++ /dev/null @@ -1,808 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var dtype = require( '@stdlib/ndarray-base-buffer-dtype' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var forEach = require( './fixtures/foreach.js' ); -var map1N = require( './fixtures/map1n.js' ); -var fill = require( './fixtures/fill.js' ); -var sum = require( './fixtures/sum.js' ); - - -// TESTS // - -tape( 'the function returns a function which throws an error if not provided an ndarray for the first argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var ybuf = new Float64Array( 10 ); - var y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( value, y ); - }; - } -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the second argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var xbuf = new Float64Array( 10 ); - var x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( x, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided insufficient arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var f; - var x; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [], - [ x ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided too many arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var ybuf; - var f; - var x; - var y; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [ x, y, y ], - [ x, y, y, y ], - [ x, y, y, y, y ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if unable to resolve a ndarray function supporting the provided array argument data types', function test( t ) { - var values; - var types; - var data; - var xbuf; - var fcn; - var x; - var i; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ abs, abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 4 ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - values = [ - new Uint8Array( 4 ), - new Int32Array( 4 ), - [ 0, 0, 0, 0 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided an array having data type: ' + dtype( values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var y = ndarray( dtype( value ), value, [ value.length ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - }; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only input arrays)', function test( t ) { - var types; - var xbuf; - var ybuf; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only output arrays)', function test( t ) { - var expected; - var types; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only input arrays)', function test( t ) { - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var ctx; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcns = [ - sum( ctx ), - sum( ctx ) - ]; - fcn = dispatch( fcns, types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only output arrays)', function test( t ) { - var expected; - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcns = [ - fill( 3.0 ), - fill( 4.0 ) - ]; - fcn = dispatch( fcns, types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - - fcn = dispatch( forEach, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - - fcn = dispatch( map1N, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - fcns = [ - forEach, - forEach - ]; - fcn = dispatch( fcns, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - fcns = [ - map1N, - map1N - ]; - fcn = dispatch( fcns, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - fcns = [ - unary, - unary - ]; - fcn = dispatch( fcns, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which returns one or more output arrays, if one or more output arrays is specified, and otherwise returns `undefined`', function test( t ) { - var types; - var data; - var xbuf; - var ybuf; - var out; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - // No output arrays... - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, void 0, 'returns expected value' ); - - // One output array... - data = [ - abs, - abs - ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - fcn = dispatch( fill( 3.0 ), types, null, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - // Two output arrays... - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.end(); -}); From 71a3cf06bbf5254b5cf1b9148cb79855b65e6247 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 02:31:18 +0000 Subject: [PATCH 026/109] Transform error messages --- lib/main.js | 28 ++++++++++++++-------------- package.json | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/main.js b/lib/main.js index 3d28781..c8218ef 100644 --- a/lib/main.js +++ b/lib/main.js @@ -27,7 +27,7 @@ var isFunctionArray = require( '@stdlib/assert-is-function-array' ); var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var indexOfTypes = require( './index_of_types.js' ); @@ -89,43 +89,43 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { if ( isFunction( fcns ) ) { fcn = fcns; } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) ); + throw new TypeError( format( '0Mq5s', fcns ) ); } if ( !isCollection( types ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) ); + throw new TypeError( format( '0Mq3A', types ) ); } if ( !isCollection( data ) && data !== null ) { throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); } if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) ); + throw new TypeError( format( '0Mq5u', nargs ) ); } if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) ); + throw new TypeError( format( '0Mq5v', nin ) ); } if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) ); + throw new TypeError( format( '0Mq5w', nout ) ); } narrays = nin + nout; if ( narrays === 0 ) { - throw new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' ); + throw new Error( format( '0Mq0h' ) ); } if ( nargs !== narrays ) { - throw new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' ); + throw new Error( format( '0Mq0i' ) ); } if ( fcn ) { nfcns = types.length / narrays; if ( !isInteger( nfcns ) ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format( '0Mq0j' ) ); } } else { nfcns = fcns.length; if ( types.length !== nfcns*narrays ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format( '0Mq0j' ) ); } } if ( data && data.length !== nfcns ) { - throw new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' ); + throw new Error( format( '0Mq0k' ) ); } return dispatcher; @@ -154,9 +154,9 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { argc = arguments.length; if ( argc !== nargs ) { if ( argc < nargs ) { - throw new Error( 'invalid invocation. Insufficient arguments.' ); + throw new Error( format( '0Mq0l' ) ); } - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format( '0Mq0m' ) ); } arrays = []; dtypes = []; @@ -177,7 +177,7 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { // Check whether we were able to successfully resolve an ndarray function: if ( idx < 0 ) { - throw new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' ); + throw new TypeError( format( '0Mq0p' ) ); } // Retrieve the ndarray function: if ( fcn ) { diff --git a/package.json b/package.json index bc090e7..63ab6bc 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "@stdlib/assert-is-ndarray-like": "^0.0.x", "@stdlib/assert-is-nonnegative-integer": "^0.0.x", "@stdlib/assert-is-positive-integer": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From 57eb442c54b9623a20a73075ae28ae09a2eca9d3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 15:23:31 +0000 Subject: [PATCH 027/109] Remove files --- index.d.ts | 334 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4383 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index e8f79c8..0000000 --- a/index.d.ts +++ /dev/null @@ -1,334 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* ndarray function. -* -* @param arrays - array containing input and output ndarrays -* @param data - ndarray function data (e.g., a callback) -* -* @example -* var numel = require( `@stdlib/ndarray/base/numel` ); -* var ind2sub = require( `@stdlib/ndarray/ind2sub` ); -* -* function ndarrayFcn( arrays, fcn ) { -* var xord; -* var yord; -* var opts; -* var sub; -* var sh; -* var N; -* var x; -* var y; -* var v; -* var i; -* -* x = arrays[ 0 ]; -* y = arrays[ 1 ]; -* sh = x.shape; -* N = numel( sh ); -* if ( N <= 0 ) { -* return; -* } -* xord = x.order; -* yord = y.order; -* opts = {}; -* opts.order = xord; -* for ( i = 0; i < N; i++ ) { -* // Convert a linear index to subscripts: -* opts.order = xord; -* sub = ind2sub( sh, i, opts ); -* -* // Retrieve an element from `x`: -* v = x.get.apply( x, sub ); -* -* // Convert a linear index to subscripts: -* opts.order = yord; -* sub = ind2sub( sh, i, opts ); -* -* // Append the result of applying the callback: -* sub.push( fcn( v ) ); -* -* // Assign the result to an element in `y`: -* y.set.apply( y, sub ); -* } -* } -*/ -type ndarrayFcn = ( arrays: Array, data?: any ) => void; - -/** -* Interface describing an ndarray function dispatcher. -*/ -interface Dispatcher { - /** - * Invokes an ndarray function based on the provided array data type(s). - * - * @param x - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array - * - * @example - * var nullary = require( `@stdlib/ndarray/base/nullary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function value() { - * return 3.14; - * } - * - * var types = [ 'float64' ]; - * var data = [ value ]; - * - * var fcn = dispatch( nullary, types, data, 1, 0, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( 5 ); - * var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x ); - * // xbuf => [ 3.14, 3.14, 3.14, 3.14, 3.14 ] - */ - ( x: ndarray ): ndarray | void; - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var unary = require( `@stdlib/ndarray/base/unary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * var abs = require( `@stdlib/math/base/special/abs` ); - * - * var types = [ 'float64', 'float64' ]; - * var data = [ abs ]; - * - * var fcn = dispatch( unary, types, data, 2, 1, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - * var ybuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y ); - * // ybuf => [ 1.0, 2.0, 3.0 ] - */ - ( x: ndarray, y: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var ternary = require( `@stdlib/ndarray/base/ternary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add2( x, y ) { - * return x + y; - * } - * - * var types = [ 'float64', 'float64', 'float64' ]; - * var data = [ add2 ]; - * - * var fcn = dispatch( ternary, types, data, 3, 2, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z ); - * // zbuf => [ 2.0, 4.0, 6.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quaternary = require( `@stdlib/ndarray/base/quaternary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add3( x, y, z ) { - * return x + y + z; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add3 ]; - * - * var fcn = dispatch( quaternary, types, data, 4, 3, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w ); - * // wbuf => [ 3.0, 6.0, 9.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @param args - ndarray arguments - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quinary = require( `@stdlib/ndarray/base/quinary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add4( x, y, z, w ) { - * return x + y + z + w; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add4 ]; - * - * var fcn = dispatch( quinary, types, data, 5, 4, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ubuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var u = ndarray( 'float64', ubuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w, u ); - * // ubuf => [ 4.0, 8.0, 12.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray, ...args: Array ): ndarray | void; // tslint:disable-line:max-line-length unified-signatures -} - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param fcns - list of ndarray functions -* @param types - one-dimensional list of ndarray argument data types -* @param data - ndarray function data (e.g., callbacks) -* @param nargs - total number of ndarray function interface arguments -* @param nin - number of input ndarrays -* @param nout - number of output ndarrays -* @throws first argument must be either a function or an array of functions -* @throws second argument must be an array-like object -* @throws third argument must be an array-like object or `null` -* @throws third and first arguments must have the same number of elements -* @throws fourth argument must be a positive integer -* @throws fifth argument must be a nonnegative integer -* @throws sixth argument must be a nonnegative integer -* @throws fourth argument must equal the specified number of input and output arrays -* @throws number of types must match the number of functions times the total number of array arguments for each function -* @throws interface must accept at least one input and/or output ndarray -* @returns ndarray function interface -* -* @example -* var unary = require( `@stdlib/ndarray/base/unary` ); -* var abs = require( `@stdlib/math/base/special/abs` ); -* var Float64Array = require( `@stdlib/array/float64` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var fcn = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* fcn( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function dispatch( fcns: ndarrayFcn | ArrayLike, types: ArrayLike, data: ArrayLike | null, nargs: number, nin: number, nout: number ): Dispatcher; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = dispatch; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index f48c2d5..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function m(r,e,t,i,s,n,o,l,m){var d,a,h,f;for(d=n,h=0;h [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0Mq5s', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0Mq3A', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0Mq5u', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0Mq5v', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0Mq5w', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format( '0Mq0h' ) );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format( '0Mq0i' ) );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format( '0Mq0k' ) );\n\t}\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format( '0Mq0l' ) );\n\t\t\t}\n\t\t\tthrow new Error( format( '0Mq0m' ) );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( v.dtype );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format( '0Mq0p' ) );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n"],"names":["indexOfTypes","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","i","j","dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","push","dtype","slice"],"mappings":";;uvBA6EA,SAASA,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,KAAgBE,EAAGI,GADdE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,CACN,CACD,OAAQ,CACT,CCjBA,SAASU,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,sFAAuFV,IAErH,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAQ,UAE1B,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAQ,UAE1B,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAQ,eAI1B,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAQ,UAG3B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAQ,UAE1B,OAeA,WACC,IAAIO,EACAC,EACAC,EACAC,EACAC,EACAC,EACA3B,EAGJ,IADAwB,EAAOI,UAAUR,UACHd,EAAQ,CACrB,GAAKkB,EAAOlB,EACX,MAAM,IAAIa,MAAOJ,EAAQ,UAE1B,MAAM,IAAII,MAAOJ,EAAQ,SACzB,CAGD,IAFAO,EAAS,GACTC,EAAS,GACHvB,EAAI,EAAGA,EAAIM,EAAON,IAAM,CAE7B,IAAM6B,EADNH,EAAIE,UAAW5B,IAEd,MAAKA,EAAIO,EACF,IAAIO,UAAWC,EAAQ,6EAA8EW,IAErG,IAAIZ,UAAWC,EAAQ,8EAA+EW,IAG9GJ,EAAOQ,KAAMJ,GACbH,EAAOO,KAAMJ,EAAEK,MACf,CAKD,IAHAN,EAAMrC,EAAcsB,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGc,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAIT,UAAWC,EAAQ,UAI7BY,EADIhB,GAGAR,EAAMsB,GAGNpB,EACJsB,EAAGL,EAAQjB,EAAMoB,IAEjBE,EAAGL,GAEJ,GAAc,IAATd,EACJ,OAAOc,EAAQb,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOc,EAAOU,MAAOzB,EACrB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e73ce4d..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From a0d03c6401e8803efba89c9407c3eb040042a3ef Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 15:24:28 +0000 Subject: [PATCH 028/109] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 781 ---- .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 183 - .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 59 +- benchmark/benchmark.dispatch_size.js | 156 - benchmark/benchmark.js | 81 - branches.md | 53 - docs/repl.txt | 87 - docs/types/test.ts | 641 ---- examples/add.js | 121 - examples/sin.js | 142 - examples/unary.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/index_of_types.js | 106 - lib/main.js | 207 -- package.json | 76 +- stats.html | 4044 +++++++++++++++++++++ test/fixtures/binary.js | 38 - test/fixtures/fill.js | 76 - test/fixtures/foreach.js | 72 - test/fixtures/map1n.js | 74 - test/fixtures/nullary.js | 36 - test/fixtures/quaternary.js | 40 - test/fixtures/quinary.js | 41 - test/fixtures/sum.js | 98 - test/fixtures/ternary.js | 39 - test/test.js | 363 -- test/test.two_arrays.js | 808 ---- 51 files changed, 4078 insertions(+), 6422 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.dispatch_size.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/add.js delete mode 100644 examples/sin.js delete mode 100644 examples/unary.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/index_of_types.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/fixtures/binary.js delete mode 100644 test/fixtures/fill.js delete mode 100644 test/fixtures/foreach.js delete mode 100644 test/fixtures/map1n.js delete mode 100644 test/fixtures/nullary.js delete mode 100644 test/fixtures/quaternary.js delete mode 100644 test/fixtures/quinary.js delete mode 100644 test/fixtures/sum.js delete mode 100644 test/fixtures/ternary.js delete mode 100644 test/test.js delete mode 100644 test/test.two_arrays.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 2117825..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-12-01T02:30:47.461Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ac0b7cd..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 920b304..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 34e41d6..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '43 7 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 37ddb4f..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,781 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -291,7 +284,7 @@ console.log( ybuf ); ## 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. +This package is part of [stdlib][stdlib], a standard library 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]. @@ -353,11 +346,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm diff --git a/benchmark/benchmark.dispatch_size.js b/benchmark/benchmark.dispatch_size.js deleted file mode 100644 index 3bd0418..0000000 --- a/benchmark/benchmark.dispatch_size.js +++ /dev/null @@ -1,156 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib/main.js' ); - - -// FUNCTIONS // - -/** -* Evaluates the identity function. -* -* @private -* @param {*} v - value -* @returns {*} input value -*/ -function identity( v ) { - return v; -} - -/** -* Dummy function which throws an error. -* -* @private -* @throws {Error} unexpected error -*/ -function throwError() { - throw new Error( 'unexpected error' ); -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} size - dispatch size -* @returns {Function} benchmark function -*/ -function createBenchmark( size ) { - var types; - var data; - var fcn; - var x; - var y; - var t; - var i; - - types = []; - - // Create dummy types... - for ( i = 0; i < (size-1)*2; i += 2 ) { - t = 'foo' + i; - types.push( t ); - types.push( t ); - } - // Append test types: - types.push( 'float64' ); - types.push( 'float64' ); - - // Define a list of callbacks: - data = []; - for ( i = 0; i < size-1; i++ ) { - data.push( throwError ); - } - // Append a test callback: - data.push( identity ); - - // Create the dispatcher: - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - // Create sample arrays: - x = new Float64Array( 1 ); - y = new Float64Array( x.length ); - - x = ndarray( 'float64', x, [ 1 ], [ 1 ], 0, 'row-major' ); - y = ndarray( 'float64', y, [ 1 ], [ 1 ], 0, 'row-major' ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var z; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x.data[ 0 ] = i; - z = fcn( x, y ); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var size; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - size = pow( 2, i ); - f = createBenchmark( size ); - bench( pkg+':size='+size, f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index a70dc5c..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::fcns_array', function benchmark( b ) { - var types; - var fcns; - var data; - var out; - var i; - - fcns = [ unary ]; - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( fcns, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::fcn_arg', function benchmark( b ) { - var types; - var data; - var out; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( unary, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index d04d051..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch" -click B href "https://github.com/stdlib-js/ndarray-dispatch/tree/main" -click C href "https://github.com/stdlib-js/ndarray-dispatch/tree/production" -click D href "https://github.com/stdlib-js/ndarray-dispatch/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-dispatch/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-dispatch/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch -[production-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 02fe150..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,87 +0,0 @@ - -{{alias}}( fcns, types, data, nargs, nin, nout ) - Returns an ndarray function interface which performs multiple dispatch. - - An ndarray function interface has the following signature: - - f( x, y, ... ) - - where - - - x: ndarray. - - y: ndarray. - - ...: additional ndarrays. - - The number of parameters is derived from `nargs`, the number of input - ndarrays is derived from `nin`, and the number of output ndarrays is derived - from `nout`. - - Parameters - ---------- - fcns: Function|ArrayLikeObject - List of ndarray functions. An ndarray function should have the following - signature: - - f( arrays, data ) - - where - - - arrays: array containing input and output ndarrays. - - data: ndarray function data (e.g., a callback). - - For convenience, a single ndarray function may be provided which will be - invoked whenever the ndarray argument data types match a sequence of - types in `types`. Providing a single ndarray function is particularly - convenient for the case where, regardless of array data types, - traversing arrays remains the same, but the ndarray function `data` - differs (e.g., callbacks which differ based on the array data types). - - types: ArrayLikeObject - One-dimensional list of ndarray argument data types. - - data: ArrayLikeObject|null - ndarray function data (e.g., callbacks). If `null`, a returned ndarray - function interface does **not** provide a `data` argument to an invoked - ndarray function. - - nargs: integer - Total number of ndarray function interface arguments. - - nin: integer - Number of input ndarrays. - - nout: integer - Number of output ndarrays. - - Returns - ------- - fcn: Function - ndarray function interface. - - Examples - -------- - // Define ndarray argument data types: - > var t = [ 'float64', 'float64', 'float32', 'float32' ]; - - // Define a list of ndarray function data (callbacks): - > var d = [ {{alias:@stdlib/math/base/special/abs}}, {{alias:@stdlib/math/base/special/absf}} ]; - - // Create an ndarray function interface for applying unary callbacks: - > var f = {{alias}}( {{alias:@stdlib/ndarray/base/unary}}, t, d, 2, 1, 1 ); - - // Create an input ndarray: - > var xbuf = new {{alias:@stdlib/array/float64}}( [ -1.0, -2.0, -3.0, -4.0 ] ); - > var x = {{alias:@stdlib/ndarray/ctor}}( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Create an output ndarray: - > var ybuf = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 0.0, 0.0 ] ); - > var y = {{alias:@stdlib/ndarray/ctor}}( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Compute the element-wise absolute value: - > f( x, y ); - > ybuf - [ 1.0, 2.0, 3.0, 4.0 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 397185e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,641 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// tslint:disable:max-file-line-count - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import dispatch = require( './index' ); - - -// FUNCTIONS // - -/** -* Nullary callback. -* -* @return input value -*/ -function nullary(): any { - return 5.0; -} - -/** -* Unary callback. -* -* @param x - input value -* @return input value -*/ -function unary( x: any ): any { - return x; -} - -/** -* Binary callback. -* -* @param x - input value -* @param y - input value -* @return output value -*/ -function binary( x: number, y: number ): number { - return x + y; -} - -/** -* Ternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @return output value -*/ -function ternary( x: number, y: number, z: number ): number { - return x + y + z; -} - -/** -* Quaternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @param w - input value -* @return output value -*/ -function quaternary( x: number, y: number, z: number, w: number ): number { - return x + y + z + w; -} - -/** -* Mock `ind2sub` function. -* -* @param shape - dimensions -* @param idx - linear index -* @param opts - options -* @return subscripts -*/ -function ind2sub( shape: ArrayLike, idx: number, opts?: any ): Array { // tslint:disable-line:max-line-length - let out; - let i; - - out = []; - if ( typeof opts === 'object' && opts !== null && opts.order === 'row-major' ) { // tslint:disable-line:max-line-length no-unsafe-any - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } else { - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } - return out; -} - -/** -* Mock ndarray function. -* -* @param arrays - ndarrays -* @param fcn - callback -*/ -function ndarrayFcn( arrays: Array, fcn: ( x: any ) => any ): void { - let xord; - let yord; - let opts; - let sub; - let sh; - let N; - let x; - let y; - let v; - let i; - - x = arrays[ 0 ]; - y = arrays[ 1 ]; - sh = x.shape; - if ( sh.length === 0 ) { - return; - } - N = 1; - for ( i = 0; i < sh.length; i += 1 ) { - N *= sh[ i ]; - } - xord = x.order; - yord = y.order; - opts = { - 'order': '' - }; - opts.order = xord; - for ( i = 0; i < N; i += 1 ) { - // Convert a linear index to subscripts: - opts.order = xord; - sub = ind2sub( sh, i, opts ); - - // Retrieve an element from `x`: - v = x.get.apply( x, sub ); - - // Convert a linear index to subscripts: - opts.order = yord; - sub = ind2sub( sh, i, opts ); - - // Append the result of applying the callback: - sub[ sub.length ] = fcn( v ) as number; - - // Assign the result to an element in `y`: - y.set.apply( y, sub ); - } -} - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a dispatch function... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, 1 ); // $ExpectType Dispatcher - dispatch( [ ndarrayFcn ], types, data, 2, 1, 1 ); // $ExpectType Dispatcher -} - -// The compiler throws an error if the function is provided a first argument which is not either an ndarray function or an array-like object containing ndarray functions... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( '10', types, data, 2, 1, 1 ); // $ExpectError - dispatch( 10, types, data, 2, 1, 1 ); // $ExpectError - dispatch( true, types, data, 2, 1, 1 ); // $ExpectError - dispatch( false, types, data, 2, 1, 1 ); // $ExpectError - dispatch( null, types, data, 2, 1, 1 ); // $ExpectError - dispatch( undefined, types, data, 2, 1, 1 ); // $ExpectError - dispatch( [ '1' ], types, data, 2, 1, 1 ); // $ExpectError - dispatch( {}, types, data, 2, 1, 1 ); // $ExpectError - dispatch( ( x: number ): number => x, types, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object... -{ - const data = [ unary ]; - - dispatch( ndarrayFcn, 10, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, true, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, false, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, null, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, undefined, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, {}, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object or null... -{ - const types = [ 'float64', 'float64' ]; - - dispatch( ndarrayFcn, types, 10, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, true, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, false, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, undefined, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, {}, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, '10', 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, true, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, false, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, null, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, undefined, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, [ '1' ], 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, {}, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, ( x: number ): number => x, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, '10', 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, true, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, false, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, null, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, undefined, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, [ '1' ], 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, {}, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, ( x: number ): number => x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, '10' ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, true ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, false ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, null ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, undefined ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, [ '1' ] ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, {} ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch(); // $ExpectError - dispatch( ndarrayFcn ); // $ExpectError - dispatch( ndarrayFcn, types ); // $ExpectError - dispatch( ndarrayFcn, types, data ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, 1, 0 ); // $ExpectError -} - -// The function returns a dispatch function... -{ - const x = array(); - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const t1 = [ 'float64' ]; - const d1 = [ nullary ]; - const f1 = dispatch( ndarrayFcn, t1, d1, 1, 1, 0 ); - f1( x ); // $ExpectType void | ndarray - - const t2 = [ 'float64', 'float64' ]; - const d2 = [ unary ]; - const f2 = dispatch( ndarrayFcn, t2, d2, 2, 1, 1 ); - f2( x, y ); // $ExpectType void | ndarray - - const t3 = [ 'float64', 'float64', 'float64' ]; - const d3 = [ binary ]; - const f3 = dispatch( ndarrayFcn, t3, d3, 3, 2, 1 ); - f3( x, y, z ); // $ExpectType void | ndarray - - const t4 = [ 'float64', 'float64', 'float64', 'float64' ]; - const d4 = [ ternary ]; - const f4 = dispatch( ndarrayFcn, t4, d4, 4, 3, 1 ); - f4( x, y, z, w ); // $ExpectType void | ndarray - - const t5 = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const d5 = [ quaternary ]; - const f5 = dispatch( ndarrayFcn, t5, d5, 5, 4, 1 ); - f5( x, y, z, w, u ); // $ExpectType void | ndarray -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (1 ndarray)... -{ - const types = [ 'float64' ]; - const data = [ nullary ]; - - const f = dispatch( ndarrayFcn, types, data, 1, 0, 1 ); - f( '10' ); // $ExpectError - f( 10 ); // $ExpectError - f( true ); // $ExpectError - f( false ); // $ExpectError - f( null ); // $ExpectError - f( undefined ); // $ExpectError - f( [ '1' ] ); // $ExpectError - f( {} ); // $ExpectError - f( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( 10, y ); // $ExpectError - f( '10', y ); // $ExpectError - f( true, y ); // $ExpectError - f( false, y ); // $ExpectError - f( null, y ); // $ExpectError - f( undefined, y ); // $ExpectError - f( [ '1' ], y ); // $ExpectError - f( {}, y ); // $ExpectError - f( ( x: number ): number => x, y ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const x = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( x, 10 ); // $ExpectError - f( x, '10' ); // $ExpectError - f( x, true ); // $ExpectError - f( x, false ); // $ExpectError - f( x, null ); // $ExpectError - f( x, undefined ); // $ExpectError - f( x, [ '1' ] ); // $ExpectError - f( x, {} ); // $ExpectError - f( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( 10, y, z ); // $ExpectError - f( '10', y, z ); // $ExpectError - f( true, y, z ); // $ExpectError - f( false, y, z ); // $ExpectError - f( null, y, z ); // $ExpectError - f( undefined, y, z ); // $ExpectError - f( [ '1' ], y, z ); // $ExpectError - f( {}, y, z ); // $ExpectError - f( ( x: number ): number => x, y, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, 10, z ); // $ExpectError - f( x, '10', z ); // $ExpectError - f( x, true, z ); // $ExpectError - f( x, false, z ); // $ExpectError - f( x, null, z ); // $ExpectError - f( x, undefined, z ); // $ExpectError - f( x, [ '1' ], z ); // $ExpectError - f( x, {}, z ); // $ExpectError - f( x, ( x: number ): number => x, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, y, '10' ); // $ExpectError - f( x, y, true ); // $ExpectError - f( x, y, false ); // $ExpectError - f( x, y, null ); // $ExpectError - f( x, y, undefined ); // $ExpectError - f( x, y, [ '1' ] ); // $ExpectError - f( x, y, {} ); // $ExpectError - f( x, y, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( 10, y, z, w ); // $ExpectError - f( '10', y, z, w ); // $ExpectError - f( true, y, z, w ); // $ExpectError - f( false, y, z, w ); // $ExpectError - f( null, y, z, w ); // $ExpectError - f( undefined, y, z, w ); // $ExpectError - f( [ '1' ], y, z, w ); // $ExpectError - f( {}, y, z, w ); // $ExpectError - f( ( x: number ): number => x, y, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, 10, z, w ); // $ExpectError - f( x, '10', z, w ); // $ExpectError - f( x, true, z, w ); // $ExpectError - f( x, false, z, w ); // $ExpectError - f( x, null, z, w ); // $ExpectError - f( x, undefined, z, w ); // $ExpectError - f( x, [ '1' ], z, w ); // $ExpectError - f( x, {}, z, w ); // $ExpectError - f( x, ( x: number ): number => x, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, 10, w ); // $ExpectError - f( x, y, '10', w ); // $ExpectError - f( x, y, true, w ); // $ExpectError - f( x, y, false, w ); // $ExpectError - f( x, y, null, w ); // $ExpectError - f( x, y, undefined, w ); // $ExpectError - f( x, y, [ '1' ], w ); // $ExpectError - f( x, y, {}, w ); // $ExpectError - f( x, y, ( x: number ): number => x, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, z, 10 ); // $ExpectError - f( x, y, z, '10' ); // $ExpectError - f( x, y, z, true ); // $ExpectError - f( x, y, z, false ); // $ExpectError - f( x, y, z, null ); // $ExpectError - f( x, y, z, undefined ); // $ExpectError - f( x, y, z, [ '1' ] ); // $ExpectError - f( x, y, z, {} ); // $ExpectError - f( x, y, z, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( 10, y, z, w, u ); // $ExpectError - f( '10', y, z, w, u ); // $ExpectError - f( true, y, z, w, u ); // $ExpectError - f( false, y, z, w, u ); // $ExpectError - f( null, y, z, w, u ); // $ExpectError - f( undefined, y, z, w, u ); // $ExpectError - f( [ '1' ], y, z, w, u ); // $ExpectError - f( {}, y, z, w, u ); // $ExpectError - f( ( x: number ): number => x, y, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, 10, z, w, u ); // $ExpectError - f( x, '10', z, w, u ); // $ExpectError - f( x, true, z, w, u ); // $ExpectError - f( x, false, z, w, u ); // $ExpectError - f( x, null, z, w, u ); // $ExpectError - f( x, undefined, z, w, u ); // $ExpectError - f( x, [ '1' ], z, w, u ); // $ExpectError - f( x, {}, z, w, u ); // $ExpectError - f( x, ( x: number ): number => x, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, 10, w, u ); // $ExpectError - f( x, y, '10', w, u ); // $ExpectError - f( x, y, true, w, u ); // $ExpectError - f( x, y, false, w, u ); // $ExpectError - f( x, y, null, w, u ); // $ExpectError - f( x, y, undefined, w, u ); // $ExpectError - f( x, y, [ '1' ], w, u ); // $ExpectError - f( x, y, {}, w, u ); // $ExpectError - f( x, y, ( x: number ): number => x, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, 10, u ); // $ExpectError - f( x, y, z, '10', u ); // $ExpectError - f( x, y, z, true, u ); // $ExpectError - f( x, y, z, false, u ); // $ExpectError - f( x, y, z, null, u ); // $ExpectError - f( x, y, z, undefined, u ); // $ExpectError - f( x, y, z, [ '1' ], u ); // $ExpectError - f( x, y, z, {}, u ); // $ExpectError - f( x, y, z, ( x: number ): number => x, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fifth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, w, 10 ); // $ExpectError - f( x, y, z, w, '10' ); // $ExpectError - f( x, y, z, w, true ); // $ExpectError - f( x, y, z, w, false ); // $ExpectError - f( x, y, z, w, null ); // $ExpectError - f( x, y, z, w, undefined ); // $ExpectError - f( x, y, z, w, [ '1' ] ); // $ExpectError - f( x, y, z, w, {} ); // $ExpectError - f( x, y, z, w, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/add.js b/examples/add.js deleted file mode 100644 index 775b711..0000000 --- a/examples/add.js +++ /dev/null @@ -1,121 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var dispatch = require( './../lib' ); - -function add2( arrays ) { - var opts; - var xo; - var yo; - var zo; - var sx; - var sy; - var sz; - var sh; - var N; - var x; - var y; - var z; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - z = arrays[ 2 ]; - xo = x.order; - yo = y.order; - zo = z.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - opts.order = yo; - sy = ind2sub( sh, i, opts ); - v = x.get.apply( x, sx ) + y.get.apply( y, sy ); - - opts.order = zo; - sz = ind2sub( sh, i, opts ); - sz.push( v ); - z.set.apply( z, sz ); - } -} - -var fcns = [ - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2 -]; - -var types = [ - dtypes.float64, dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.int32, dtypes.int32, - dtypes.uint32, dtypes.uint32, dtypes.uint32, - dtypes.int16, dtypes.int16, dtypes.int16, - dtypes.uint16, dtypes.uint16, dtypes.uint16, - dtypes.int8, dtypes.int8, dtypes.int8, - dtypes.uint8, dtypes.uint8, dtypes.uint8, - dtypes.uint8c, dtypes.uint8c, dtypes.uint8c -]; - -var add = dispatch( fcns, types, null, 3, 2, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var zbuf = new Float64Array( xbuf.length ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var z = ndarray( 'float64', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); - -xbuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -ybuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -zbuf = new Int32Array( xbuf.length ); - -x = ndarray( 'int32', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'int32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -z = ndarray( 'int32', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); diff --git a/examples/sin.js b/examples/sin.js deleted file mode 100644 index 8cd4871..0000000 --- a/examples/sin.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int8Array = require( '@stdlib/array-int8' ); -var sin = require( '@stdlib/math-base-special-sin' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/strided-dtypes' ); -var dispatch = require( './../lib' ); - -function apply( arrays, fcn ) { - var opts; - var xo; - var yo; - var sx; - var sy; - var sh; - var N; - var x; - var y; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - xo = x.order; - yo = y.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - v = fcn( x.get.apply( x, sx ) ); - - opts.order = yo; - sy = ind2sub( sh, i, opts ); - sy.push( v ); - y.set.apply( y, sy ); - } -} - -var fcns = [ - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply -]; - -var types = [ - dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float64, - dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.float64, - dtypes.uint32, dtypes.float64, - dtypes.int16, dtypes.float64, - dtypes.int16, dtypes.float32, - dtypes.uint16, dtypes.float64, - dtypes.uint16, dtypes.float32, - dtypes.int8, dtypes.float64, - dtypes.int8, dtypes.float32, - dtypes.uint8, dtypes.float64, - dtypes.uint8, dtypes.float32, - dtypes.uint8c, dtypes.float64, - dtypes.uint8c, dtypes.float32 -]; - -var data = [ - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin -]; - -var sine = dispatch( fcns, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); - -xbuf = new Int8Array( [ 1, 2, 3, 4, 5 ] ); -ybuf = new Float32Array( xbuf.length ); - -x = ndarray( 'int8', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'float32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); diff --git a/examples/unary.js b/examples/unary.js deleted file mode 100644 index e9c3fb4..0000000 --- a/examples/unary.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -var unary = require( '@stdlib/ndarray-base-unary' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var dispatch = require( './../lib' ); - -var types = [ 'float64', 'float64' ]; - -var data = [ - abs -]; - -var absolute = dispatch( unary, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -absolute( x, y ); -console.log( ybuf ); -// => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 610167d..e8f79c8 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..f48c2d5 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function m(r,e,t,i,s,n,o,l,m){var d,a,h,f;for(d=n,h=0;h [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0Mq5s', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0Mq3A', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0Mq5u', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0Mq5v', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0Mq5w', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format( '0Mq0h' ) );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format( '0Mq0i' ) );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format( '0Mq0k' ) );\n\t}\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format( '0Mq0l' ) );\n\t\t\t}\n\t\t\tthrow new Error( format( '0Mq0m' ) );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( v.dtype );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format( '0Mq0p' ) );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n"],"names":["indexOfTypes","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","i","j","dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","push","dtype","slice"],"mappings":";;uvBA6EA,SAASA,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,KAAgBE,EAAGI,GADdE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,CACN,CACD,OAAQ,CACT,CCjBA,SAASU,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,sFAAuFV,IAErH,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAQ,UAE1B,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAQ,UAE1B,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAQ,eAI1B,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAQ,UAG3B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAQ,UAE1B,OAeA,WACC,IAAIO,EACAC,EACAC,EACAC,EACAC,EACAC,EACA3B,EAGJ,IADAwB,EAAOI,UAAUR,UACHd,EAAQ,CACrB,GAAKkB,EAAOlB,EACX,MAAM,IAAIa,MAAOJ,EAAQ,UAE1B,MAAM,IAAII,MAAOJ,EAAQ,SACzB,CAGD,IAFAO,EAAS,GACTC,EAAS,GACHvB,EAAI,EAAGA,EAAIM,EAAON,IAAM,CAE7B,IAAM6B,EADNH,EAAIE,UAAW5B,IAEd,MAAKA,EAAIO,EACF,IAAIO,UAAWC,EAAQ,6EAA8EW,IAErG,IAAIZ,UAAWC,EAAQ,8EAA+EW,IAG9GJ,EAAOQ,KAAMJ,GACbH,EAAOO,KAAMJ,EAAEK,MACf,CAKD,IAHAN,EAAMrC,EAAcsB,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGc,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAIT,UAAWC,EAAQ,UAI7BY,EADIhB,GAGAR,EAAMsB,GAGNpB,EACJsB,EAAGL,EAAQjB,EAAMoB,IAEjBE,EAAGL,GAEJ,GAAc,IAATd,EACJ,OAAOc,EAAQb,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOc,EAAOU,MAAOzB,EACrB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 291641d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Create an ndarray function interface which performs multiple dispatch. -* -* @module @stdlib/ndarray-dispatch -* -* @example -* var dispatch = require( '@stdlib/ndarray-dispatch' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/index_of_types.js b/lib/index_of_types.js deleted file mode 100644 index fda2297..0000000 --- a/lib/index_of_types.js +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found). -* -* ## Notes -* -* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types). -* - The function assumes that `x` is stored in row-major order. -* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`. -* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value. -* -* @private -* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension) -* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension) -* @param {ArrayLikeObject} x - input two-dimensional reference array -* @param {integer} strideX1 - `x` stride length along first dimension -* @param {integer} strideX2 - `x` stride length along second dimension -* @param {NonNegativeInteger} offsetX - `x` starting index -* @param {ArrayLikeObject} y - search array -* @param {integer} strideY - `y` stride length -* @param {NonNegativeInteger} offsetY - `y` starting index -* @returns {integer} row index (if found) and `-1` otherwise -* -* @example -* // Define a reference array to search: -* var types = [ -* 'float64', 'float64', 'float64', -* 'float32', 'float32', 'float32', -* 'uint32', 'uint32', 'float64', -* 'int32', 'int32', 'float64', -* 'uint16', 'uint16', 'float64', -* 'int16', 'int16', 'float64', -* 'uint8', 'uint8', 'float64', -* 'int8', 'int8', 'float64' -* ]; -* -* // Define reference array dimensions: -* var N = 8; // rows -* var M = 3; // columns -* -* // Define a search array: -* y1 = [ -* 'float32', 'float32', 'float32', -* ]; -* -* // Find the list of types: -* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 ); -* // returns 1 -* -// Define a search array: -* y2 = [ -* 'float32', 'float32', 'float64', -* ]; -* -* // Find the list of types: -* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 ); -* // returns -1 -*/ -function indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len - var ix; - var iy; - var i; - var j; - - // Search for the first row which matches `y`... - ix = offsetX; - for ( i = 0; i < N; i++ ) { - iy = offsetY; - for ( j = 0; j < M; j++ ) { - if ( x[ ix+(j*strideX2) ] !== y[ iy ] ) { - break; - } - iy += strideY; - } - // If we successfully iterated over all columns, then that means we've found a match... - if ( j === M ) { - return i; - } - ix += strideX1; - } - return -1; -} - - -// EXPORTS // - -module.exports = indexOfTypes; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c8218ef..0000000 --- a/lib/main.js +++ /dev/null @@ -1,207 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isFunctionArray = require( '@stdlib/assert-is-function-array' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var indexOfTypes = require( './index_of_types.js' ); - - -// MAIN // - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param {(FunctionArray|Function)} fcns - list of ndarray functions -* @param {Collection} types - one-dimensional list of ndarray argument data types -* @param {(Collection|null)} data - ndarray function data (e.g., callbacks) -* @param {PositiveInteger} nargs - total number of ndarray function interface arguments -* @param {NonNegativeInteger} nin - number of input ndarrays -* @param {NonNegativeInteger} nout - number of output ndarrays -* @throws {TypeError} first argument must be either a function or an array of functions -* @throws {TypeError} second argument must be an array-like object -* @throws {TypeError} third argument must be an array-like object or `null` -* @throws {Error} third and first arguments must have the same number of elements -* @throws {TypeError} fourth argument must be a positive integer -* @throws {TypeError} fifth argument must be a nonnegative integer -* @throws {TypeError} sixth argument must be a nonnegative integer -* @throws {Error} fourth argument must equal the specified number of input and output arrays -* @throws {Error} number of types must match the number of functions times the total number of array arguments for each function -* @throws {Error} interface must accept at least one input and/or output ndarray -* @returns {Function} ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function dispatch( fcns, types, data, nargs, nin, nout ) { - var narrays; - var nfcns; - var fcn; - - if ( isFunction( fcns ) ) { - fcn = fcns; - } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( '0Mq5s', fcns ) ); - } - if ( !isCollection( types ) ) { - throw new TypeError( format( '0Mq3A', types ) ); - } - if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); - } - if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( '0Mq5u', nargs ) ); - } - if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( '0Mq5v', nin ) ); - } - if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( '0Mq5w', nout ) ); - } - narrays = nin + nout; - if ( narrays === 0 ) { - throw new Error( format( '0Mq0h' ) ); - } - if ( nargs !== narrays ) { - throw new Error( format( '0Mq0i' ) ); - } - if ( fcn ) { - nfcns = types.length / narrays; - if ( !isInteger( nfcns ) ) { - throw new Error( format( '0Mq0j' ) ); - } - } else { - nfcns = fcns.length; - if ( types.length !== nfcns*narrays ) { - throw new Error( format( '0Mq0j' ) ); - } - } - if ( data && data.length !== nfcns ) { - throw new Error( format( '0Mq0k' ) ); - } - return dispatcher; - - /** - * ndarray function interface which performs multiple dispatch. - * - * @private - * @param {ndarrayLike} x - ndarray - * @param {...ndarrayLike} args - ndarray arguments - * @throws {Error} insufficient arguments - * @throws {Error} too many arguments - * @throws {TypeError} input array arguments must be ndarray-like objects - * @throws {TypeError} output array arguments must be ndarray-like objects - * @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types - * @returns {(ndarrayLike|Array|void)} destination array(s) - */ - function dispatcher() { - var arrays; - var dtypes; - var argc; - var idx; - var v; - var f; - var i; - - argc = arguments.length; - if ( argc !== nargs ) { - if ( argc < nargs ) { - throw new Error( format( '0Mq0l' ) ); - } - throw new Error( format( '0Mq0m' ) ); - } - arrays = []; - dtypes = []; - for ( i = 0; i < nargs; i++ ) { - v = arguments[ i ]; - if ( !isndarrayLike( v ) ) { - if ( i < nin ) { - throw new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) ); - } else { - throw new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) ); - } - } - arrays.push( v ); - dtypes.push( v.dtype ); - } - // Resolve the ndarray function satisfying the input array types: - idx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len - - // Check whether we were able to successfully resolve an ndarray function: - if ( idx < 0 ) { - throw new TypeError( format( '0Mq0p' ) ); - } - // Retrieve the ndarray function: - if ( fcn ) { - f = fcn; - } else { - f = fcns[ idx ]; - } - // Evaluate the ndarray function: - if ( data ) { - f( arrays, data[ idx ] ); - } else { - f( arrays ); - } - if ( nout === 1 ) { - return arrays[ narrays-1 ]; - } - if ( nout === 0 ) { - return; - } - return arrays.slice( nin ); - } -} - - -// EXPORTS // - -module.exports = dispatch; diff --git a/package.json b/package.json index 63ab6bc..aab393c 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Create an ndarray function interface which performs multiple dispatch.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,54 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@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-ndarray-like": "^0.0.x", - "@stdlib/assert-is-nonnegative-integer": "^0.0.x", - "@stdlib/assert-is-positive-integer": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/array-int32": "^0.0.x", - "@stdlib/array-int8": "^0.0.x", - "@stdlib/array-uint8": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/math-base-assert-is-nan": "^0.0.x", - "@stdlib/math-base-special-abs": "^0.0.x", - "@stdlib/math-base-special-pow": "^0.0.x", - "@stdlib/math-base-special-sin": "^0.0.x", - "@stdlib/ndarray-base-buffer-dtype": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/ndarray-base-unary": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/ndarray-dtypes": "^0.0.x", - "@stdlib/ndarray-ind2sub": "^0.0.x", - "@stdlib/strided-dtypes": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "2.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "ndarray", @@ -97,7 +26,6 @@ "multimethod", "multimethods" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..41d829b --- /dev/null +++ b/stats.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/fixtures/binary.js b/test/fixtures/binary.js deleted file mode 100644 index a60dfa2..0000000 --- a/test/fixtures/binary.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Binary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @returns {number} sum -*/ -function binary( x, y ) { - return x + y; -} - - -// EXPORTS // - -module.exports = binary; diff --git a/test/fixtures/fill.js b/test/fixtures/fill.js deleted file mode 100644 index 41b2958..0000000 --- a/test/fixtures/fill.js +++ /dev/null @@ -1,76 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which fills one or more ndarrays. -* -* @private -* @param {*} value - fill value -* @returns {Function} ndarray function -*/ -function fill( value ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - */ - function ndarrayFcn( arrays ) { - var opts; - var sub; - var arr; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - opts = { - 'order': '' - }; - for ( j = 0; j < M; j++ ) { - arr = arrays[ j ]; - opts.order = arrays[ j ].order; - for ( i = 0; i < N; i++ ) { - sub = ind2sub( sh, i, opts ); - sub.push( value ); - arr.set.apply( arr, sub ); - } - } - } -} - - -// EXPORTS // - -module.exports = fill; diff --git a/test/fixtures/foreach.js b/test/fixtures/foreach.js deleted file mode 100644 index a426290..0000000 --- a/test/fixtures/foreach.js +++ /dev/null @@ -1,72 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function forEach( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - fcn.apply( null, args ); - } -} - - -// EXPORTS // - -module.exports = forEach; diff --git a/test/fixtures/map1n.js b/test/fixtures/map1n.js deleted file mode 100644 index 614196b..0000000 --- a/test/fixtures/map1n.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function which maps the return value of a callback to `N` arrays. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function map1N( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var v; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - v = fcn(); - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - sub.push( v ); - arrays[ j ].set.apply( arrays[ j ], sub ); - } - } -} - - -// EXPORTS // - -module.exports = map1N; diff --git a/test/fixtures/nullary.js b/test/fixtures/nullary.js deleted file mode 100644 index 4f22126..0000000 --- a/test/fixtures/nullary.js +++ /dev/null @@ -1,36 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Nullary callback. -* -* @private -* @returns {number} value -*/ -function nullary() { - return 3.0; -} - - -// EXPORTS // - -module.exports = nullary; diff --git a/test/fixtures/quaternary.js b/test/fixtures/quaternary.js deleted file mode 100644 index 548437b..0000000 --- a/test/fixtures/quaternary.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quaternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @returns {number} sum -*/ -function quaternary( x, y, z, w ) { - return x + y + z + w; -} - - -// EXPORTS // - -module.exports = quaternary; diff --git a/test/fixtures/quinary.js b/test/fixtures/quinary.js deleted file mode 100644 index 36068de..0000000 --- a/test/fixtures/quinary.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quinary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @param {number} u - input value -* @returns {number} sum -*/ -function quinary( x, y, z, w, u ) { - return x + y + z + w + u; -} - - -// EXPORTS // - -module.exports = quinary; diff --git a/test/fixtures/sum.js b/test/fixtures/sum.js deleted file mode 100644 index efdbb1b..0000000 --- a/test/fixtures/sum.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which computes the sum across one or more ndarrays. -* -* @private -* @param {Object} ctx - context -* @param {number} ctx.sum - initial sum -* @returns {Function} ndarray function -*/ -function wrapper( ctx ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - * @param {Function} [fcn] - callback - */ - function ndarrayFcn( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var f; - var i; - var j; - - if ( arguments.length > 1 ) { - f = fcn; - } - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - if ( f ) { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - ctx.sum += f.apply( null, args ); - } - } else { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - ctx.sum += arrays[ j ].get.apply( arrays[ j ], sub ); - } - } - } - } -} - - -// EXPORTS // - -module.exports = wrapper; diff --git a/test/fixtures/ternary.js b/test/fixtures/ternary.js deleted file mode 100644 index 0595d5f..0000000 --- a/test/fixtures/ternary.js +++ /dev/null @@ -1,39 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Ternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @returns {number} sum -*/ -function ternary( x, y, z ) { - return x + y + z; -} - - -// EXPORTS // - -module.exports = ternary; diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d6c2c8e..0000000 --- a/test/test.js +++ /dev/null @@ -1,363 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var fill = require( './fixtures/fill.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either a function or an array of functions as a first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( value, types, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object as a second argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided either an array-like object or `null` as a third argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - dispatch( unary, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a positive integer for a fourth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 0, - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a fifth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, value, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a sixth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, 1, value ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function array)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var fcns = [ unary, unary, unary ]; - var data = [ abs, abs, abs ]; - dispatch( fcns, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function argument)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs, abs, abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the length of `data` argument does not match the number of ndarray functions', function test( t ) { - var values; - var i; - - values = [ - [], - [ abs, abs ], - [ abs, abs, abs ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var fcns = [ unary ]; - dispatch( fcns, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the fourth argument is incompatible with the number of input and output ndarrays', function test( t ) { - var values; - var i; - - values = [ - 0, - 1, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of specified input and output ndarrays is zero', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var types = [ 'float64' ]; - dispatch( fill( 3 ), types, null, 1, 0, 0 ); - } -}); - -tape( 'the function returns an ndarray function interface', function test( t ) { - var types; - var data; - var f; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - f = dispatch( unary, types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ unary ], types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( fill( 3 ), types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ fill( 3 ) ], types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.two_arrays.js b/test/test.two_arrays.js deleted file mode 100644 index 071500e..0000000 --- a/test/test.two_arrays.js +++ /dev/null @@ -1,808 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var dtype = require( '@stdlib/ndarray-base-buffer-dtype' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var forEach = require( './fixtures/foreach.js' ); -var map1N = require( './fixtures/map1n.js' ); -var fill = require( './fixtures/fill.js' ); -var sum = require( './fixtures/sum.js' ); - - -// TESTS // - -tape( 'the function returns a function which throws an error if not provided an ndarray for the first argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var ybuf = new Float64Array( 10 ); - var y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( value, y ); - }; - } -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the second argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var xbuf = new Float64Array( 10 ); - var x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( x, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided insufficient arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var f; - var x; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [], - [ x ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided too many arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var ybuf; - var f; - var x; - var y; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [ x, y, y ], - [ x, y, y, y ], - [ x, y, y, y, y ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if unable to resolve a ndarray function supporting the provided array argument data types', function test( t ) { - var values; - var types; - var data; - var xbuf; - var fcn; - var x; - var i; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ abs, abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 4 ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - values = [ - new Uint8Array( 4 ), - new Int32Array( 4 ), - [ 0, 0, 0, 0 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided an array having data type: ' + dtype( values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var y = ndarray( dtype( value ), value, [ value.length ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - }; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only input arrays)', function test( t ) { - var types; - var xbuf; - var ybuf; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only output arrays)', function test( t ) { - var expected; - var types; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only input arrays)', function test( t ) { - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var ctx; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcns = [ - sum( ctx ), - sum( ctx ) - ]; - fcn = dispatch( fcns, types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only output arrays)', function test( t ) { - var expected; - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcns = [ - fill( 3.0 ), - fill( 4.0 ) - ]; - fcn = dispatch( fcns, types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - - fcn = dispatch( forEach, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - - fcn = dispatch( map1N, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - fcns = [ - forEach, - forEach - ]; - fcn = dispatch( fcns, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - fcns = [ - map1N, - map1N - ]; - fcn = dispatch( fcns, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - fcns = [ - unary, - unary - ]; - fcn = dispatch( fcns, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which returns one or more output arrays, if one or more output arrays is specified, and otherwise returns `undefined`', function test( t ) { - var types; - var data; - var xbuf; - var ybuf; - var out; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - // No output arrays... - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, void 0, 'returns expected value' ); - - // One output array... - data = [ - abs, - abs - ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - fcn = dispatch( fill( 3.0 ), types, null, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - // Two output arrays... - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.end(); -}); From ea738564674a3006a34e81a91901c482205dc1fe Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 9 Dec 2022 07:39:42 +0000 Subject: [PATCH 029/109] Transform error messages --- lib/main.js | 28 ++++++++++++++-------------- package.json | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/main.js b/lib/main.js index a19fa68..7653329 100644 --- a/lib/main.js +++ b/lib/main.js @@ -27,7 +27,7 @@ var isFunctionArray = require( '@stdlib/assert-is-function-array' ); var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var resolveEnum = require( '@stdlib/ndarray-base-dtype-resolve-enum' ); var indexOfTypes = require( './index_of_types.js' ); @@ -111,43 +111,43 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { if ( isFunction( fcns ) ) { fcn = fcns; } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) ); + throw new TypeError( format( '0Mq5s', fcns ) ); } if ( !isCollection( types ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) ); + throw new TypeError( format( '0Mq3A', types ) ); } if ( !isCollection( data ) && data !== null ) { throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); } if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) ); + throw new TypeError( format( '0Mq5u', nargs ) ); } if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) ); + throw new TypeError( format( '0Mq5v', nin ) ); } if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) ); + throw new TypeError( format( '0Mq5w', nout ) ); } narrays = nin + nout; if ( narrays === 0 ) { - throw new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' ); + throw new Error( format( '0Mq0h' ) ); } if ( nargs !== narrays ) { - throw new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' ); + throw new Error( format( '0Mq0i' ) ); } if ( fcn ) { nfcns = types.length / narrays; if ( !isInteger( nfcns ) ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format( '0Mq0j' ) ); } } else { nfcns = fcns.length; if ( types.length !== nfcns*narrays ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format( '0Mq0j' ) ); } } if ( data && data.length !== nfcns ) { - throw new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' ); + throw new Error( format( '0Mq0k' ) ); } types = types2enums( types ); return dispatcher; @@ -177,9 +177,9 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { argc = arguments.length; if ( argc !== nargs ) { if ( argc < nargs ) { - throw new Error( 'invalid invocation. Insufficient arguments.' ); + throw new Error( format( '0Mq0l' ) ); } - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format( '0Mq0m' ) ); } arrays = []; dtypes = []; @@ -200,7 +200,7 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { // Check whether we were able to successfully resolve an ndarray function: if ( idx < 0 ) { - throw new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' ); + throw new TypeError( format( '0Mq0p' ) ); } // Retrieve the ndarray function: if ( fcn ) { diff --git a/package.json b/package.json index f0e599e..18eada8 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/assert-is-nonnegative-integer": "^0.0.x", "@stdlib/assert-is-positive-integer": "^0.0.x", "@stdlib/ndarray-base-dtype-resolve-enum": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From f5a12ad0124372f5633e2c71be8b4f05edb4e7b1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 9 Dec 2022 07:41:08 +0000 Subject: [PATCH 030/109] Remove files --- index.d.ts | 334 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4383 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index e8f79c8..0000000 --- a/index.d.ts +++ /dev/null @@ -1,334 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* ndarray function. -* -* @param arrays - array containing input and output ndarrays -* @param data - ndarray function data (e.g., a callback) -* -* @example -* var numel = require( `@stdlib/ndarray/base/numel` ); -* var ind2sub = require( `@stdlib/ndarray/ind2sub` ); -* -* function ndarrayFcn( arrays, fcn ) { -* var xord; -* var yord; -* var opts; -* var sub; -* var sh; -* var N; -* var x; -* var y; -* var v; -* var i; -* -* x = arrays[ 0 ]; -* y = arrays[ 1 ]; -* sh = x.shape; -* N = numel( sh ); -* if ( N <= 0 ) { -* return; -* } -* xord = x.order; -* yord = y.order; -* opts = {}; -* opts.order = xord; -* for ( i = 0; i < N; i++ ) { -* // Convert a linear index to subscripts: -* opts.order = xord; -* sub = ind2sub( sh, i, opts ); -* -* // Retrieve an element from `x`: -* v = x.get.apply( x, sub ); -* -* // Convert a linear index to subscripts: -* opts.order = yord; -* sub = ind2sub( sh, i, opts ); -* -* // Append the result of applying the callback: -* sub.push( fcn( v ) ); -* -* // Assign the result to an element in `y`: -* y.set.apply( y, sub ); -* } -* } -*/ -type ndarrayFcn = ( arrays: Array, data?: any ) => void; - -/** -* Interface describing an ndarray function dispatcher. -*/ -interface Dispatcher { - /** - * Invokes an ndarray function based on the provided array data type(s). - * - * @param x - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array - * - * @example - * var nullary = require( `@stdlib/ndarray/base/nullary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function value() { - * return 3.14; - * } - * - * var types = [ 'float64' ]; - * var data = [ value ]; - * - * var fcn = dispatch( nullary, types, data, 1, 0, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( 5 ); - * var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x ); - * // xbuf => [ 3.14, 3.14, 3.14, 3.14, 3.14 ] - */ - ( x: ndarray ): ndarray | void; - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var unary = require( `@stdlib/ndarray/base/unary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * var abs = require( `@stdlib/math/base/special/abs` ); - * - * var types = [ 'float64', 'float64' ]; - * var data = [ abs ]; - * - * var fcn = dispatch( unary, types, data, 2, 1, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - * var ybuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y ); - * // ybuf => [ 1.0, 2.0, 3.0 ] - */ - ( x: ndarray, y: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var ternary = require( `@stdlib/ndarray/base/ternary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add2( x, y ) { - * return x + y; - * } - * - * var types = [ 'float64', 'float64', 'float64' ]; - * var data = [ add2 ]; - * - * var fcn = dispatch( ternary, types, data, 3, 2, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z ); - * // zbuf => [ 2.0, 4.0, 6.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quaternary = require( `@stdlib/ndarray/base/quaternary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add3( x, y, z ) { - * return x + y + z; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add3 ]; - * - * var fcn = dispatch( quaternary, types, data, 4, 3, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w ); - * // wbuf => [ 3.0, 6.0, 9.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @param args - ndarray arguments - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quinary = require( `@stdlib/ndarray/base/quinary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add4( x, y, z, w ) { - * return x + y + z + w; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add4 ]; - * - * var fcn = dispatch( quinary, types, data, 5, 4, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ubuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var u = ndarray( 'float64', ubuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w, u ); - * // ubuf => [ 4.0, 8.0, 12.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray, ...args: Array ): ndarray | void; // tslint:disable-line:max-line-length unified-signatures -} - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param fcns - list of ndarray functions -* @param types - one-dimensional list of ndarray argument data types -* @param data - ndarray function data (e.g., callbacks) -* @param nargs - total number of ndarray function interface arguments -* @param nin - number of input ndarrays -* @param nout - number of output ndarrays -* @throws first argument must be either a function or an array of functions -* @throws second argument must be an array-like object -* @throws third argument must be an array-like object or `null` -* @throws third and first arguments must have the same number of elements -* @throws fourth argument must be a positive integer -* @throws fifth argument must be a nonnegative integer -* @throws sixth argument must be a nonnegative integer -* @throws fourth argument must equal the specified number of input and output arrays -* @throws number of types must match the number of functions times the total number of array arguments for each function -* @throws interface must accept at least one input and/or output ndarray -* @returns ndarray function interface -* -* @example -* var unary = require( `@stdlib/ndarray/base/unary` ); -* var abs = require( `@stdlib/math/base/special/abs` ); -* var Float64Array = require( `@stdlib/array/float64` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var fcn = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* fcn( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function dispatch( fcns: ndarrayFcn | ArrayLike, types: ArrayLike, data: ArrayLike | null, nargs: number, nin: number, nout: number ): Dispatcher; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = dispatch; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index f48c2d5..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";function m(r,e,t,i,s,n,o,l,m){var d,a,h,f;for(d=n,h=0;h [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0Mq5s', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0Mq3A', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0Mq5u', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0Mq5v', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0Mq5w', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format( '0Mq0h' ) );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format( '0Mq0i' ) );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format( '0Mq0k' ) );\n\t}\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format( '0Mq0l' ) );\n\t\t\t}\n\t\t\tthrow new Error( format( '0Mq0m' ) );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( v.dtype );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format( '0Mq0p' ) );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n"],"names":["indexOfTypes","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","i","j","dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","push","dtype","slice"],"mappings":";;uvBA6EA,SAASA,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,KAAgBE,EAAGI,GADdE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,CACN,CACD,OAAQ,CACT,CCjBA,SAASU,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,sFAAuFV,IAErH,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAQ,UAE1B,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAQ,UAE1B,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAQ,eAI1B,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAQ,UAG3B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAQ,UAE1B,OAeA,WACC,IAAIO,EACAC,EACAC,EACAC,EACAC,EACAC,EACA3B,EAGJ,IADAwB,EAAOI,UAAUR,UACHd,EAAQ,CACrB,GAAKkB,EAAOlB,EACX,MAAM,IAAIa,MAAOJ,EAAQ,UAE1B,MAAM,IAAII,MAAOJ,EAAQ,SACzB,CAGD,IAFAO,EAAS,GACTC,EAAS,GACHvB,EAAI,EAAGA,EAAIM,EAAON,IAAM,CAE7B,IAAM6B,EADNH,EAAIE,UAAW5B,IAEd,MAAKA,EAAIO,EACF,IAAIO,UAAWC,EAAQ,6EAA8EW,IAErG,IAAIZ,UAAWC,EAAQ,8EAA+EW,IAG9GJ,EAAOQ,KAAMJ,GACbH,EAAOO,KAAMJ,EAAEK,MACf,CAKD,IAHAN,EAAMrC,EAAcsB,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGc,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAIT,UAAWC,EAAQ,UAI7BY,EADIhB,GAGAR,EAAMsB,GAGNpB,EACJsB,EAAGL,EAAQjB,EAAMoB,IAEjBE,EAAGL,GAEJ,GAAc,IAATd,EACJ,OAAOc,EAAQb,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOc,EAAOU,MAAOzB,EACrB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 41d829b..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 39f6284d726531c286f3af4ae3a2655a246b1d7d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 9 Dec 2022 07:42:29 +0000 Subject: [PATCH 031/109] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 781 ---- .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 183 - .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 59 +- benchmark/benchmark.dispatch_size.js | 156 - benchmark/benchmark.js | 81 - branches.md | 53 - docs/repl.txt | 87 - docs/types/test.ts | 641 ---- examples/add.js | 121 - examples/sin.js | 142 - examples/unary.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/index_of_types.js | 106 - lib/main.js | 230 -- package.json | 77 +- stats.html | 4044 +++++++++++++++++++++ test/fixtures/binary.js | 38 - test/fixtures/fill.js | 76 - test/fixtures/foreach.js | 72 - test/fixtures/map1n.js | 74 - test/fixtures/nullary.js | 36 - test/fixtures/quaternary.js | 40 - test/fixtures/quinary.js | 41 - test/fixtures/sum.js | 98 - test/fixtures/ternary.js | 39 - test/test.js | 363 -- test/test.two_arrays.js | 808 ---- 50 files changed, 4078 insertions(+), 6445 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.dispatch_size.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/add.js delete mode 100644 examples/sin.js delete mode 100644 examples/unary.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/index_of_types.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/fixtures/binary.js delete mode 100644 test/fixtures/fill.js delete mode 100644 test/fixtures/foreach.js delete mode 100644 test/fixtures/map1n.js delete mode 100644 test/fixtures/nullary.js delete mode 100644 test/fixtures/quaternary.js delete mode 100644 test/fixtures/quinary.js delete mode 100644 test/fixtures/sum.js delete mode 100644 test/fixtures/ternary.js delete mode 100644 test/test.js delete mode 100644 test/test.two_arrays.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ac0b7cd..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 920b304..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 34e41d6..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '43 7 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 37ddb4f..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,781 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -291,7 +284,7 @@ console.log( ybuf ); ## 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. +This package is part of [stdlib][stdlib], a standard library 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]. @@ -353,11 +346,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm diff --git a/benchmark/benchmark.dispatch_size.js b/benchmark/benchmark.dispatch_size.js deleted file mode 100644 index 3bd0418..0000000 --- a/benchmark/benchmark.dispatch_size.js +++ /dev/null @@ -1,156 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib/main.js' ); - - -// FUNCTIONS // - -/** -* Evaluates the identity function. -* -* @private -* @param {*} v - value -* @returns {*} input value -*/ -function identity( v ) { - return v; -} - -/** -* Dummy function which throws an error. -* -* @private -* @throws {Error} unexpected error -*/ -function throwError() { - throw new Error( 'unexpected error' ); -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} size - dispatch size -* @returns {Function} benchmark function -*/ -function createBenchmark( size ) { - var types; - var data; - var fcn; - var x; - var y; - var t; - var i; - - types = []; - - // Create dummy types... - for ( i = 0; i < (size-1)*2; i += 2 ) { - t = 'foo' + i; - types.push( t ); - types.push( t ); - } - // Append test types: - types.push( 'float64' ); - types.push( 'float64' ); - - // Define a list of callbacks: - data = []; - for ( i = 0; i < size-1; i++ ) { - data.push( throwError ); - } - // Append a test callback: - data.push( identity ); - - // Create the dispatcher: - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - // Create sample arrays: - x = new Float64Array( 1 ); - y = new Float64Array( x.length ); - - x = ndarray( 'float64', x, [ 1 ], [ 1 ], 0, 'row-major' ); - y = ndarray( 'float64', y, [ 1 ], [ 1 ], 0, 'row-major' ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var z; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x.data[ 0 ] = i; - z = fcn( x, y ); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var size; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - size = pow( 2, i ); - f = createBenchmark( size ); - bench( pkg+':size='+size, f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index a70dc5c..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::fcns_array', function benchmark( b ) { - var types; - var fcns; - var data; - var out; - var i; - - fcns = [ unary ]; - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( fcns, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::fcn_arg', function benchmark( b ) { - var types; - var data; - var out; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( unary, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index d04d051..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch" -click B href "https://github.com/stdlib-js/ndarray-dispatch/tree/main" -click C href "https://github.com/stdlib-js/ndarray-dispatch/tree/production" -click D href "https://github.com/stdlib-js/ndarray-dispatch/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-dispatch/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-dispatch/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch -[production-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 02fe150..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,87 +0,0 @@ - -{{alias}}( fcns, types, data, nargs, nin, nout ) - Returns an ndarray function interface which performs multiple dispatch. - - An ndarray function interface has the following signature: - - f( x, y, ... ) - - where - - - x: ndarray. - - y: ndarray. - - ...: additional ndarrays. - - The number of parameters is derived from `nargs`, the number of input - ndarrays is derived from `nin`, and the number of output ndarrays is derived - from `nout`. - - Parameters - ---------- - fcns: Function|ArrayLikeObject - List of ndarray functions. An ndarray function should have the following - signature: - - f( arrays, data ) - - where - - - arrays: array containing input and output ndarrays. - - data: ndarray function data (e.g., a callback). - - For convenience, a single ndarray function may be provided which will be - invoked whenever the ndarray argument data types match a sequence of - types in `types`. Providing a single ndarray function is particularly - convenient for the case where, regardless of array data types, - traversing arrays remains the same, but the ndarray function `data` - differs (e.g., callbacks which differ based on the array data types). - - types: ArrayLikeObject - One-dimensional list of ndarray argument data types. - - data: ArrayLikeObject|null - ndarray function data (e.g., callbacks). If `null`, a returned ndarray - function interface does **not** provide a `data` argument to an invoked - ndarray function. - - nargs: integer - Total number of ndarray function interface arguments. - - nin: integer - Number of input ndarrays. - - nout: integer - Number of output ndarrays. - - Returns - ------- - fcn: Function - ndarray function interface. - - Examples - -------- - // Define ndarray argument data types: - > var t = [ 'float64', 'float64', 'float32', 'float32' ]; - - // Define a list of ndarray function data (callbacks): - > var d = [ {{alias:@stdlib/math/base/special/abs}}, {{alias:@stdlib/math/base/special/absf}} ]; - - // Create an ndarray function interface for applying unary callbacks: - > var f = {{alias}}( {{alias:@stdlib/ndarray/base/unary}}, t, d, 2, 1, 1 ); - - // Create an input ndarray: - > var xbuf = new {{alias:@stdlib/array/float64}}( [ -1.0, -2.0, -3.0, -4.0 ] ); - > var x = {{alias:@stdlib/ndarray/ctor}}( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Create an output ndarray: - > var ybuf = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 0.0, 0.0 ] ); - > var y = {{alias:@stdlib/ndarray/ctor}}( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Compute the element-wise absolute value: - > f( x, y ); - > ybuf - [ 1.0, 2.0, 3.0, 4.0 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 397185e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,641 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// tslint:disable:max-file-line-count - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import dispatch = require( './index' ); - - -// FUNCTIONS // - -/** -* Nullary callback. -* -* @return input value -*/ -function nullary(): any { - return 5.0; -} - -/** -* Unary callback. -* -* @param x - input value -* @return input value -*/ -function unary( x: any ): any { - return x; -} - -/** -* Binary callback. -* -* @param x - input value -* @param y - input value -* @return output value -*/ -function binary( x: number, y: number ): number { - return x + y; -} - -/** -* Ternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @return output value -*/ -function ternary( x: number, y: number, z: number ): number { - return x + y + z; -} - -/** -* Quaternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @param w - input value -* @return output value -*/ -function quaternary( x: number, y: number, z: number, w: number ): number { - return x + y + z + w; -} - -/** -* Mock `ind2sub` function. -* -* @param shape - dimensions -* @param idx - linear index -* @param opts - options -* @return subscripts -*/ -function ind2sub( shape: ArrayLike, idx: number, opts?: any ): Array { // tslint:disable-line:max-line-length - let out; - let i; - - out = []; - if ( typeof opts === 'object' && opts !== null && opts.order === 'row-major' ) { // tslint:disable-line:max-line-length no-unsafe-any - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } else { - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } - return out; -} - -/** -* Mock ndarray function. -* -* @param arrays - ndarrays -* @param fcn - callback -*/ -function ndarrayFcn( arrays: Array, fcn: ( x: any ) => any ): void { - let xord; - let yord; - let opts; - let sub; - let sh; - let N; - let x; - let y; - let v; - let i; - - x = arrays[ 0 ]; - y = arrays[ 1 ]; - sh = x.shape; - if ( sh.length === 0 ) { - return; - } - N = 1; - for ( i = 0; i < sh.length; i += 1 ) { - N *= sh[ i ]; - } - xord = x.order; - yord = y.order; - opts = { - 'order': '' - }; - opts.order = xord; - for ( i = 0; i < N; i += 1 ) { - // Convert a linear index to subscripts: - opts.order = xord; - sub = ind2sub( sh, i, opts ); - - // Retrieve an element from `x`: - v = x.get.apply( x, sub ); - - // Convert a linear index to subscripts: - opts.order = yord; - sub = ind2sub( sh, i, opts ); - - // Append the result of applying the callback: - sub[ sub.length ] = fcn( v ) as number; - - // Assign the result to an element in `y`: - y.set.apply( y, sub ); - } -} - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a dispatch function... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, 1 ); // $ExpectType Dispatcher - dispatch( [ ndarrayFcn ], types, data, 2, 1, 1 ); // $ExpectType Dispatcher -} - -// The compiler throws an error if the function is provided a first argument which is not either an ndarray function or an array-like object containing ndarray functions... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( '10', types, data, 2, 1, 1 ); // $ExpectError - dispatch( 10, types, data, 2, 1, 1 ); // $ExpectError - dispatch( true, types, data, 2, 1, 1 ); // $ExpectError - dispatch( false, types, data, 2, 1, 1 ); // $ExpectError - dispatch( null, types, data, 2, 1, 1 ); // $ExpectError - dispatch( undefined, types, data, 2, 1, 1 ); // $ExpectError - dispatch( [ '1' ], types, data, 2, 1, 1 ); // $ExpectError - dispatch( {}, types, data, 2, 1, 1 ); // $ExpectError - dispatch( ( x: number ): number => x, types, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object... -{ - const data = [ unary ]; - - dispatch( ndarrayFcn, 10, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, true, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, false, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, null, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, undefined, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, {}, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object or null... -{ - const types = [ 'float64', 'float64' ]; - - dispatch( ndarrayFcn, types, 10, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, true, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, false, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, undefined, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, {}, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, '10', 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, true, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, false, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, null, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, undefined, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, [ '1' ], 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, {}, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, ( x: number ): number => x, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, '10', 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, true, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, false, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, null, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, undefined, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, [ '1' ], 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, {}, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, ( x: number ): number => x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, '10' ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, true ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, false ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, null ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, undefined ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, [ '1' ] ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, {} ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch(); // $ExpectError - dispatch( ndarrayFcn ); // $ExpectError - dispatch( ndarrayFcn, types ); // $ExpectError - dispatch( ndarrayFcn, types, data ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, 1, 0 ); // $ExpectError -} - -// The function returns a dispatch function... -{ - const x = array(); - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const t1 = [ 'float64' ]; - const d1 = [ nullary ]; - const f1 = dispatch( ndarrayFcn, t1, d1, 1, 1, 0 ); - f1( x ); // $ExpectType void | ndarray - - const t2 = [ 'float64', 'float64' ]; - const d2 = [ unary ]; - const f2 = dispatch( ndarrayFcn, t2, d2, 2, 1, 1 ); - f2( x, y ); // $ExpectType void | ndarray - - const t3 = [ 'float64', 'float64', 'float64' ]; - const d3 = [ binary ]; - const f3 = dispatch( ndarrayFcn, t3, d3, 3, 2, 1 ); - f3( x, y, z ); // $ExpectType void | ndarray - - const t4 = [ 'float64', 'float64', 'float64', 'float64' ]; - const d4 = [ ternary ]; - const f4 = dispatch( ndarrayFcn, t4, d4, 4, 3, 1 ); - f4( x, y, z, w ); // $ExpectType void | ndarray - - const t5 = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const d5 = [ quaternary ]; - const f5 = dispatch( ndarrayFcn, t5, d5, 5, 4, 1 ); - f5( x, y, z, w, u ); // $ExpectType void | ndarray -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (1 ndarray)... -{ - const types = [ 'float64' ]; - const data = [ nullary ]; - - const f = dispatch( ndarrayFcn, types, data, 1, 0, 1 ); - f( '10' ); // $ExpectError - f( 10 ); // $ExpectError - f( true ); // $ExpectError - f( false ); // $ExpectError - f( null ); // $ExpectError - f( undefined ); // $ExpectError - f( [ '1' ] ); // $ExpectError - f( {} ); // $ExpectError - f( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( 10, y ); // $ExpectError - f( '10', y ); // $ExpectError - f( true, y ); // $ExpectError - f( false, y ); // $ExpectError - f( null, y ); // $ExpectError - f( undefined, y ); // $ExpectError - f( [ '1' ], y ); // $ExpectError - f( {}, y ); // $ExpectError - f( ( x: number ): number => x, y ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const x = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( x, 10 ); // $ExpectError - f( x, '10' ); // $ExpectError - f( x, true ); // $ExpectError - f( x, false ); // $ExpectError - f( x, null ); // $ExpectError - f( x, undefined ); // $ExpectError - f( x, [ '1' ] ); // $ExpectError - f( x, {} ); // $ExpectError - f( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( 10, y, z ); // $ExpectError - f( '10', y, z ); // $ExpectError - f( true, y, z ); // $ExpectError - f( false, y, z ); // $ExpectError - f( null, y, z ); // $ExpectError - f( undefined, y, z ); // $ExpectError - f( [ '1' ], y, z ); // $ExpectError - f( {}, y, z ); // $ExpectError - f( ( x: number ): number => x, y, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, 10, z ); // $ExpectError - f( x, '10', z ); // $ExpectError - f( x, true, z ); // $ExpectError - f( x, false, z ); // $ExpectError - f( x, null, z ); // $ExpectError - f( x, undefined, z ); // $ExpectError - f( x, [ '1' ], z ); // $ExpectError - f( x, {}, z ); // $ExpectError - f( x, ( x: number ): number => x, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, y, '10' ); // $ExpectError - f( x, y, true ); // $ExpectError - f( x, y, false ); // $ExpectError - f( x, y, null ); // $ExpectError - f( x, y, undefined ); // $ExpectError - f( x, y, [ '1' ] ); // $ExpectError - f( x, y, {} ); // $ExpectError - f( x, y, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( 10, y, z, w ); // $ExpectError - f( '10', y, z, w ); // $ExpectError - f( true, y, z, w ); // $ExpectError - f( false, y, z, w ); // $ExpectError - f( null, y, z, w ); // $ExpectError - f( undefined, y, z, w ); // $ExpectError - f( [ '1' ], y, z, w ); // $ExpectError - f( {}, y, z, w ); // $ExpectError - f( ( x: number ): number => x, y, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, 10, z, w ); // $ExpectError - f( x, '10', z, w ); // $ExpectError - f( x, true, z, w ); // $ExpectError - f( x, false, z, w ); // $ExpectError - f( x, null, z, w ); // $ExpectError - f( x, undefined, z, w ); // $ExpectError - f( x, [ '1' ], z, w ); // $ExpectError - f( x, {}, z, w ); // $ExpectError - f( x, ( x: number ): number => x, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, 10, w ); // $ExpectError - f( x, y, '10', w ); // $ExpectError - f( x, y, true, w ); // $ExpectError - f( x, y, false, w ); // $ExpectError - f( x, y, null, w ); // $ExpectError - f( x, y, undefined, w ); // $ExpectError - f( x, y, [ '1' ], w ); // $ExpectError - f( x, y, {}, w ); // $ExpectError - f( x, y, ( x: number ): number => x, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, z, 10 ); // $ExpectError - f( x, y, z, '10' ); // $ExpectError - f( x, y, z, true ); // $ExpectError - f( x, y, z, false ); // $ExpectError - f( x, y, z, null ); // $ExpectError - f( x, y, z, undefined ); // $ExpectError - f( x, y, z, [ '1' ] ); // $ExpectError - f( x, y, z, {} ); // $ExpectError - f( x, y, z, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( 10, y, z, w, u ); // $ExpectError - f( '10', y, z, w, u ); // $ExpectError - f( true, y, z, w, u ); // $ExpectError - f( false, y, z, w, u ); // $ExpectError - f( null, y, z, w, u ); // $ExpectError - f( undefined, y, z, w, u ); // $ExpectError - f( [ '1' ], y, z, w, u ); // $ExpectError - f( {}, y, z, w, u ); // $ExpectError - f( ( x: number ): number => x, y, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, 10, z, w, u ); // $ExpectError - f( x, '10', z, w, u ); // $ExpectError - f( x, true, z, w, u ); // $ExpectError - f( x, false, z, w, u ); // $ExpectError - f( x, null, z, w, u ); // $ExpectError - f( x, undefined, z, w, u ); // $ExpectError - f( x, [ '1' ], z, w, u ); // $ExpectError - f( x, {}, z, w, u ); // $ExpectError - f( x, ( x: number ): number => x, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, 10, w, u ); // $ExpectError - f( x, y, '10', w, u ); // $ExpectError - f( x, y, true, w, u ); // $ExpectError - f( x, y, false, w, u ); // $ExpectError - f( x, y, null, w, u ); // $ExpectError - f( x, y, undefined, w, u ); // $ExpectError - f( x, y, [ '1' ], w, u ); // $ExpectError - f( x, y, {}, w, u ); // $ExpectError - f( x, y, ( x: number ): number => x, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, 10, u ); // $ExpectError - f( x, y, z, '10', u ); // $ExpectError - f( x, y, z, true, u ); // $ExpectError - f( x, y, z, false, u ); // $ExpectError - f( x, y, z, null, u ); // $ExpectError - f( x, y, z, undefined, u ); // $ExpectError - f( x, y, z, [ '1' ], u ); // $ExpectError - f( x, y, z, {}, u ); // $ExpectError - f( x, y, z, ( x: number ): number => x, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fifth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, w, 10 ); // $ExpectError - f( x, y, z, w, '10' ); // $ExpectError - f( x, y, z, w, true ); // $ExpectError - f( x, y, z, w, false ); // $ExpectError - f( x, y, z, w, null ); // $ExpectError - f( x, y, z, w, undefined ); // $ExpectError - f( x, y, z, w, [ '1' ] ); // $ExpectError - f( x, y, z, w, {} ); // $ExpectError - f( x, y, z, w, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/add.js b/examples/add.js deleted file mode 100644 index 775b711..0000000 --- a/examples/add.js +++ /dev/null @@ -1,121 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var dispatch = require( './../lib' ); - -function add2( arrays ) { - var opts; - var xo; - var yo; - var zo; - var sx; - var sy; - var sz; - var sh; - var N; - var x; - var y; - var z; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - z = arrays[ 2 ]; - xo = x.order; - yo = y.order; - zo = z.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - opts.order = yo; - sy = ind2sub( sh, i, opts ); - v = x.get.apply( x, sx ) + y.get.apply( y, sy ); - - opts.order = zo; - sz = ind2sub( sh, i, opts ); - sz.push( v ); - z.set.apply( z, sz ); - } -} - -var fcns = [ - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2 -]; - -var types = [ - dtypes.float64, dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.int32, dtypes.int32, - dtypes.uint32, dtypes.uint32, dtypes.uint32, - dtypes.int16, dtypes.int16, dtypes.int16, - dtypes.uint16, dtypes.uint16, dtypes.uint16, - dtypes.int8, dtypes.int8, dtypes.int8, - dtypes.uint8, dtypes.uint8, dtypes.uint8, - dtypes.uint8c, dtypes.uint8c, dtypes.uint8c -]; - -var add = dispatch( fcns, types, null, 3, 2, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var zbuf = new Float64Array( xbuf.length ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var z = ndarray( 'float64', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); - -xbuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -ybuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -zbuf = new Int32Array( xbuf.length ); - -x = ndarray( 'int32', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'int32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -z = ndarray( 'int32', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); diff --git a/examples/sin.js b/examples/sin.js deleted file mode 100644 index 8cd4871..0000000 --- a/examples/sin.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int8Array = require( '@stdlib/array-int8' ); -var sin = require( '@stdlib/math-base-special-sin' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/strided-dtypes' ); -var dispatch = require( './../lib' ); - -function apply( arrays, fcn ) { - var opts; - var xo; - var yo; - var sx; - var sy; - var sh; - var N; - var x; - var y; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - xo = x.order; - yo = y.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - v = fcn( x.get.apply( x, sx ) ); - - opts.order = yo; - sy = ind2sub( sh, i, opts ); - sy.push( v ); - y.set.apply( y, sy ); - } -} - -var fcns = [ - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply -]; - -var types = [ - dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float64, - dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.float64, - dtypes.uint32, dtypes.float64, - dtypes.int16, dtypes.float64, - dtypes.int16, dtypes.float32, - dtypes.uint16, dtypes.float64, - dtypes.uint16, dtypes.float32, - dtypes.int8, dtypes.float64, - dtypes.int8, dtypes.float32, - dtypes.uint8, dtypes.float64, - dtypes.uint8, dtypes.float32, - dtypes.uint8c, dtypes.float64, - dtypes.uint8c, dtypes.float32 -]; - -var data = [ - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin -]; - -var sine = dispatch( fcns, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); - -xbuf = new Int8Array( [ 1, 2, 3, 4, 5 ] ); -ybuf = new Float32Array( xbuf.length ); - -x = ndarray( 'int8', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'float32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); diff --git a/examples/unary.js b/examples/unary.js deleted file mode 100644 index e9c3fb4..0000000 --- a/examples/unary.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -var unary = require( '@stdlib/ndarray-base-unary' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var dispatch = require( './../lib' ); - -var types = [ 'float64', 'float64' ]; - -var data = [ - abs -]; - -var absolute = dispatch( unary, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -absolute( x, y ); -console.log( ybuf ); -// => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 610167d..e8f79c8 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..f86f148 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@esm/index.mjs";function l(r,e,t,s,i,n,o,d,m){var l,a,h,f;for(l=n,h=0;h [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0Mq5s', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0Mq3A', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0Mq5u', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0Mq5v', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0Mq5w', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format( '0Mq0h' ) );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format( '0Mq0i' ) );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format( '0Mq0k' ) );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format( '0Mq0l' ) );\n\t\t\t}\n\t\t\tthrow new Error( format( '0Mq0m' ) );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( v.dtype ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format( '0Mq0p' ) );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n"],"names":["indexOfTypes","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","i","j","dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","out","push","resolveEnum","types2enums","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","dtype","slice"],"mappings":";;01BA6EA,SAASA,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,KAAgBE,EAAGI,GADdE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,CACN,CACD,OAAQ,CACT,CCKA,SAASU,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,sFAAuFV,IAErH,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAQ,UAE1B,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAQ,UAE1B,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAQ,eAI1B,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAQ,UAG3B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAQ,UAG1B,OADAX,EA5GD,SAAsBA,GACrB,IAAIkB,EACAtB,EAGJ,IADAsB,EAAM,GACAtB,EAAI,EAAGA,EAAII,EAAMgB,OAAQpB,IAC9BsB,EAAIC,KAAMC,EAAapB,EAAOJ,KAE/B,OAAOsB,CACR,CAmGSG,CAAarB,GAgBrB,WACC,IAAIsB,EACAC,EACAC,EACAC,EACAC,EACAC,EACA/B,EAGJ,IADA4B,EAAOI,UAAUZ,UACHd,EAAQ,CACrB,GAAKsB,EAAOtB,EACX,MAAM,IAAIa,MAAOJ,EAAQ,UAE1B,MAAM,IAAII,MAAOJ,EAAQ,SACzB,CAGD,IAFAW,EAAS,GACTC,EAAS,GACH3B,EAAI,EAAGA,EAAIM,EAAON,IAAM,CAE7B,IAAMiC,EADNH,EAAIE,UAAWhC,IAEd,MAAKA,EAAIO,EACF,IAAIO,UAAWC,EAAQ,6EAA8Ee,IAErG,IAAIhB,UAAWC,EAAQ,8EAA+Ee,IAG9GJ,EAAOH,KAAMO,GACbH,EAAOJ,KAAMC,EAAaM,EAAEI,OAC5B,CAKD,IAHAL,EAAMzC,EAAcsB,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGkB,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAIb,UAAWC,EAAQ,UAI7BgB,EADIpB,GAGAR,EAAM0B,GAGNxB,EACJ0B,EAAGL,EAAQrB,EAAMwB,IAEjBE,EAAGL,GAEJ,GAAc,IAATlB,EACJ,OAAOkB,EAAQjB,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOkB,EAAOS,MAAO5B,EACrB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 291641d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Create an ndarray function interface which performs multiple dispatch. -* -* @module @stdlib/ndarray-dispatch -* -* @example -* var dispatch = require( '@stdlib/ndarray-dispatch' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/index_of_types.js b/lib/index_of_types.js deleted file mode 100644 index fda2297..0000000 --- a/lib/index_of_types.js +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found). -* -* ## Notes -* -* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types). -* - The function assumes that `x` is stored in row-major order. -* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`. -* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value. -* -* @private -* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension) -* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension) -* @param {ArrayLikeObject} x - input two-dimensional reference array -* @param {integer} strideX1 - `x` stride length along first dimension -* @param {integer} strideX2 - `x` stride length along second dimension -* @param {NonNegativeInteger} offsetX - `x` starting index -* @param {ArrayLikeObject} y - search array -* @param {integer} strideY - `y` stride length -* @param {NonNegativeInteger} offsetY - `y` starting index -* @returns {integer} row index (if found) and `-1` otherwise -* -* @example -* // Define a reference array to search: -* var types = [ -* 'float64', 'float64', 'float64', -* 'float32', 'float32', 'float32', -* 'uint32', 'uint32', 'float64', -* 'int32', 'int32', 'float64', -* 'uint16', 'uint16', 'float64', -* 'int16', 'int16', 'float64', -* 'uint8', 'uint8', 'float64', -* 'int8', 'int8', 'float64' -* ]; -* -* // Define reference array dimensions: -* var N = 8; // rows -* var M = 3; // columns -* -* // Define a search array: -* y1 = [ -* 'float32', 'float32', 'float32', -* ]; -* -* // Find the list of types: -* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 ); -* // returns 1 -* -// Define a search array: -* y2 = [ -* 'float32', 'float32', 'float64', -* ]; -* -* // Find the list of types: -* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 ); -* // returns -1 -*/ -function indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len - var ix; - var iy; - var i; - var j; - - // Search for the first row which matches `y`... - ix = offsetX; - for ( i = 0; i < N; i++ ) { - iy = offsetY; - for ( j = 0; j < M; j++ ) { - if ( x[ ix+(j*strideX2) ] !== y[ iy ] ) { - break; - } - iy += strideY; - } - // If we successfully iterated over all columns, then that means we've found a match... - if ( j === M ) { - return i; - } - ix += strideX1; - } - return -1; -} - - -// EXPORTS // - -module.exports = indexOfTypes; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 7653329..0000000 --- a/lib/main.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isFunctionArray = require( '@stdlib/assert-is-function-array' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var resolveEnum = require( '@stdlib/ndarray-base-dtype-resolve-enum' ); -var indexOfTypes = require( './index_of_types.js' ); - - -// FUNCTIONS // - -/** -* Returns a list of data type enumeration constants. -* -* @private -* @param {Collection} types - list of types -* @returns {IntegerArray} list of data type enumeration constants -*/ -function types2enums( types ) { - var out; - var i; - - out = []; - for ( i = 0; i < types.length; i++ ) { - out.push( resolveEnum( types[ i ] ) ); - } - return out; -} - - -// MAIN // - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param {(FunctionArray|Function)} fcns - list of ndarray functions -* @param {Collection} types - one-dimensional list of ndarray argument data types -* @param {(Collection|null)} data - ndarray function data (e.g., callbacks) -* @param {PositiveInteger} nargs - total number of ndarray function interface arguments -* @param {NonNegativeInteger} nin - number of input ndarrays -* @param {NonNegativeInteger} nout - number of output ndarrays -* @throws {TypeError} first argument must be either a function or an array of functions -* @throws {TypeError} second argument must be an array-like object -* @throws {TypeError} third argument must be an array-like object or `null` -* @throws {Error} third and first arguments must have the same number of elements -* @throws {TypeError} fourth argument must be a positive integer -* @throws {TypeError} fifth argument must be a nonnegative integer -* @throws {TypeError} sixth argument must be a nonnegative integer -* @throws {Error} fourth argument must equal the specified number of input and output arrays -* @throws {Error} number of types must match the number of functions times the total number of array arguments for each function -* @throws {Error} interface must accept at least one input and/or output ndarray -* @returns {Function} ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function dispatch( fcns, types, data, nargs, nin, nout ) { - var narrays; - var nfcns; - var fcn; - - if ( isFunction( fcns ) ) { - fcn = fcns; - } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( '0Mq5s', fcns ) ); - } - if ( !isCollection( types ) ) { - throw new TypeError( format( '0Mq3A', types ) ); - } - if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); - } - if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( '0Mq5u', nargs ) ); - } - if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( '0Mq5v', nin ) ); - } - if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( '0Mq5w', nout ) ); - } - narrays = nin + nout; - if ( narrays === 0 ) { - throw new Error( format( '0Mq0h' ) ); - } - if ( nargs !== narrays ) { - throw new Error( format( '0Mq0i' ) ); - } - if ( fcn ) { - nfcns = types.length / narrays; - if ( !isInteger( nfcns ) ) { - throw new Error( format( '0Mq0j' ) ); - } - } else { - nfcns = fcns.length; - if ( types.length !== nfcns*narrays ) { - throw new Error( format( '0Mq0j' ) ); - } - } - if ( data && data.length !== nfcns ) { - throw new Error( format( '0Mq0k' ) ); - } - types = types2enums( types ); - return dispatcher; - - /** - * ndarray function interface which performs multiple dispatch. - * - * @private - * @param {ndarrayLike} x - ndarray - * @param {...ndarrayLike} args - ndarray arguments - * @throws {Error} insufficient arguments - * @throws {Error} too many arguments - * @throws {TypeError} input array arguments must be ndarray-like objects - * @throws {TypeError} output array arguments must be ndarray-like objects - * @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types - * @returns {(ndarrayLike|Array|void)} destination array(s) - */ - function dispatcher() { - var arrays; - var dtypes; - var argc; - var idx; - var v; - var f; - var i; - - argc = arguments.length; - if ( argc !== nargs ) { - if ( argc < nargs ) { - throw new Error( format( '0Mq0l' ) ); - } - throw new Error( format( '0Mq0m' ) ); - } - arrays = []; - dtypes = []; - for ( i = 0; i < nargs; i++ ) { - v = arguments[ i ]; - if ( !isndarrayLike( v ) ) { - if ( i < nin ) { - throw new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) ); - } else { - throw new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) ); - } - } - arrays.push( v ); - dtypes.push( resolveEnum( v.dtype ) ); - } - // Resolve the ndarray function satisfying the input array types: - idx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len - - // Check whether we were able to successfully resolve an ndarray function: - if ( idx < 0 ) { - throw new TypeError( format( '0Mq0p' ) ); - } - // Retrieve the ndarray function: - if ( fcn ) { - f = fcn; - } else { - f = fcns[ idx ]; - } - // Evaluate the ndarray function: - if ( data ) { - f( arrays, data[ idx ] ); - } else { - f( arrays ); - } - if ( nout === 1 ) { - return arrays[ narrays-1 ]; - } - if ( nout === 0 ) { - return; - } - return arrays.slice( nin ); - } -} - - -// EXPORTS // - -module.exports = dispatch; diff --git a/package.json b/package.json index 18eada8..aab393c 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Create an ndarray function interface which performs multiple dispatch.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,55 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@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-ndarray-like": "^0.0.x", - "@stdlib/assert-is-nonnegative-integer": "^0.0.x", - "@stdlib/assert-is-positive-integer": "^0.0.x", - "@stdlib/ndarray-base-dtype-resolve-enum": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/array-int32": "^0.0.x", - "@stdlib/array-int8": "^0.0.x", - "@stdlib/array-uint8": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/math-base-assert-is-nan": "^0.0.x", - "@stdlib/math-base-special-abs": "^0.0.x", - "@stdlib/math-base-special-pow": "^0.0.x", - "@stdlib/math-base-special-sin": "^0.0.x", - "@stdlib/ndarray-base-buffer-dtype": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/ndarray-base-unary": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/ndarray-dtypes": "^0.0.x", - "@stdlib/ndarray-ind2sub": "^0.0.x", - "@stdlib/strided-dtypes": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "2.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "ndarray", @@ -98,7 +26,6 @@ "multimethod", "multimethods" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..d5738de --- /dev/null +++ b/stats.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/fixtures/binary.js b/test/fixtures/binary.js deleted file mode 100644 index a60dfa2..0000000 --- a/test/fixtures/binary.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Binary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @returns {number} sum -*/ -function binary( x, y ) { - return x + y; -} - - -// EXPORTS // - -module.exports = binary; diff --git a/test/fixtures/fill.js b/test/fixtures/fill.js deleted file mode 100644 index 41b2958..0000000 --- a/test/fixtures/fill.js +++ /dev/null @@ -1,76 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which fills one or more ndarrays. -* -* @private -* @param {*} value - fill value -* @returns {Function} ndarray function -*/ -function fill( value ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - */ - function ndarrayFcn( arrays ) { - var opts; - var sub; - var arr; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - opts = { - 'order': '' - }; - for ( j = 0; j < M; j++ ) { - arr = arrays[ j ]; - opts.order = arrays[ j ].order; - for ( i = 0; i < N; i++ ) { - sub = ind2sub( sh, i, opts ); - sub.push( value ); - arr.set.apply( arr, sub ); - } - } - } -} - - -// EXPORTS // - -module.exports = fill; diff --git a/test/fixtures/foreach.js b/test/fixtures/foreach.js deleted file mode 100644 index a426290..0000000 --- a/test/fixtures/foreach.js +++ /dev/null @@ -1,72 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function forEach( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - fcn.apply( null, args ); - } -} - - -// EXPORTS // - -module.exports = forEach; diff --git a/test/fixtures/map1n.js b/test/fixtures/map1n.js deleted file mode 100644 index 614196b..0000000 --- a/test/fixtures/map1n.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function which maps the return value of a callback to `N` arrays. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function map1N( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var v; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - v = fcn(); - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - sub.push( v ); - arrays[ j ].set.apply( arrays[ j ], sub ); - } - } -} - - -// EXPORTS // - -module.exports = map1N; diff --git a/test/fixtures/nullary.js b/test/fixtures/nullary.js deleted file mode 100644 index 4f22126..0000000 --- a/test/fixtures/nullary.js +++ /dev/null @@ -1,36 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Nullary callback. -* -* @private -* @returns {number} value -*/ -function nullary() { - return 3.0; -} - - -// EXPORTS // - -module.exports = nullary; diff --git a/test/fixtures/quaternary.js b/test/fixtures/quaternary.js deleted file mode 100644 index 548437b..0000000 --- a/test/fixtures/quaternary.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quaternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @returns {number} sum -*/ -function quaternary( x, y, z, w ) { - return x + y + z + w; -} - - -// EXPORTS // - -module.exports = quaternary; diff --git a/test/fixtures/quinary.js b/test/fixtures/quinary.js deleted file mode 100644 index 36068de..0000000 --- a/test/fixtures/quinary.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quinary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @param {number} u - input value -* @returns {number} sum -*/ -function quinary( x, y, z, w, u ) { - return x + y + z + w + u; -} - - -// EXPORTS // - -module.exports = quinary; diff --git a/test/fixtures/sum.js b/test/fixtures/sum.js deleted file mode 100644 index efdbb1b..0000000 --- a/test/fixtures/sum.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which computes the sum across one or more ndarrays. -* -* @private -* @param {Object} ctx - context -* @param {number} ctx.sum - initial sum -* @returns {Function} ndarray function -*/ -function wrapper( ctx ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - * @param {Function} [fcn] - callback - */ - function ndarrayFcn( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var f; - var i; - var j; - - if ( arguments.length > 1 ) { - f = fcn; - } - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - if ( f ) { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - ctx.sum += f.apply( null, args ); - } - } else { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - ctx.sum += arrays[ j ].get.apply( arrays[ j ], sub ); - } - } - } - } -} - - -// EXPORTS // - -module.exports = wrapper; diff --git a/test/fixtures/ternary.js b/test/fixtures/ternary.js deleted file mode 100644 index 0595d5f..0000000 --- a/test/fixtures/ternary.js +++ /dev/null @@ -1,39 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Ternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @returns {number} sum -*/ -function ternary( x, y, z ) { - return x + y + z; -} - - -// EXPORTS // - -module.exports = ternary; diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d6c2c8e..0000000 --- a/test/test.js +++ /dev/null @@ -1,363 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var fill = require( './fixtures/fill.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either a function or an array of functions as a first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( value, types, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object as a second argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided either an array-like object or `null` as a third argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - dispatch( unary, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a positive integer for a fourth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 0, - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a fifth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, value, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a sixth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, 1, value ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function array)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var fcns = [ unary, unary, unary ]; - var data = [ abs, abs, abs ]; - dispatch( fcns, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function argument)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs, abs, abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the length of `data` argument does not match the number of ndarray functions', function test( t ) { - var values; - var i; - - values = [ - [], - [ abs, abs ], - [ abs, abs, abs ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var fcns = [ unary ]; - dispatch( fcns, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the fourth argument is incompatible with the number of input and output ndarrays', function test( t ) { - var values; - var i; - - values = [ - 0, - 1, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of specified input and output ndarrays is zero', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var types = [ 'float64' ]; - dispatch( fill( 3 ), types, null, 1, 0, 0 ); - } -}); - -tape( 'the function returns an ndarray function interface', function test( t ) { - var types; - var data; - var f; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - f = dispatch( unary, types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ unary ], types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( fill( 3 ), types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ fill( 3 ) ], types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.two_arrays.js b/test/test.two_arrays.js deleted file mode 100644 index 071500e..0000000 --- a/test/test.two_arrays.js +++ /dev/null @@ -1,808 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var dtype = require( '@stdlib/ndarray-base-buffer-dtype' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var forEach = require( './fixtures/foreach.js' ); -var map1N = require( './fixtures/map1n.js' ); -var fill = require( './fixtures/fill.js' ); -var sum = require( './fixtures/sum.js' ); - - -// TESTS // - -tape( 'the function returns a function which throws an error if not provided an ndarray for the first argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var ybuf = new Float64Array( 10 ); - var y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( value, y ); - }; - } -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the second argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var xbuf = new Float64Array( 10 ); - var x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( x, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided insufficient arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var f; - var x; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [], - [ x ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided too many arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var ybuf; - var f; - var x; - var y; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [ x, y, y ], - [ x, y, y, y ], - [ x, y, y, y, y ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if unable to resolve a ndarray function supporting the provided array argument data types', function test( t ) { - var values; - var types; - var data; - var xbuf; - var fcn; - var x; - var i; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ abs, abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 4 ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - values = [ - new Uint8Array( 4 ), - new Int32Array( 4 ), - [ 0, 0, 0, 0 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided an array having data type: ' + dtype( values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var y = ndarray( dtype( value ), value, [ value.length ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - }; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only input arrays)', function test( t ) { - var types; - var xbuf; - var ybuf; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only output arrays)', function test( t ) { - var expected; - var types; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only input arrays)', function test( t ) { - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var ctx; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcns = [ - sum( ctx ), - sum( ctx ) - ]; - fcn = dispatch( fcns, types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only output arrays)', function test( t ) { - var expected; - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcns = [ - fill( 3.0 ), - fill( 4.0 ) - ]; - fcn = dispatch( fcns, types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - - fcn = dispatch( forEach, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - - fcn = dispatch( map1N, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - fcns = [ - forEach, - forEach - ]; - fcn = dispatch( fcns, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - fcns = [ - map1N, - map1N - ]; - fcn = dispatch( fcns, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - fcns = [ - unary, - unary - ]; - fcn = dispatch( fcns, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which returns one or more output arrays, if one or more output arrays is specified, and otherwise returns `undefined`', function test( t ) { - var types; - var data; - var xbuf; - var ybuf; - var out; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - // No output arrays... - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, void 0, 'returns expected value' ); - - // One output array... - data = [ - abs, - abs - ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - fcn = dispatch( fill( 3.0 ), types, null, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - // Two output arrays... - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.end(); -}); From 67ac77a59a37ac604b8c21bfcabca88bd5f02e28 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Jan 2023 03:33:50 +0000 Subject: [PATCH 032/109] Transform error messages --- lib/main.js | 28 ++++++++++++++-------------- package.json | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/main.js b/lib/main.js index a19fa68..7653329 100644 --- a/lib/main.js +++ b/lib/main.js @@ -27,7 +27,7 @@ var isFunctionArray = require( '@stdlib/assert-is-function-array' ); var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var resolveEnum = require( '@stdlib/ndarray-base-dtype-resolve-enum' ); var indexOfTypes = require( './index_of_types.js' ); @@ -111,43 +111,43 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { if ( isFunction( fcns ) ) { fcn = fcns; } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) ); + throw new TypeError( format( '0Mq5s', fcns ) ); } if ( !isCollection( types ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) ); + throw new TypeError( format( '0Mq3A', types ) ); } if ( !isCollection( data ) && data !== null ) { throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); } if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) ); + throw new TypeError( format( '0Mq5u', nargs ) ); } if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) ); + throw new TypeError( format( '0Mq5v', nin ) ); } if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) ); + throw new TypeError( format( '0Mq5w', nout ) ); } narrays = nin + nout; if ( narrays === 0 ) { - throw new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' ); + throw new Error( format( '0Mq0h' ) ); } if ( nargs !== narrays ) { - throw new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' ); + throw new Error( format( '0Mq0i' ) ); } if ( fcn ) { nfcns = types.length / narrays; if ( !isInteger( nfcns ) ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format( '0Mq0j' ) ); } } else { nfcns = fcns.length; if ( types.length !== nfcns*narrays ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format( '0Mq0j' ) ); } } if ( data && data.length !== nfcns ) { - throw new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' ); + throw new Error( format( '0Mq0k' ) ); } types = types2enums( types ); return dispatcher; @@ -177,9 +177,9 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { argc = arguments.length; if ( argc !== nargs ) { if ( argc < nargs ) { - throw new Error( 'invalid invocation. Insufficient arguments.' ); + throw new Error( format( '0Mq0l' ) ); } - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format( '0Mq0m' ) ); } arrays = []; dtypes = []; @@ -200,7 +200,7 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { // Check whether we were able to successfully resolve an ndarray function: if ( idx < 0 ) { - throw new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' ); + throw new TypeError( format( '0Mq0p' ) ); } // Retrieve the ndarray function: if ( fcn ) { diff --git a/package.json b/package.json index 753ad9c..8da4654 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/assert-is-nonnegative-integer": "^0.0.x", "@stdlib/assert-is-positive-integer": "^0.0.x", "@stdlib/ndarray-base-dtype-resolve-enum": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From 2cd2c1e2ead993e806216d71dce013ee775b2d8d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Jan 2023 13:46:35 +0000 Subject: [PATCH 033/109] Remove files --- index.d.ts | 334 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4383 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index e8f79c8..0000000 --- a/index.d.ts +++ /dev/null @@ -1,334 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* ndarray function. -* -* @param arrays - array containing input and output ndarrays -* @param data - ndarray function data (e.g., a callback) -* -* @example -* var numel = require( `@stdlib/ndarray/base/numel` ); -* var ind2sub = require( `@stdlib/ndarray/ind2sub` ); -* -* function ndarrayFcn( arrays, fcn ) { -* var xord; -* var yord; -* var opts; -* var sub; -* var sh; -* var N; -* var x; -* var y; -* var v; -* var i; -* -* x = arrays[ 0 ]; -* y = arrays[ 1 ]; -* sh = x.shape; -* N = numel( sh ); -* if ( N <= 0 ) { -* return; -* } -* xord = x.order; -* yord = y.order; -* opts = {}; -* opts.order = xord; -* for ( i = 0; i < N; i++ ) { -* // Convert a linear index to subscripts: -* opts.order = xord; -* sub = ind2sub( sh, i, opts ); -* -* // Retrieve an element from `x`: -* v = x.get.apply( x, sub ); -* -* // Convert a linear index to subscripts: -* opts.order = yord; -* sub = ind2sub( sh, i, opts ); -* -* // Append the result of applying the callback: -* sub.push( fcn( v ) ); -* -* // Assign the result to an element in `y`: -* y.set.apply( y, sub ); -* } -* } -*/ -type ndarrayFcn = ( arrays: Array, data?: any ) => void; - -/** -* Interface describing an ndarray function dispatcher. -*/ -interface Dispatcher { - /** - * Invokes an ndarray function based on the provided array data type(s). - * - * @param x - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array - * - * @example - * var nullary = require( `@stdlib/ndarray/base/nullary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function value() { - * return 3.14; - * } - * - * var types = [ 'float64' ]; - * var data = [ value ]; - * - * var fcn = dispatch( nullary, types, data, 1, 0, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( 5 ); - * var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x ); - * // xbuf => [ 3.14, 3.14, 3.14, 3.14, 3.14 ] - */ - ( x: ndarray ): ndarray | void; - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var unary = require( `@stdlib/ndarray/base/unary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * var abs = require( `@stdlib/math/base/special/abs` ); - * - * var types = [ 'float64', 'float64' ]; - * var data = [ abs ]; - * - * var fcn = dispatch( unary, types, data, 2, 1, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - * var ybuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y ); - * // ybuf => [ 1.0, 2.0, 3.0 ] - */ - ( x: ndarray, y: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var ternary = require( `@stdlib/ndarray/base/ternary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add2( x, y ) { - * return x + y; - * } - * - * var types = [ 'float64', 'float64', 'float64' ]; - * var data = [ add2 ]; - * - * var fcn = dispatch( ternary, types, data, 3, 2, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z ); - * // zbuf => [ 2.0, 4.0, 6.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quaternary = require( `@stdlib/ndarray/base/quaternary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add3( x, y, z ) { - * return x + y + z; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add3 ]; - * - * var fcn = dispatch( quaternary, types, data, 4, 3, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w ); - * // wbuf => [ 3.0, 6.0, 9.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @param args - ndarray arguments - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quinary = require( `@stdlib/ndarray/base/quinary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add4( x, y, z, w ) { - * return x + y + z + w; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add4 ]; - * - * var fcn = dispatch( quinary, types, data, 5, 4, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ubuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var u = ndarray( 'float64', ubuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w, u ); - * // ubuf => [ 4.0, 8.0, 12.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray, ...args: Array ): ndarray | void; // tslint:disable-line:max-line-length unified-signatures -} - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param fcns - list of ndarray functions -* @param types - one-dimensional list of ndarray argument data types -* @param data - ndarray function data (e.g., callbacks) -* @param nargs - total number of ndarray function interface arguments -* @param nin - number of input ndarrays -* @param nout - number of output ndarrays -* @throws first argument must be either a function or an array of functions -* @throws second argument must be an array-like object -* @throws third argument must be an array-like object or `null` -* @throws third and first arguments must have the same number of elements -* @throws fourth argument must be a positive integer -* @throws fifth argument must be a nonnegative integer -* @throws sixth argument must be a nonnegative integer -* @throws fourth argument must equal the specified number of input and output arrays -* @throws number of types must match the number of functions times the total number of array arguments for each function -* @throws interface must accept at least one input and/or output ndarray -* @returns ndarray function interface -* -* @example -* var unary = require( `@stdlib/ndarray/base/unary` ); -* var abs = require( `@stdlib/math/base/special/abs` ); -* var Float64Array = require( `@stdlib/array/float64` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var fcn = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* fcn( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function dispatch( fcns: ndarrayFcn | ArrayLike, types: ArrayLike, data: ArrayLike | null, nargs: number, nin: number, nout: number ): Dispatcher; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = dispatch; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index f86f148..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@esm/index.mjs";function l(r,e,t,s,i,n,o,d,m){var l,a,h,f;for(l=n,h=0;h [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0Mq5s', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0Mq3A', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0Mq5u', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0Mq5v', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0Mq5w', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format( '0Mq0h' ) );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format( '0Mq0i' ) );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format( '0Mq0k' ) );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format( '0Mq0l' ) );\n\t\t\t}\n\t\t\tthrow new Error( format( '0Mq0m' ) );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( v.dtype ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format( '0Mq0p' ) );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n"],"names":["indexOfTypes","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","i","j","dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","out","push","resolveEnum","types2enums","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","dtype","slice"],"mappings":";;01BA6EA,SAASA,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,KAAgBE,EAAGI,GADdE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,CACN,CACD,OAAQ,CACT,CCKA,SAASU,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,sFAAuFV,IAErH,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAQ,UAE1B,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAQ,UAE1B,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAQ,eAI1B,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAQ,UAG3B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAQ,UAG1B,OADAX,EA5GD,SAAsBA,GACrB,IAAIkB,EACAtB,EAGJ,IADAsB,EAAM,GACAtB,EAAI,EAAGA,EAAII,EAAMgB,OAAQpB,IAC9BsB,EAAIC,KAAMC,EAAapB,EAAOJ,KAE/B,OAAOsB,CACR,CAmGSG,CAAarB,GAgBrB,WACC,IAAIsB,EACAC,EACAC,EACAC,EACAC,EACAC,EACA/B,EAGJ,IADA4B,EAAOI,UAAUZ,UACHd,EAAQ,CACrB,GAAKsB,EAAOtB,EACX,MAAM,IAAIa,MAAOJ,EAAQ,UAE1B,MAAM,IAAII,MAAOJ,EAAQ,SACzB,CAGD,IAFAW,EAAS,GACTC,EAAS,GACH3B,EAAI,EAAGA,EAAIM,EAAON,IAAM,CAE7B,IAAMiC,EADNH,EAAIE,UAAWhC,IAEd,MAAKA,EAAIO,EACF,IAAIO,UAAWC,EAAQ,6EAA8Ee,IAErG,IAAIhB,UAAWC,EAAQ,8EAA+Ee,IAG9GJ,EAAOH,KAAMO,GACbH,EAAOJ,KAAMC,EAAaM,EAAEI,OAC5B,CAKD,IAHAL,EAAMzC,EAAcsB,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGkB,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAIb,UAAWC,EAAQ,UAI7BgB,EADIpB,GAGAR,EAAM0B,GAGNxB,EACJ0B,EAAGL,EAAQrB,EAAMwB,IAEjBE,EAAGL,GAEJ,GAAc,IAATlB,EACJ,OAAOkB,EAAQjB,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOkB,EAAOS,MAAO5B,EACrB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d5738de..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 4ab1429177de414827696ce660c4b909e4f4c482 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Jan 2023 13:47:28 +0000 Subject: [PATCH 034/109] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 791 ---- .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 184 - .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 59 +- benchmark/benchmark.dispatch_size.js | 156 - benchmark/benchmark.js | 81 - branches.md | 53 - docs/repl.txt | 87 - docs/types/test.ts | 641 ---- examples/add.js | 121 - examples/sin.js | 142 - examples/unary.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/index_of_types.js | 106 - lib/main.js | 230 -- package.json | 77 +- stats.html | 4044 +++++++++++++++++++++ test/fixtures/binary.js | 38 - test/fixtures/fill.js | 76 - test/fixtures/foreach.js | 72 - test/fixtures/map1n.js | 74 - test/fixtures/nullary.js | 36 - test/fixtures/quaternary.js | 40 - test/fixtures/quinary.js | 41 - test/fixtures/sum.js | 98 - test/fixtures/ternary.js | 39 - test/test.js | 363 -- test/test.two_arrays.js | 808 ---- 51 files changed, 4078 insertions(+), 6457 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.dispatch_size.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/add.js delete mode 100644 examples/sin.js delete mode 100644 examples/unary.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/index_of_types.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/fixtures/binary.js delete mode 100644 test/fixtures/fill.js delete mode 100644 test/fixtures/foreach.js delete mode 100644 test/fixtures/map1n.js delete mode 100644 test/fixtures/nullary.js delete mode 100644 test/fixtures/quaternary.js delete mode 100644 test/fixtures/quinary.js delete mode 100644 test/fixtures/sum.js delete mode 100644 test/fixtures/ternary.js delete mode 100644 test/test.js delete mode 100644 test/test.two_arrays.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 971ea5a..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-01-01T01:39:29.422Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ac0b7cd..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 920b304..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 34e41d6..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '43 7 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4eea88..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,791 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -291,7 +284,7 @@ console.log( ybuf ); ## 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. +This package is part of [stdlib][stdlib], a standard library 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]. @@ -353,11 +346,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm diff --git a/benchmark/benchmark.dispatch_size.js b/benchmark/benchmark.dispatch_size.js deleted file mode 100644 index 3bd0418..0000000 --- a/benchmark/benchmark.dispatch_size.js +++ /dev/null @@ -1,156 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib/main.js' ); - - -// FUNCTIONS // - -/** -* Evaluates the identity function. -* -* @private -* @param {*} v - value -* @returns {*} input value -*/ -function identity( v ) { - return v; -} - -/** -* Dummy function which throws an error. -* -* @private -* @throws {Error} unexpected error -*/ -function throwError() { - throw new Error( 'unexpected error' ); -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} size - dispatch size -* @returns {Function} benchmark function -*/ -function createBenchmark( size ) { - var types; - var data; - var fcn; - var x; - var y; - var t; - var i; - - types = []; - - // Create dummy types... - for ( i = 0; i < (size-1)*2; i += 2 ) { - t = 'foo' + i; - types.push( t ); - types.push( t ); - } - // Append test types: - types.push( 'float64' ); - types.push( 'float64' ); - - // Define a list of callbacks: - data = []; - for ( i = 0; i < size-1; i++ ) { - data.push( throwError ); - } - // Append a test callback: - data.push( identity ); - - // Create the dispatcher: - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - // Create sample arrays: - x = new Float64Array( 1 ); - y = new Float64Array( x.length ); - - x = ndarray( 'float64', x, [ 1 ], [ 1 ], 0, 'row-major' ); - y = ndarray( 'float64', y, [ 1 ], [ 1 ], 0, 'row-major' ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var z; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x.data[ 0 ] = i; - z = fcn( x, y ); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var size; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - size = pow( 2, i ); - f = createBenchmark( size ); - bench( pkg+':size='+size, f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index a70dc5c..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::fcns_array', function benchmark( b ) { - var types; - var fcns; - var data; - var out; - var i; - - fcns = [ unary ]; - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( fcns, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::fcn_arg', function benchmark( b ) { - var types; - var data; - var out; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( unary, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index d04d051..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch" -click B href "https://github.com/stdlib-js/ndarray-dispatch/tree/main" -click C href "https://github.com/stdlib-js/ndarray-dispatch/tree/production" -click D href "https://github.com/stdlib-js/ndarray-dispatch/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-dispatch/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-dispatch/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch -[production-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 02fe150..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,87 +0,0 @@ - -{{alias}}( fcns, types, data, nargs, nin, nout ) - Returns an ndarray function interface which performs multiple dispatch. - - An ndarray function interface has the following signature: - - f( x, y, ... ) - - where - - - x: ndarray. - - y: ndarray. - - ...: additional ndarrays. - - The number of parameters is derived from `nargs`, the number of input - ndarrays is derived from `nin`, and the number of output ndarrays is derived - from `nout`. - - Parameters - ---------- - fcns: Function|ArrayLikeObject - List of ndarray functions. An ndarray function should have the following - signature: - - f( arrays, data ) - - where - - - arrays: array containing input and output ndarrays. - - data: ndarray function data (e.g., a callback). - - For convenience, a single ndarray function may be provided which will be - invoked whenever the ndarray argument data types match a sequence of - types in `types`. Providing a single ndarray function is particularly - convenient for the case where, regardless of array data types, - traversing arrays remains the same, but the ndarray function `data` - differs (e.g., callbacks which differ based on the array data types). - - types: ArrayLikeObject - One-dimensional list of ndarray argument data types. - - data: ArrayLikeObject|null - ndarray function data (e.g., callbacks). If `null`, a returned ndarray - function interface does **not** provide a `data` argument to an invoked - ndarray function. - - nargs: integer - Total number of ndarray function interface arguments. - - nin: integer - Number of input ndarrays. - - nout: integer - Number of output ndarrays. - - Returns - ------- - fcn: Function - ndarray function interface. - - Examples - -------- - // Define ndarray argument data types: - > var t = [ 'float64', 'float64', 'float32', 'float32' ]; - - // Define a list of ndarray function data (callbacks): - > var d = [ {{alias:@stdlib/math/base/special/abs}}, {{alias:@stdlib/math/base/special/absf}} ]; - - // Create an ndarray function interface for applying unary callbacks: - > var f = {{alias}}( {{alias:@stdlib/ndarray/base/unary}}, t, d, 2, 1, 1 ); - - // Create an input ndarray: - > var xbuf = new {{alias:@stdlib/array/float64}}( [ -1.0, -2.0, -3.0, -4.0 ] ); - > var x = {{alias:@stdlib/ndarray/ctor}}( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Create an output ndarray: - > var ybuf = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 0.0, 0.0 ] ); - > var y = {{alias:@stdlib/ndarray/ctor}}( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Compute the element-wise absolute value: - > f( x, y ); - > ybuf - [ 1.0, 2.0, 3.0, 4.0 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 397185e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,641 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// tslint:disable:max-file-line-count - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import dispatch = require( './index' ); - - -// FUNCTIONS // - -/** -* Nullary callback. -* -* @return input value -*/ -function nullary(): any { - return 5.0; -} - -/** -* Unary callback. -* -* @param x - input value -* @return input value -*/ -function unary( x: any ): any { - return x; -} - -/** -* Binary callback. -* -* @param x - input value -* @param y - input value -* @return output value -*/ -function binary( x: number, y: number ): number { - return x + y; -} - -/** -* Ternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @return output value -*/ -function ternary( x: number, y: number, z: number ): number { - return x + y + z; -} - -/** -* Quaternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @param w - input value -* @return output value -*/ -function quaternary( x: number, y: number, z: number, w: number ): number { - return x + y + z + w; -} - -/** -* Mock `ind2sub` function. -* -* @param shape - dimensions -* @param idx - linear index -* @param opts - options -* @return subscripts -*/ -function ind2sub( shape: ArrayLike, idx: number, opts?: any ): Array { // tslint:disable-line:max-line-length - let out; - let i; - - out = []; - if ( typeof opts === 'object' && opts !== null && opts.order === 'row-major' ) { // tslint:disable-line:max-line-length no-unsafe-any - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } else { - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } - return out; -} - -/** -* Mock ndarray function. -* -* @param arrays - ndarrays -* @param fcn - callback -*/ -function ndarrayFcn( arrays: Array, fcn: ( x: any ) => any ): void { - let xord; - let yord; - let opts; - let sub; - let sh; - let N; - let x; - let y; - let v; - let i; - - x = arrays[ 0 ]; - y = arrays[ 1 ]; - sh = x.shape; - if ( sh.length === 0 ) { - return; - } - N = 1; - for ( i = 0; i < sh.length; i += 1 ) { - N *= sh[ i ]; - } - xord = x.order; - yord = y.order; - opts = { - 'order': '' - }; - opts.order = xord; - for ( i = 0; i < N; i += 1 ) { - // Convert a linear index to subscripts: - opts.order = xord; - sub = ind2sub( sh, i, opts ); - - // Retrieve an element from `x`: - v = x.get.apply( x, sub ); - - // Convert a linear index to subscripts: - opts.order = yord; - sub = ind2sub( sh, i, opts ); - - // Append the result of applying the callback: - sub[ sub.length ] = fcn( v ) as number; - - // Assign the result to an element in `y`: - y.set.apply( y, sub ); - } -} - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a dispatch function... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, 1 ); // $ExpectType Dispatcher - dispatch( [ ndarrayFcn ], types, data, 2, 1, 1 ); // $ExpectType Dispatcher -} - -// The compiler throws an error if the function is provided a first argument which is not either an ndarray function or an array-like object containing ndarray functions... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( '10', types, data, 2, 1, 1 ); // $ExpectError - dispatch( 10, types, data, 2, 1, 1 ); // $ExpectError - dispatch( true, types, data, 2, 1, 1 ); // $ExpectError - dispatch( false, types, data, 2, 1, 1 ); // $ExpectError - dispatch( null, types, data, 2, 1, 1 ); // $ExpectError - dispatch( undefined, types, data, 2, 1, 1 ); // $ExpectError - dispatch( [ '1' ], types, data, 2, 1, 1 ); // $ExpectError - dispatch( {}, types, data, 2, 1, 1 ); // $ExpectError - dispatch( ( x: number ): number => x, types, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object... -{ - const data = [ unary ]; - - dispatch( ndarrayFcn, 10, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, true, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, false, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, null, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, undefined, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, {}, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object or null... -{ - const types = [ 'float64', 'float64' ]; - - dispatch( ndarrayFcn, types, 10, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, true, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, false, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, undefined, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, {}, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, '10', 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, true, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, false, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, null, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, undefined, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, [ '1' ], 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, {}, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, ( x: number ): number => x, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, '10', 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, true, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, false, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, null, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, undefined, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, [ '1' ], 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, {}, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, ( x: number ): number => x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, '10' ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, true ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, false ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, null ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, undefined ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, [ '1' ] ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, {} ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch(); // $ExpectError - dispatch( ndarrayFcn ); // $ExpectError - dispatch( ndarrayFcn, types ); // $ExpectError - dispatch( ndarrayFcn, types, data ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, 1, 0 ); // $ExpectError -} - -// The function returns a dispatch function... -{ - const x = array(); - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const t1 = [ 'float64' ]; - const d1 = [ nullary ]; - const f1 = dispatch( ndarrayFcn, t1, d1, 1, 1, 0 ); - f1( x ); // $ExpectType void | ndarray - - const t2 = [ 'float64', 'float64' ]; - const d2 = [ unary ]; - const f2 = dispatch( ndarrayFcn, t2, d2, 2, 1, 1 ); - f2( x, y ); // $ExpectType void | ndarray - - const t3 = [ 'float64', 'float64', 'float64' ]; - const d3 = [ binary ]; - const f3 = dispatch( ndarrayFcn, t3, d3, 3, 2, 1 ); - f3( x, y, z ); // $ExpectType void | ndarray - - const t4 = [ 'float64', 'float64', 'float64', 'float64' ]; - const d4 = [ ternary ]; - const f4 = dispatch( ndarrayFcn, t4, d4, 4, 3, 1 ); - f4( x, y, z, w ); // $ExpectType void | ndarray - - const t5 = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const d5 = [ quaternary ]; - const f5 = dispatch( ndarrayFcn, t5, d5, 5, 4, 1 ); - f5( x, y, z, w, u ); // $ExpectType void | ndarray -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (1 ndarray)... -{ - const types = [ 'float64' ]; - const data = [ nullary ]; - - const f = dispatch( ndarrayFcn, types, data, 1, 0, 1 ); - f( '10' ); // $ExpectError - f( 10 ); // $ExpectError - f( true ); // $ExpectError - f( false ); // $ExpectError - f( null ); // $ExpectError - f( undefined ); // $ExpectError - f( [ '1' ] ); // $ExpectError - f( {} ); // $ExpectError - f( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( 10, y ); // $ExpectError - f( '10', y ); // $ExpectError - f( true, y ); // $ExpectError - f( false, y ); // $ExpectError - f( null, y ); // $ExpectError - f( undefined, y ); // $ExpectError - f( [ '1' ], y ); // $ExpectError - f( {}, y ); // $ExpectError - f( ( x: number ): number => x, y ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const x = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( x, 10 ); // $ExpectError - f( x, '10' ); // $ExpectError - f( x, true ); // $ExpectError - f( x, false ); // $ExpectError - f( x, null ); // $ExpectError - f( x, undefined ); // $ExpectError - f( x, [ '1' ] ); // $ExpectError - f( x, {} ); // $ExpectError - f( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( 10, y, z ); // $ExpectError - f( '10', y, z ); // $ExpectError - f( true, y, z ); // $ExpectError - f( false, y, z ); // $ExpectError - f( null, y, z ); // $ExpectError - f( undefined, y, z ); // $ExpectError - f( [ '1' ], y, z ); // $ExpectError - f( {}, y, z ); // $ExpectError - f( ( x: number ): number => x, y, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, 10, z ); // $ExpectError - f( x, '10', z ); // $ExpectError - f( x, true, z ); // $ExpectError - f( x, false, z ); // $ExpectError - f( x, null, z ); // $ExpectError - f( x, undefined, z ); // $ExpectError - f( x, [ '1' ], z ); // $ExpectError - f( x, {}, z ); // $ExpectError - f( x, ( x: number ): number => x, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, y, '10' ); // $ExpectError - f( x, y, true ); // $ExpectError - f( x, y, false ); // $ExpectError - f( x, y, null ); // $ExpectError - f( x, y, undefined ); // $ExpectError - f( x, y, [ '1' ] ); // $ExpectError - f( x, y, {} ); // $ExpectError - f( x, y, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( 10, y, z, w ); // $ExpectError - f( '10', y, z, w ); // $ExpectError - f( true, y, z, w ); // $ExpectError - f( false, y, z, w ); // $ExpectError - f( null, y, z, w ); // $ExpectError - f( undefined, y, z, w ); // $ExpectError - f( [ '1' ], y, z, w ); // $ExpectError - f( {}, y, z, w ); // $ExpectError - f( ( x: number ): number => x, y, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, 10, z, w ); // $ExpectError - f( x, '10', z, w ); // $ExpectError - f( x, true, z, w ); // $ExpectError - f( x, false, z, w ); // $ExpectError - f( x, null, z, w ); // $ExpectError - f( x, undefined, z, w ); // $ExpectError - f( x, [ '1' ], z, w ); // $ExpectError - f( x, {}, z, w ); // $ExpectError - f( x, ( x: number ): number => x, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, 10, w ); // $ExpectError - f( x, y, '10', w ); // $ExpectError - f( x, y, true, w ); // $ExpectError - f( x, y, false, w ); // $ExpectError - f( x, y, null, w ); // $ExpectError - f( x, y, undefined, w ); // $ExpectError - f( x, y, [ '1' ], w ); // $ExpectError - f( x, y, {}, w ); // $ExpectError - f( x, y, ( x: number ): number => x, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, z, 10 ); // $ExpectError - f( x, y, z, '10' ); // $ExpectError - f( x, y, z, true ); // $ExpectError - f( x, y, z, false ); // $ExpectError - f( x, y, z, null ); // $ExpectError - f( x, y, z, undefined ); // $ExpectError - f( x, y, z, [ '1' ] ); // $ExpectError - f( x, y, z, {} ); // $ExpectError - f( x, y, z, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( 10, y, z, w, u ); // $ExpectError - f( '10', y, z, w, u ); // $ExpectError - f( true, y, z, w, u ); // $ExpectError - f( false, y, z, w, u ); // $ExpectError - f( null, y, z, w, u ); // $ExpectError - f( undefined, y, z, w, u ); // $ExpectError - f( [ '1' ], y, z, w, u ); // $ExpectError - f( {}, y, z, w, u ); // $ExpectError - f( ( x: number ): number => x, y, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, 10, z, w, u ); // $ExpectError - f( x, '10', z, w, u ); // $ExpectError - f( x, true, z, w, u ); // $ExpectError - f( x, false, z, w, u ); // $ExpectError - f( x, null, z, w, u ); // $ExpectError - f( x, undefined, z, w, u ); // $ExpectError - f( x, [ '1' ], z, w, u ); // $ExpectError - f( x, {}, z, w, u ); // $ExpectError - f( x, ( x: number ): number => x, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, 10, w, u ); // $ExpectError - f( x, y, '10', w, u ); // $ExpectError - f( x, y, true, w, u ); // $ExpectError - f( x, y, false, w, u ); // $ExpectError - f( x, y, null, w, u ); // $ExpectError - f( x, y, undefined, w, u ); // $ExpectError - f( x, y, [ '1' ], w, u ); // $ExpectError - f( x, y, {}, w, u ); // $ExpectError - f( x, y, ( x: number ): number => x, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, 10, u ); // $ExpectError - f( x, y, z, '10', u ); // $ExpectError - f( x, y, z, true, u ); // $ExpectError - f( x, y, z, false, u ); // $ExpectError - f( x, y, z, null, u ); // $ExpectError - f( x, y, z, undefined, u ); // $ExpectError - f( x, y, z, [ '1' ], u ); // $ExpectError - f( x, y, z, {}, u ); // $ExpectError - f( x, y, z, ( x: number ): number => x, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fifth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, w, 10 ); // $ExpectError - f( x, y, z, w, '10' ); // $ExpectError - f( x, y, z, w, true ); // $ExpectError - f( x, y, z, w, false ); // $ExpectError - f( x, y, z, w, null ); // $ExpectError - f( x, y, z, w, undefined ); // $ExpectError - f( x, y, z, w, [ '1' ] ); // $ExpectError - f( x, y, z, w, {} ); // $ExpectError - f( x, y, z, w, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/add.js b/examples/add.js deleted file mode 100644 index 775b711..0000000 --- a/examples/add.js +++ /dev/null @@ -1,121 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var dispatch = require( './../lib' ); - -function add2( arrays ) { - var opts; - var xo; - var yo; - var zo; - var sx; - var sy; - var sz; - var sh; - var N; - var x; - var y; - var z; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - z = arrays[ 2 ]; - xo = x.order; - yo = y.order; - zo = z.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - opts.order = yo; - sy = ind2sub( sh, i, opts ); - v = x.get.apply( x, sx ) + y.get.apply( y, sy ); - - opts.order = zo; - sz = ind2sub( sh, i, opts ); - sz.push( v ); - z.set.apply( z, sz ); - } -} - -var fcns = [ - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2 -]; - -var types = [ - dtypes.float64, dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.int32, dtypes.int32, - dtypes.uint32, dtypes.uint32, dtypes.uint32, - dtypes.int16, dtypes.int16, dtypes.int16, - dtypes.uint16, dtypes.uint16, dtypes.uint16, - dtypes.int8, dtypes.int8, dtypes.int8, - dtypes.uint8, dtypes.uint8, dtypes.uint8, - dtypes.uint8c, dtypes.uint8c, dtypes.uint8c -]; - -var add = dispatch( fcns, types, null, 3, 2, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var zbuf = new Float64Array( xbuf.length ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var z = ndarray( 'float64', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); - -xbuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -ybuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -zbuf = new Int32Array( xbuf.length ); - -x = ndarray( 'int32', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'int32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -z = ndarray( 'int32', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); diff --git a/examples/sin.js b/examples/sin.js deleted file mode 100644 index 8cd4871..0000000 --- a/examples/sin.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int8Array = require( '@stdlib/array-int8' ); -var sin = require( '@stdlib/math-base-special-sin' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/strided-dtypes' ); -var dispatch = require( './../lib' ); - -function apply( arrays, fcn ) { - var opts; - var xo; - var yo; - var sx; - var sy; - var sh; - var N; - var x; - var y; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - xo = x.order; - yo = y.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - v = fcn( x.get.apply( x, sx ) ); - - opts.order = yo; - sy = ind2sub( sh, i, opts ); - sy.push( v ); - y.set.apply( y, sy ); - } -} - -var fcns = [ - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply -]; - -var types = [ - dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float64, - dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.float64, - dtypes.uint32, dtypes.float64, - dtypes.int16, dtypes.float64, - dtypes.int16, dtypes.float32, - dtypes.uint16, dtypes.float64, - dtypes.uint16, dtypes.float32, - dtypes.int8, dtypes.float64, - dtypes.int8, dtypes.float32, - dtypes.uint8, dtypes.float64, - dtypes.uint8, dtypes.float32, - dtypes.uint8c, dtypes.float64, - dtypes.uint8c, dtypes.float32 -]; - -var data = [ - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin -]; - -var sine = dispatch( fcns, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); - -xbuf = new Int8Array( [ 1, 2, 3, 4, 5 ] ); -ybuf = new Float32Array( xbuf.length ); - -x = ndarray( 'int8', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'float32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); diff --git a/examples/unary.js b/examples/unary.js deleted file mode 100644 index e9c3fb4..0000000 --- a/examples/unary.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -var unary = require( '@stdlib/ndarray-base-unary' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var dispatch = require( './../lib' ); - -var types = [ 'float64', 'float64' ]; - -var data = [ - abs -]; - -var absolute = dispatch( unary, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -absolute( x, y ); -console.log( ybuf ); -// => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 610167d..e8f79c8 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..0509674 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@esm/index.mjs";function l(r,e,t,s,i,n,o,d,m){var l,a,h,f;for(l=n,h=0;h [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0Mq5s', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0Mq3A', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0Mq5u', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0Mq5v', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0Mq5w', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format( '0Mq0h' ) );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format( '0Mq0i' ) );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format( '0Mq0k' ) );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format( '0Mq0l' ) );\n\t\t\t}\n\t\t\tthrow new Error( format( '0Mq0m' ) );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( v.dtype ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format( '0Mq0p' ) );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n"],"names":["indexOfTypes","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","i","j","dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","out","push","resolveEnum","types2enums","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","dtype","slice"],"mappings":";;m1BA6EA,SAASA,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,KAAgBE,EAAGI,GADdE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,CACN,CACD,OAAQ,CACT,CCKA,SAASU,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,sFAAuFV,IAErH,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAQ,UAE1B,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAQ,UAE1B,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAQ,eAI1B,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAQ,UAG3B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAQ,UAG1B,OADAX,EA5GD,SAAsBA,GACrB,IAAIkB,EACAtB,EAGJ,IADAsB,EAAM,GACAtB,EAAI,EAAGA,EAAII,EAAMgB,OAAQpB,IAC9BsB,EAAIC,KAAMC,EAAapB,EAAOJ,KAE/B,OAAOsB,CACR,CAmGSG,CAAarB,GAgBrB,WACC,IAAIsB,EACAC,EACAC,EACAC,EACAC,EACAC,EACA/B,EAGJ,IADA4B,EAAOI,UAAUZ,UACHd,EAAQ,CACrB,GAAKsB,EAAOtB,EACX,MAAM,IAAIa,MAAOJ,EAAQ,UAE1B,MAAM,IAAII,MAAOJ,EAAQ,SACzB,CAGD,IAFAW,EAAS,GACTC,EAAS,GACH3B,EAAI,EAAGA,EAAIM,EAAON,IAAM,CAE7B,IAAMiC,EADNH,EAAIE,UAAWhC,IAEd,MAAKA,EAAIO,EACF,IAAIO,UAAWC,EAAQ,6EAA8Ee,IAErG,IAAIhB,UAAWC,EAAQ,8EAA+Ee,IAG9GJ,EAAOH,KAAMO,GACbH,EAAOJ,KAAMC,EAAaM,EAAEI,OAC5B,CAKD,IAHAL,EAAMzC,EAAcsB,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGkB,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAIb,UAAWC,EAAQ,UAI7BgB,EADIpB,GAGAR,EAAM0B,GAGNxB,EACJ0B,EAAGL,EAAQrB,EAAMwB,IAEjBE,EAAGL,GAEJ,GAAc,IAATlB,EACJ,OAAOkB,EAAQjB,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOkB,EAAOS,MAAO5B,EACrB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 291641d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Create an ndarray function interface which performs multiple dispatch. -* -* @module @stdlib/ndarray-dispatch -* -* @example -* var dispatch = require( '@stdlib/ndarray-dispatch' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/index_of_types.js b/lib/index_of_types.js deleted file mode 100644 index fda2297..0000000 --- a/lib/index_of_types.js +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found). -* -* ## Notes -* -* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types). -* - The function assumes that `x` is stored in row-major order. -* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`. -* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value. -* -* @private -* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension) -* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension) -* @param {ArrayLikeObject} x - input two-dimensional reference array -* @param {integer} strideX1 - `x` stride length along first dimension -* @param {integer} strideX2 - `x` stride length along second dimension -* @param {NonNegativeInteger} offsetX - `x` starting index -* @param {ArrayLikeObject} y - search array -* @param {integer} strideY - `y` stride length -* @param {NonNegativeInteger} offsetY - `y` starting index -* @returns {integer} row index (if found) and `-1` otherwise -* -* @example -* // Define a reference array to search: -* var types = [ -* 'float64', 'float64', 'float64', -* 'float32', 'float32', 'float32', -* 'uint32', 'uint32', 'float64', -* 'int32', 'int32', 'float64', -* 'uint16', 'uint16', 'float64', -* 'int16', 'int16', 'float64', -* 'uint8', 'uint8', 'float64', -* 'int8', 'int8', 'float64' -* ]; -* -* // Define reference array dimensions: -* var N = 8; // rows -* var M = 3; // columns -* -* // Define a search array: -* y1 = [ -* 'float32', 'float32', 'float32', -* ]; -* -* // Find the list of types: -* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 ); -* // returns 1 -* -// Define a search array: -* y2 = [ -* 'float32', 'float32', 'float64', -* ]; -* -* // Find the list of types: -* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 ); -* // returns -1 -*/ -function indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len - var ix; - var iy; - var i; - var j; - - // Search for the first row which matches `y`... - ix = offsetX; - for ( i = 0; i < N; i++ ) { - iy = offsetY; - for ( j = 0; j < M; j++ ) { - if ( x[ ix+(j*strideX2) ] !== y[ iy ] ) { - break; - } - iy += strideY; - } - // If we successfully iterated over all columns, then that means we've found a match... - if ( j === M ) { - return i; - } - ix += strideX1; - } - return -1; -} - - -// EXPORTS // - -module.exports = indexOfTypes; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 7653329..0000000 --- a/lib/main.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isFunctionArray = require( '@stdlib/assert-is-function-array' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var resolveEnum = require( '@stdlib/ndarray-base-dtype-resolve-enum' ); -var indexOfTypes = require( './index_of_types.js' ); - - -// FUNCTIONS // - -/** -* Returns a list of data type enumeration constants. -* -* @private -* @param {Collection} types - list of types -* @returns {IntegerArray} list of data type enumeration constants -*/ -function types2enums( types ) { - var out; - var i; - - out = []; - for ( i = 0; i < types.length; i++ ) { - out.push( resolveEnum( types[ i ] ) ); - } - return out; -} - - -// MAIN // - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param {(FunctionArray|Function)} fcns - list of ndarray functions -* @param {Collection} types - one-dimensional list of ndarray argument data types -* @param {(Collection|null)} data - ndarray function data (e.g., callbacks) -* @param {PositiveInteger} nargs - total number of ndarray function interface arguments -* @param {NonNegativeInteger} nin - number of input ndarrays -* @param {NonNegativeInteger} nout - number of output ndarrays -* @throws {TypeError} first argument must be either a function or an array of functions -* @throws {TypeError} second argument must be an array-like object -* @throws {TypeError} third argument must be an array-like object or `null` -* @throws {Error} third and first arguments must have the same number of elements -* @throws {TypeError} fourth argument must be a positive integer -* @throws {TypeError} fifth argument must be a nonnegative integer -* @throws {TypeError} sixth argument must be a nonnegative integer -* @throws {Error} fourth argument must equal the specified number of input and output arrays -* @throws {Error} number of types must match the number of functions times the total number of array arguments for each function -* @throws {Error} interface must accept at least one input and/or output ndarray -* @returns {Function} ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function dispatch( fcns, types, data, nargs, nin, nout ) { - var narrays; - var nfcns; - var fcn; - - if ( isFunction( fcns ) ) { - fcn = fcns; - } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( '0Mq5s', fcns ) ); - } - if ( !isCollection( types ) ) { - throw new TypeError( format( '0Mq3A', types ) ); - } - if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); - } - if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( '0Mq5u', nargs ) ); - } - if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( '0Mq5v', nin ) ); - } - if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( '0Mq5w', nout ) ); - } - narrays = nin + nout; - if ( narrays === 0 ) { - throw new Error( format( '0Mq0h' ) ); - } - if ( nargs !== narrays ) { - throw new Error( format( '0Mq0i' ) ); - } - if ( fcn ) { - nfcns = types.length / narrays; - if ( !isInteger( nfcns ) ) { - throw new Error( format( '0Mq0j' ) ); - } - } else { - nfcns = fcns.length; - if ( types.length !== nfcns*narrays ) { - throw new Error( format( '0Mq0j' ) ); - } - } - if ( data && data.length !== nfcns ) { - throw new Error( format( '0Mq0k' ) ); - } - types = types2enums( types ); - return dispatcher; - - /** - * ndarray function interface which performs multiple dispatch. - * - * @private - * @param {ndarrayLike} x - ndarray - * @param {...ndarrayLike} args - ndarray arguments - * @throws {Error} insufficient arguments - * @throws {Error} too many arguments - * @throws {TypeError} input array arguments must be ndarray-like objects - * @throws {TypeError} output array arguments must be ndarray-like objects - * @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types - * @returns {(ndarrayLike|Array|void)} destination array(s) - */ - function dispatcher() { - var arrays; - var dtypes; - var argc; - var idx; - var v; - var f; - var i; - - argc = arguments.length; - if ( argc !== nargs ) { - if ( argc < nargs ) { - throw new Error( format( '0Mq0l' ) ); - } - throw new Error( format( '0Mq0m' ) ); - } - arrays = []; - dtypes = []; - for ( i = 0; i < nargs; i++ ) { - v = arguments[ i ]; - if ( !isndarrayLike( v ) ) { - if ( i < nin ) { - throw new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) ); - } else { - throw new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) ); - } - } - arrays.push( v ); - dtypes.push( resolveEnum( v.dtype ) ); - } - // Resolve the ndarray function satisfying the input array types: - idx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len - - // Check whether we were able to successfully resolve an ndarray function: - if ( idx < 0 ) { - throw new TypeError( format( '0Mq0p' ) ); - } - // Retrieve the ndarray function: - if ( fcn ) { - f = fcn; - } else { - f = fcns[ idx ]; - } - // Evaluate the ndarray function: - if ( data ) { - f( arrays, data[ idx ] ); - } else { - f( arrays ); - } - if ( nout === 1 ) { - return arrays[ narrays-1 ]; - } - if ( nout === 0 ) { - return; - } - return arrays.slice( nin ); - } -} - - -// EXPORTS // - -module.exports = dispatch; diff --git a/package.json b/package.json index 8da4654..aab393c 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Create an ndarray function interface which performs multiple dispatch.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,55 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@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-ndarray-like": "^0.0.x", - "@stdlib/assert-is-nonnegative-integer": "^0.0.x", - "@stdlib/assert-is-positive-integer": "^0.0.x", - "@stdlib/ndarray-base-dtype-resolve-enum": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/array-int32": "^0.0.x", - "@stdlib/array-int8": "^0.0.x", - "@stdlib/array-uint8": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/math-base-assert-is-nan": "^0.0.x", - "@stdlib/math-base-special-abs": "^0.0.x", - "@stdlib/math-base-special-pow": "^0.0.x", - "@stdlib/math-base-special-sin": "^0.0.x", - "@stdlib/ndarray-base-buffer-dtype": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/ndarray-base-unary": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/ndarray-dtypes": "^0.0.x", - "@stdlib/ndarray-ind2sub": "^0.0.x", - "@stdlib/strided-dtypes": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "ndarray", @@ -98,7 +26,6 @@ "multimethod", "multimethods" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..3188cba --- /dev/null +++ b/stats.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/fixtures/binary.js b/test/fixtures/binary.js deleted file mode 100644 index a60dfa2..0000000 --- a/test/fixtures/binary.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Binary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @returns {number} sum -*/ -function binary( x, y ) { - return x + y; -} - - -// EXPORTS // - -module.exports = binary; diff --git a/test/fixtures/fill.js b/test/fixtures/fill.js deleted file mode 100644 index 41b2958..0000000 --- a/test/fixtures/fill.js +++ /dev/null @@ -1,76 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which fills one or more ndarrays. -* -* @private -* @param {*} value - fill value -* @returns {Function} ndarray function -*/ -function fill( value ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - */ - function ndarrayFcn( arrays ) { - var opts; - var sub; - var arr; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - opts = { - 'order': '' - }; - for ( j = 0; j < M; j++ ) { - arr = arrays[ j ]; - opts.order = arrays[ j ].order; - for ( i = 0; i < N; i++ ) { - sub = ind2sub( sh, i, opts ); - sub.push( value ); - arr.set.apply( arr, sub ); - } - } - } -} - - -// EXPORTS // - -module.exports = fill; diff --git a/test/fixtures/foreach.js b/test/fixtures/foreach.js deleted file mode 100644 index a426290..0000000 --- a/test/fixtures/foreach.js +++ /dev/null @@ -1,72 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function forEach( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - fcn.apply( null, args ); - } -} - - -// EXPORTS // - -module.exports = forEach; diff --git a/test/fixtures/map1n.js b/test/fixtures/map1n.js deleted file mode 100644 index 614196b..0000000 --- a/test/fixtures/map1n.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function which maps the return value of a callback to `N` arrays. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function map1N( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var v; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - v = fcn(); - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - sub.push( v ); - arrays[ j ].set.apply( arrays[ j ], sub ); - } - } -} - - -// EXPORTS // - -module.exports = map1N; diff --git a/test/fixtures/nullary.js b/test/fixtures/nullary.js deleted file mode 100644 index 4f22126..0000000 --- a/test/fixtures/nullary.js +++ /dev/null @@ -1,36 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Nullary callback. -* -* @private -* @returns {number} value -*/ -function nullary() { - return 3.0; -} - - -// EXPORTS // - -module.exports = nullary; diff --git a/test/fixtures/quaternary.js b/test/fixtures/quaternary.js deleted file mode 100644 index 548437b..0000000 --- a/test/fixtures/quaternary.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quaternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @returns {number} sum -*/ -function quaternary( x, y, z, w ) { - return x + y + z + w; -} - - -// EXPORTS // - -module.exports = quaternary; diff --git a/test/fixtures/quinary.js b/test/fixtures/quinary.js deleted file mode 100644 index 36068de..0000000 --- a/test/fixtures/quinary.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quinary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @param {number} u - input value -* @returns {number} sum -*/ -function quinary( x, y, z, w, u ) { - return x + y + z + w + u; -} - - -// EXPORTS // - -module.exports = quinary; diff --git a/test/fixtures/sum.js b/test/fixtures/sum.js deleted file mode 100644 index efdbb1b..0000000 --- a/test/fixtures/sum.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which computes the sum across one or more ndarrays. -* -* @private -* @param {Object} ctx - context -* @param {number} ctx.sum - initial sum -* @returns {Function} ndarray function -*/ -function wrapper( ctx ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - * @param {Function} [fcn] - callback - */ - function ndarrayFcn( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var f; - var i; - var j; - - if ( arguments.length > 1 ) { - f = fcn; - } - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - if ( f ) { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - ctx.sum += f.apply( null, args ); - } - } else { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - ctx.sum += arrays[ j ].get.apply( arrays[ j ], sub ); - } - } - } - } -} - - -// EXPORTS // - -module.exports = wrapper; diff --git a/test/fixtures/ternary.js b/test/fixtures/ternary.js deleted file mode 100644 index 0595d5f..0000000 --- a/test/fixtures/ternary.js +++ /dev/null @@ -1,39 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Ternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @returns {number} sum -*/ -function ternary( x, y, z ) { - return x + y + z; -} - - -// EXPORTS // - -module.exports = ternary; diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d6c2c8e..0000000 --- a/test/test.js +++ /dev/null @@ -1,363 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var fill = require( './fixtures/fill.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either a function or an array of functions as a first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( value, types, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object as a second argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided either an array-like object or `null` as a third argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - dispatch( unary, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a positive integer for a fourth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 0, - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a fifth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, value, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a sixth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, 1, value ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function array)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var fcns = [ unary, unary, unary ]; - var data = [ abs, abs, abs ]; - dispatch( fcns, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function argument)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs, abs, abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the length of `data` argument does not match the number of ndarray functions', function test( t ) { - var values; - var i; - - values = [ - [], - [ abs, abs ], - [ abs, abs, abs ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var fcns = [ unary ]; - dispatch( fcns, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the fourth argument is incompatible with the number of input and output ndarrays', function test( t ) { - var values; - var i; - - values = [ - 0, - 1, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of specified input and output ndarrays is zero', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var types = [ 'float64' ]; - dispatch( fill( 3 ), types, null, 1, 0, 0 ); - } -}); - -tape( 'the function returns an ndarray function interface', function test( t ) { - var types; - var data; - var f; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - f = dispatch( unary, types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ unary ], types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( fill( 3 ), types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ fill( 3 ) ], types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.two_arrays.js b/test/test.two_arrays.js deleted file mode 100644 index 071500e..0000000 --- a/test/test.two_arrays.js +++ /dev/null @@ -1,808 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var dtype = require( '@stdlib/ndarray-base-buffer-dtype' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var forEach = require( './fixtures/foreach.js' ); -var map1N = require( './fixtures/map1n.js' ); -var fill = require( './fixtures/fill.js' ); -var sum = require( './fixtures/sum.js' ); - - -// TESTS // - -tape( 'the function returns a function which throws an error if not provided an ndarray for the first argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var ybuf = new Float64Array( 10 ); - var y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( value, y ); - }; - } -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the second argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var xbuf = new Float64Array( 10 ); - var x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( x, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided insufficient arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var f; - var x; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [], - [ x ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided too many arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var ybuf; - var f; - var x; - var y; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [ x, y, y ], - [ x, y, y, y ], - [ x, y, y, y, y ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if unable to resolve a ndarray function supporting the provided array argument data types', function test( t ) { - var values; - var types; - var data; - var xbuf; - var fcn; - var x; - var i; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ abs, abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 4 ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - values = [ - new Uint8Array( 4 ), - new Int32Array( 4 ), - [ 0, 0, 0, 0 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided an array having data type: ' + dtype( values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var y = ndarray( dtype( value ), value, [ value.length ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - }; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only input arrays)', function test( t ) { - var types; - var xbuf; - var ybuf; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only output arrays)', function test( t ) { - var expected; - var types; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only input arrays)', function test( t ) { - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var ctx; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcns = [ - sum( ctx ), - sum( ctx ) - ]; - fcn = dispatch( fcns, types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only output arrays)', function test( t ) { - var expected; - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcns = [ - fill( 3.0 ), - fill( 4.0 ) - ]; - fcn = dispatch( fcns, types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - - fcn = dispatch( forEach, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - - fcn = dispatch( map1N, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - fcns = [ - forEach, - forEach - ]; - fcn = dispatch( fcns, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - fcns = [ - map1N, - map1N - ]; - fcn = dispatch( fcns, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - fcns = [ - unary, - unary - ]; - fcn = dispatch( fcns, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which returns one or more output arrays, if one or more output arrays is specified, and otherwise returns `undefined`', function test( t ) { - var types; - var data; - var xbuf; - var ybuf; - var out; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - // No output arrays... - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, void 0, 'returns expected value' ); - - // One output array... - data = [ - abs, - abs - ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - fcn = dispatch( fill( 3.0 ), types, null, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - // Two output arrays... - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.end(); -}); From 567c9366454be1a81aa7b5048874d0265bc19481 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 04:07:57 +0000 Subject: [PATCH 035/109] Transform error messages --- lib/main.js | 28 ++++++++++++++-------------- package.json | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/main.js b/lib/main.js index a19fa68..7653329 100644 --- a/lib/main.js +++ b/lib/main.js @@ -27,7 +27,7 @@ var isFunctionArray = require( '@stdlib/assert-is-function-array' ); var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var resolveEnum = require( '@stdlib/ndarray-base-dtype-resolve-enum' ); var indexOfTypes = require( './index_of_types.js' ); @@ -111,43 +111,43 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { if ( isFunction( fcns ) ) { fcn = fcns; } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) ); + throw new TypeError( format( '0Mq5s', fcns ) ); } if ( !isCollection( types ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) ); + throw new TypeError( format( '0Mq3A', types ) ); } if ( !isCollection( data ) && data !== null ) { throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); } if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) ); + throw new TypeError( format( '0Mq5u', nargs ) ); } if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) ); + throw new TypeError( format( '0Mq5v', nin ) ); } if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) ); + throw new TypeError( format( '0Mq5w', nout ) ); } narrays = nin + nout; if ( narrays === 0 ) { - throw new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' ); + throw new Error( format( '0Mq0h' ) ); } if ( nargs !== narrays ) { - throw new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' ); + throw new Error( format( '0Mq0i' ) ); } if ( fcn ) { nfcns = types.length / narrays; if ( !isInteger( nfcns ) ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format( '0Mq0j' ) ); } } else { nfcns = fcns.length; if ( types.length !== nfcns*narrays ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format( '0Mq0j' ) ); } } if ( data && data.length !== nfcns ) { - throw new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' ); + throw new Error( format( '0Mq0k' ) ); } types = types2enums( types ); return dispatcher; @@ -177,9 +177,9 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { argc = arguments.length; if ( argc !== nargs ) { if ( argc < nargs ) { - throw new Error( 'invalid invocation. Insufficient arguments.' ); + throw new Error( format( '0Mq0l' ) ); } - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format( '0Mq0m' ) ); } arrays = []; dtypes = []; @@ -200,7 +200,7 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { // Check whether we were able to successfully resolve an ndarray function: if ( idx < 0 ) { - throw new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' ); + throw new TypeError( format( '0Mq0p' ) ); } // Retrieve the ndarray function: if ( fcn ) { diff --git a/package.json b/package.json index 753ad9c..8da4654 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/assert-is-nonnegative-integer": "^0.0.x", "@stdlib/assert-is-positive-integer": "^0.0.x", "@stdlib/ndarray-base-dtype-resolve-enum": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From a38e587d4efd9d1bc421d432d18cdb5f3f82c1c3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 12:48:08 +0000 Subject: [PATCH 036/109] Remove files --- index.d.ts | 334 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4383 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index e8f79c8..0000000 --- a/index.d.ts +++ /dev/null @@ -1,334 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* ndarray function. -* -* @param arrays - array containing input and output ndarrays -* @param data - ndarray function data (e.g., a callback) -* -* @example -* var numel = require( `@stdlib/ndarray/base/numel` ); -* var ind2sub = require( `@stdlib/ndarray/ind2sub` ); -* -* function ndarrayFcn( arrays, fcn ) { -* var xord; -* var yord; -* var opts; -* var sub; -* var sh; -* var N; -* var x; -* var y; -* var v; -* var i; -* -* x = arrays[ 0 ]; -* y = arrays[ 1 ]; -* sh = x.shape; -* N = numel( sh ); -* if ( N <= 0 ) { -* return; -* } -* xord = x.order; -* yord = y.order; -* opts = {}; -* opts.order = xord; -* for ( i = 0; i < N; i++ ) { -* // Convert a linear index to subscripts: -* opts.order = xord; -* sub = ind2sub( sh, i, opts ); -* -* // Retrieve an element from `x`: -* v = x.get.apply( x, sub ); -* -* // Convert a linear index to subscripts: -* opts.order = yord; -* sub = ind2sub( sh, i, opts ); -* -* // Append the result of applying the callback: -* sub.push( fcn( v ) ); -* -* // Assign the result to an element in `y`: -* y.set.apply( y, sub ); -* } -* } -*/ -type ndarrayFcn = ( arrays: Array, data?: any ) => void; - -/** -* Interface describing an ndarray function dispatcher. -*/ -interface Dispatcher { - /** - * Invokes an ndarray function based on the provided array data type(s). - * - * @param x - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array - * - * @example - * var nullary = require( `@stdlib/ndarray/base/nullary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function value() { - * return 3.14; - * } - * - * var types = [ 'float64' ]; - * var data = [ value ]; - * - * var fcn = dispatch( nullary, types, data, 1, 0, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( 5 ); - * var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x ); - * // xbuf => [ 3.14, 3.14, 3.14, 3.14, 3.14 ] - */ - ( x: ndarray ): ndarray | void; - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var unary = require( `@stdlib/ndarray/base/unary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * var abs = require( `@stdlib/math/base/special/abs` ); - * - * var types = [ 'float64', 'float64' ]; - * var data = [ abs ]; - * - * var fcn = dispatch( unary, types, data, 2, 1, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - * var ybuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y ); - * // ybuf => [ 1.0, 2.0, 3.0 ] - */ - ( x: ndarray, y: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var ternary = require( `@stdlib/ndarray/base/ternary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add2( x, y ) { - * return x + y; - * } - * - * var types = [ 'float64', 'float64', 'float64' ]; - * var data = [ add2 ]; - * - * var fcn = dispatch( ternary, types, data, 3, 2, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z ); - * // zbuf => [ 2.0, 4.0, 6.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quaternary = require( `@stdlib/ndarray/base/quaternary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add3( x, y, z ) { - * return x + y + z; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add3 ]; - * - * var fcn = dispatch( quaternary, types, data, 4, 3, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w ); - * // wbuf => [ 3.0, 6.0, 9.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @param args - ndarray arguments - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quinary = require( `@stdlib/ndarray/base/quinary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add4( x, y, z, w ) { - * return x + y + z + w; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add4 ]; - * - * var fcn = dispatch( quinary, types, data, 5, 4, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ubuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var u = ndarray( 'float64', ubuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w, u ); - * // ubuf => [ 4.0, 8.0, 12.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray, ...args: Array ): ndarray | void; // tslint:disable-line:max-line-length unified-signatures -} - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param fcns - list of ndarray functions -* @param types - one-dimensional list of ndarray argument data types -* @param data - ndarray function data (e.g., callbacks) -* @param nargs - total number of ndarray function interface arguments -* @param nin - number of input ndarrays -* @param nout - number of output ndarrays -* @throws first argument must be either a function or an array of functions -* @throws second argument must be an array-like object -* @throws third argument must be an array-like object or `null` -* @throws third and first arguments must have the same number of elements -* @throws fourth argument must be a positive integer -* @throws fifth argument must be a nonnegative integer -* @throws sixth argument must be a nonnegative integer -* @throws fourth argument must equal the specified number of input and output arrays -* @throws number of types must match the number of functions times the total number of array arguments for each function -* @throws interface must accept at least one input and/or output ndarray -* @returns ndarray function interface -* -* @example -* var unary = require( `@stdlib/ndarray/base/unary` ); -* var abs = require( `@stdlib/math/base/special/abs` ); -* var Float64Array = require( `@stdlib/array/float64` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var fcn = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* fcn( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function dispatch( fcns: ndarrayFcn | ArrayLike, types: ArrayLike, data: ArrayLike | null, nargs: number, nin: number, nout: number ): Dispatcher; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = dispatch; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 0509674..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@esm/index.mjs";function l(r,e,t,s,i,n,o,d,m){var l,a,h,f;for(l=n,h=0;h [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0Mq5s', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0Mq3A', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0Mq5u', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0Mq5v', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0Mq5w', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format( '0Mq0h' ) );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format( '0Mq0i' ) );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format( '0Mq0k' ) );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format( '0Mq0l' ) );\n\t\t\t}\n\t\t\tthrow new Error( format( '0Mq0m' ) );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( v.dtype ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format( '0Mq0p' ) );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n"],"names":["indexOfTypes","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","i","j","dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","out","push","resolveEnum","types2enums","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","dtype","slice"],"mappings":";;m1BA6EA,SAASA,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,KAAgBE,EAAGI,GADdE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,CACN,CACD,OAAQ,CACT,CCKA,SAASU,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,sFAAuFV,IAErH,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAQ,UAE1B,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAQ,UAE1B,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAQ,eAI1B,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAQ,UAG3B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAQ,UAG1B,OADAX,EA5GD,SAAsBA,GACrB,IAAIkB,EACAtB,EAGJ,IADAsB,EAAM,GACAtB,EAAI,EAAGA,EAAII,EAAMgB,OAAQpB,IAC9BsB,EAAIC,KAAMC,EAAapB,EAAOJ,KAE/B,OAAOsB,CACR,CAmGSG,CAAarB,GAgBrB,WACC,IAAIsB,EACAC,EACAC,EACAC,EACAC,EACAC,EACA/B,EAGJ,IADA4B,EAAOI,UAAUZ,UACHd,EAAQ,CACrB,GAAKsB,EAAOtB,EACX,MAAM,IAAIa,MAAOJ,EAAQ,UAE1B,MAAM,IAAII,MAAOJ,EAAQ,SACzB,CAGD,IAFAW,EAAS,GACTC,EAAS,GACH3B,EAAI,EAAGA,EAAIM,EAAON,IAAM,CAE7B,IAAMiC,EADNH,EAAIE,UAAWhC,IAEd,MAAKA,EAAIO,EACF,IAAIO,UAAWC,EAAQ,6EAA8Ee,IAErG,IAAIhB,UAAWC,EAAQ,8EAA+Ee,IAG9GJ,EAAOH,KAAMO,GACbH,EAAOJ,KAAMC,EAAaM,EAAEI,OAC5B,CAKD,IAHAL,EAAMzC,EAAcsB,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGkB,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAIb,UAAWC,EAAQ,UAI7BgB,EADIpB,GAGAR,EAAM0B,GAGNxB,EACJ0B,EAAGL,EAAQrB,EAAMwB,IAEjBE,EAAGL,GAEJ,GAAc,IAATlB,EACJ,OAAOkB,EAAQjB,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOkB,EAAOS,MAAO5B,EACrB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 3188cba..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From ebf693c46b28775baf199460926efa5615a19c48 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 12:49:09 +0000 Subject: [PATCH 037/109] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 791 --- .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 184 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 59 +- benchmark/benchmark.dispatch_size.js | 156 - benchmark/benchmark.js | 81 - branches.md | 53 - docs/repl.txt | 87 - docs/types/test.ts | 641 --- examples/add.js | 121 - examples/sin.js | 142 - examples/unary.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/index_of_types.js | 106 - lib/main.js | 230 - package.json | 77 +- stats.html | 6177 +++++++++++++++++++++ test/fixtures/binary.js | 38 - test/fixtures/fill.js | 76 - test/fixtures/foreach.js | 72 - test/fixtures/map1n.js | 74 - test/fixtures/nullary.js | 36 - test/fixtures/quaternary.js | 40 - test/fixtures/quinary.js | 41 - test/fixtures/sum.js | 98 - test/fixtures/ternary.js | 39 - test/test.js | 363 -- test/test.two_arrays.js | 808 --- 51 files changed, 6211 insertions(+), 6457 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.dispatch_size.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/add.js delete mode 100644 examples/sin.js delete mode 100644 examples/unary.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/index_of_types.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/fixtures/binary.js delete mode 100644 test/fixtures/fill.js delete mode 100644 test/fixtures/foreach.js delete mode 100644 test/fixtures/map1n.js delete mode 100644 test/fixtures/nullary.js delete mode 100644 test/fixtures/quaternary.js delete mode 100644 test/fixtures/quinary.js delete mode 100644 test/fixtures/sum.js delete mode 100644 test/fixtures/ternary.js delete mode 100644 test/test.js delete mode 100644 test/test.two_arrays.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 5fafece..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-02-01T02:15:03.502Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ac0b7cd..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 920b304..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 34e41d6..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '43 7 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4eea88..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,791 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -291,7 +284,7 @@ console.log( ybuf ); ## 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. +This package is part of [stdlib][stdlib], a standard library 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]. @@ -353,11 +346,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm diff --git a/benchmark/benchmark.dispatch_size.js b/benchmark/benchmark.dispatch_size.js deleted file mode 100644 index 3bd0418..0000000 --- a/benchmark/benchmark.dispatch_size.js +++ /dev/null @@ -1,156 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib/main.js' ); - - -// FUNCTIONS // - -/** -* Evaluates the identity function. -* -* @private -* @param {*} v - value -* @returns {*} input value -*/ -function identity( v ) { - return v; -} - -/** -* Dummy function which throws an error. -* -* @private -* @throws {Error} unexpected error -*/ -function throwError() { - throw new Error( 'unexpected error' ); -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} size - dispatch size -* @returns {Function} benchmark function -*/ -function createBenchmark( size ) { - var types; - var data; - var fcn; - var x; - var y; - var t; - var i; - - types = []; - - // Create dummy types... - for ( i = 0; i < (size-1)*2; i += 2 ) { - t = 'foo' + i; - types.push( t ); - types.push( t ); - } - // Append test types: - types.push( 'float64' ); - types.push( 'float64' ); - - // Define a list of callbacks: - data = []; - for ( i = 0; i < size-1; i++ ) { - data.push( throwError ); - } - // Append a test callback: - data.push( identity ); - - // Create the dispatcher: - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - // Create sample arrays: - x = new Float64Array( 1 ); - y = new Float64Array( x.length ); - - x = ndarray( 'float64', x, [ 1 ], [ 1 ], 0, 'row-major' ); - y = ndarray( 'float64', y, [ 1 ], [ 1 ], 0, 'row-major' ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var z; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x.data[ 0 ] = i; - z = fcn( x, y ); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var size; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - size = pow( 2, i ); - f = createBenchmark( size ); - bench( pkg+':size='+size, f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index a70dc5c..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::fcns_array', function benchmark( b ) { - var types; - var fcns; - var data; - var out; - var i; - - fcns = [ unary ]; - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( fcns, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::fcn_arg', function benchmark( b ) { - var types; - var data; - var out; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( unary, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index d04d051..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch" -click B href "https://github.com/stdlib-js/ndarray-dispatch/tree/main" -click C href "https://github.com/stdlib-js/ndarray-dispatch/tree/production" -click D href "https://github.com/stdlib-js/ndarray-dispatch/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-dispatch/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-dispatch/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch -[production-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 02fe150..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,87 +0,0 @@ - -{{alias}}( fcns, types, data, nargs, nin, nout ) - Returns an ndarray function interface which performs multiple dispatch. - - An ndarray function interface has the following signature: - - f( x, y, ... ) - - where - - - x: ndarray. - - y: ndarray. - - ...: additional ndarrays. - - The number of parameters is derived from `nargs`, the number of input - ndarrays is derived from `nin`, and the number of output ndarrays is derived - from `nout`. - - Parameters - ---------- - fcns: Function|ArrayLikeObject - List of ndarray functions. An ndarray function should have the following - signature: - - f( arrays, data ) - - where - - - arrays: array containing input and output ndarrays. - - data: ndarray function data (e.g., a callback). - - For convenience, a single ndarray function may be provided which will be - invoked whenever the ndarray argument data types match a sequence of - types in `types`. Providing a single ndarray function is particularly - convenient for the case where, regardless of array data types, - traversing arrays remains the same, but the ndarray function `data` - differs (e.g., callbacks which differ based on the array data types). - - types: ArrayLikeObject - One-dimensional list of ndarray argument data types. - - data: ArrayLikeObject|null - ndarray function data (e.g., callbacks). If `null`, a returned ndarray - function interface does **not** provide a `data` argument to an invoked - ndarray function. - - nargs: integer - Total number of ndarray function interface arguments. - - nin: integer - Number of input ndarrays. - - nout: integer - Number of output ndarrays. - - Returns - ------- - fcn: Function - ndarray function interface. - - Examples - -------- - // Define ndarray argument data types: - > var t = [ 'float64', 'float64', 'float32', 'float32' ]; - - // Define a list of ndarray function data (callbacks): - > var d = [ {{alias:@stdlib/math/base/special/abs}}, {{alias:@stdlib/math/base/special/absf}} ]; - - // Create an ndarray function interface for applying unary callbacks: - > var f = {{alias}}( {{alias:@stdlib/ndarray/base/unary}}, t, d, 2, 1, 1 ); - - // Create an input ndarray: - > var xbuf = new {{alias:@stdlib/array/float64}}( [ -1.0, -2.0, -3.0, -4.0 ] ); - > var x = {{alias:@stdlib/ndarray/ctor}}( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Create an output ndarray: - > var ybuf = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 0.0, 0.0 ] ); - > var y = {{alias:@stdlib/ndarray/ctor}}( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Compute the element-wise absolute value: - > f( x, y ); - > ybuf - [ 1.0, 2.0, 3.0, 4.0 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 397185e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,641 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// tslint:disable:max-file-line-count - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import dispatch = require( './index' ); - - -// FUNCTIONS // - -/** -* Nullary callback. -* -* @return input value -*/ -function nullary(): any { - return 5.0; -} - -/** -* Unary callback. -* -* @param x - input value -* @return input value -*/ -function unary( x: any ): any { - return x; -} - -/** -* Binary callback. -* -* @param x - input value -* @param y - input value -* @return output value -*/ -function binary( x: number, y: number ): number { - return x + y; -} - -/** -* Ternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @return output value -*/ -function ternary( x: number, y: number, z: number ): number { - return x + y + z; -} - -/** -* Quaternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @param w - input value -* @return output value -*/ -function quaternary( x: number, y: number, z: number, w: number ): number { - return x + y + z + w; -} - -/** -* Mock `ind2sub` function. -* -* @param shape - dimensions -* @param idx - linear index -* @param opts - options -* @return subscripts -*/ -function ind2sub( shape: ArrayLike, idx: number, opts?: any ): Array { // tslint:disable-line:max-line-length - let out; - let i; - - out = []; - if ( typeof opts === 'object' && opts !== null && opts.order === 'row-major' ) { // tslint:disable-line:max-line-length no-unsafe-any - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } else { - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } - return out; -} - -/** -* Mock ndarray function. -* -* @param arrays - ndarrays -* @param fcn - callback -*/ -function ndarrayFcn( arrays: Array, fcn: ( x: any ) => any ): void { - let xord; - let yord; - let opts; - let sub; - let sh; - let N; - let x; - let y; - let v; - let i; - - x = arrays[ 0 ]; - y = arrays[ 1 ]; - sh = x.shape; - if ( sh.length === 0 ) { - return; - } - N = 1; - for ( i = 0; i < sh.length; i += 1 ) { - N *= sh[ i ]; - } - xord = x.order; - yord = y.order; - opts = { - 'order': '' - }; - opts.order = xord; - for ( i = 0; i < N; i += 1 ) { - // Convert a linear index to subscripts: - opts.order = xord; - sub = ind2sub( sh, i, opts ); - - // Retrieve an element from `x`: - v = x.get.apply( x, sub ); - - // Convert a linear index to subscripts: - opts.order = yord; - sub = ind2sub( sh, i, opts ); - - // Append the result of applying the callback: - sub[ sub.length ] = fcn( v ) as number; - - // Assign the result to an element in `y`: - y.set.apply( y, sub ); - } -} - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a dispatch function... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, 1 ); // $ExpectType Dispatcher - dispatch( [ ndarrayFcn ], types, data, 2, 1, 1 ); // $ExpectType Dispatcher -} - -// The compiler throws an error if the function is provided a first argument which is not either an ndarray function or an array-like object containing ndarray functions... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( '10', types, data, 2, 1, 1 ); // $ExpectError - dispatch( 10, types, data, 2, 1, 1 ); // $ExpectError - dispatch( true, types, data, 2, 1, 1 ); // $ExpectError - dispatch( false, types, data, 2, 1, 1 ); // $ExpectError - dispatch( null, types, data, 2, 1, 1 ); // $ExpectError - dispatch( undefined, types, data, 2, 1, 1 ); // $ExpectError - dispatch( [ '1' ], types, data, 2, 1, 1 ); // $ExpectError - dispatch( {}, types, data, 2, 1, 1 ); // $ExpectError - dispatch( ( x: number ): number => x, types, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object... -{ - const data = [ unary ]; - - dispatch( ndarrayFcn, 10, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, true, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, false, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, null, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, undefined, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, {}, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object or null... -{ - const types = [ 'float64', 'float64' ]; - - dispatch( ndarrayFcn, types, 10, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, true, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, false, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, undefined, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, {}, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, '10', 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, true, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, false, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, null, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, undefined, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, [ '1' ], 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, {}, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, ( x: number ): number => x, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, '10', 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, true, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, false, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, null, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, undefined, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, [ '1' ], 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, {}, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, ( x: number ): number => x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, '10' ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, true ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, false ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, null ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, undefined ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, [ '1' ] ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, {} ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch(); // $ExpectError - dispatch( ndarrayFcn ); // $ExpectError - dispatch( ndarrayFcn, types ); // $ExpectError - dispatch( ndarrayFcn, types, data ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, 1, 0 ); // $ExpectError -} - -// The function returns a dispatch function... -{ - const x = array(); - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const t1 = [ 'float64' ]; - const d1 = [ nullary ]; - const f1 = dispatch( ndarrayFcn, t1, d1, 1, 1, 0 ); - f1( x ); // $ExpectType void | ndarray - - const t2 = [ 'float64', 'float64' ]; - const d2 = [ unary ]; - const f2 = dispatch( ndarrayFcn, t2, d2, 2, 1, 1 ); - f2( x, y ); // $ExpectType void | ndarray - - const t3 = [ 'float64', 'float64', 'float64' ]; - const d3 = [ binary ]; - const f3 = dispatch( ndarrayFcn, t3, d3, 3, 2, 1 ); - f3( x, y, z ); // $ExpectType void | ndarray - - const t4 = [ 'float64', 'float64', 'float64', 'float64' ]; - const d4 = [ ternary ]; - const f4 = dispatch( ndarrayFcn, t4, d4, 4, 3, 1 ); - f4( x, y, z, w ); // $ExpectType void | ndarray - - const t5 = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const d5 = [ quaternary ]; - const f5 = dispatch( ndarrayFcn, t5, d5, 5, 4, 1 ); - f5( x, y, z, w, u ); // $ExpectType void | ndarray -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (1 ndarray)... -{ - const types = [ 'float64' ]; - const data = [ nullary ]; - - const f = dispatch( ndarrayFcn, types, data, 1, 0, 1 ); - f( '10' ); // $ExpectError - f( 10 ); // $ExpectError - f( true ); // $ExpectError - f( false ); // $ExpectError - f( null ); // $ExpectError - f( undefined ); // $ExpectError - f( [ '1' ] ); // $ExpectError - f( {} ); // $ExpectError - f( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( 10, y ); // $ExpectError - f( '10', y ); // $ExpectError - f( true, y ); // $ExpectError - f( false, y ); // $ExpectError - f( null, y ); // $ExpectError - f( undefined, y ); // $ExpectError - f( [ '1' ], y ); // $ExpectError - f( {}, y ); // $ExpectError - f( ( x: number ): number => x, y ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const x = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( x, 10 ); // $ExpectError - f( x, '10' ); // $ExpectError - f( x, true ); // $ExpectError - f( x, false ); // $ExpectError - f( x, null ); // $ExpectError - f( x, undefined ); // $ExpectError - f( x, [ '1' ] ); // $ExpectError - f( x, {} ); // $ExpectError - f( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( 10, y, z ); // $ExpectError - f( '10', y, z ); // $ExpectError - f( true, y, z ); // $ExpectError - f( false, y, z ); // $ExpectError - f( null, y, z ); // $ExpectError - f( undefined, y, z ); // $ExpectError - f( [ '1' ], y, z ); // $ExpectError - f( {}, y, z ); // $ExpectError - f( ( x: number ): number => x, y, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, 10, z ); // $ExpectError - f( x, '10', z ); // $ExpectError - f( x, true, z ); // $ExpectError - f( x, false, z ); // $ExpectError - f( x, null, z ); // $ExpectError - f( x, undefined, z ); // $ExpectError - f( x, [ '1' ], z ); // $ExpectError - f( x, {}, z ); // $ExpectError - f( x, ( x: number ): number => x, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, y, '10' ); // $ExpectError - f( x, y, true ); // $ExpectError - f( x, y, false ); // $ExpectError - f( x, y, null ); // $ExpectError - f( x, y, undefined ); // $ExpectError - f( x, y, [ '1' ] ); // $ExpectError - f( x, y, {} ); // $ExpectError - f( x, y, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( 10, y, z, w ); // $ExpectError - f( '10', y, z, w ); // $ExpectError - f( true, y, z, w ); // $ExpectError - f( false, y, z, w ); // $ExpectError - f( null, y, z, w ); // $ExpectError - f( undefined, y, z, w ); // $ExpectError - f( [ '1' ], y, z, w ); // $ExpectError - f( {}, y, z, w ); // $ExpectError - f( ( x: number ): number => x, y, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, 10, z, w ); // $ExpectError - f( x, '10', z, w ); // $ExpectError - f( x, true, z, w ); // $ExpectError - f( x, false, z, w ); // $ExpectError - f( x, null, z, w ); // $ExpectError - f( x, undefined, z, w ); // $ExpectError - f( x, [ '1' ], z, w ); // $ExpectError - f( x, {}, z, w ); // $ExpectError - f( x, ( x: number ): number => x, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, 10, w ); // $ExpectError - f( x, y, '10', w ); // $ExpectError - f( x, y, true, w ); // $ExpectError - f( x, y, false, w ); // $ExpectError - f( x, y, null, w ); // $ExpectError - f( x, y, undefined, w ); // $ExpectError - f( x, y, [ '1' ], w ); // $ExpectError - f( x, y, {}, w ); // $ExpectError - f( x, y, ( x: number ): number => x, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, z, 10 ); // $ExpectError - f( x, y, z, '10' ); // $ExpectError - f( x, y, z, true ); // $ExpectError - f( x, y, z, false ); // $ExpectError - f( x, y, z, null ); // $ExpectError - f( x, y, z, undefined ); // $ExpectError - f( x, y, z, [ '1' ] ); // $ExpectError - f( x, y, z, {} ); // $ExpectError - f( x, y, z, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( 10, y, z, w, u ); // $ExpectError - f( '10', y, z, w, u ); // $ExpectError - f( true, y, z, w, u ); // $ExpectError - f( false, y, z, w, u ); // $ExpectError - f( null, y, z, w, u ); // $ExpectError - f( undefined, y, z, w, u ); // $ExpectError - f( [ '1' ], y, z, w, u ); // $ExpectError - f( {}, y, z, w, u ); // $ExpectError - f( ( x: number ): number => x, y, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, 10, z, w, u ); // $ExpectError - f( x, '10', z, w, u ); // $ExpectError - f( x, true, z, w, u ); // $ExpectError - f( x, false, z, w, u ); // $ExpectError - f( x, null, z, w, u ); // $ExpectError - f( x, undefined, z, w, u ); // $ExpectError - f( x, [ '1' ], z, w, u ); // $ExpectError - f( x, {}, z, w, u ); // $ExpectError - f( x, ( x: number ): number => x, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, 10, w, u ); // $ExpectError - f( x, y, '10', w, u ); // $ExpectError - f( x, y, true, w, u ); // $ExpectError - f( x, y, false, w, u ); // $ExpectError - f( x, y, null, w, u ); // $ExpectError - f( x, y, undefined, w, u ); // $ExpectError - f( x, y, [ '1' ], w, u ); // $ExpectError - f( x, y, {}, w, u ); // $ExpectError - f( x, y, ( x: number ): number => x, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, 10, u ); // $ExpectError - f( x, y, z, '10', u ); // $ExpectError - f( x, y, z, true, u ); // $ExpectError - f( x, y, z, false, u ); // $ExpectError - f( x, y, z, null, u ); // $ExpectError - f( x, y, z, undefined, u ); // $ExpectError - f( x, y, z, [ '1' ], u ); // $ExpectError - f( x, y, z, {}, u ); // $ExpectError - f( x, y, z, ( x: number ): number => x, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fifth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, w, 10 ); // $ExpectError - f( x, y, z, w, '10' ); // $ExpectError - f( x, y, z, w, true ); // $ExpectError - f( x, y, z, w, false ); // $ExpectError - f( x, y, z, w, null ); // $ExpectError - f( x, y, z, w, undefined ); // $ExpectError - f( x, y, z, w, [ '1' ] ); // $ExpectError - f( x, y, z, w, {} ); // $ExpectError - f( x, y, z, w, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/add.js b/examples/add.js deleted file mode 100644 index 775b711..0000000 --- a/examples/add.js +++ /dev/null @@ -1,121 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var dispatch = require( './../lib' ); - -function add2( arrays ) { - var opts; - var xo; - var yo; - var zo; - var sx; - var sy; - var sz; - var sh; - var N; - var x; - var y; - var z; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - z = arrays[ 2 ]; - xo = x.order; - yo = y.order; - zo = z.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - opts.order = yo; - sy = ind2sub( sh, i, opts ); - v = x.get.apply( x, sx ) + y.get.apply( y, sy ); - - opts.order = zo; - sz = ind2sub( sh, i, opts ); - sz.push( v ); - z.set.apply( z, sz ); - } -} - -var fcns = [ - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2 -]; - -var types = [ - dtypes.float64, dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.int32, dtypes.int32, - dtypes.uint32, dtypes.uint32, dtypes.uint32, - dtypes.int16, dtypes.int16, dtypes.int16, - dtypes.uint16, dtypes.uint16, dtypes.uint16, - dtypes.int8, dtypes.int8, dtypes.int8, - dtypes.uint8, dtypes.uint8, dtypes.uint8, - dtypes.uint8c, dtypes.uint8c, dtypes.uint8c -]; - -var add = dispatch( fcns, types, null, 3, 2, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var zbuf = new Float64Array( xbuf.length ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var z = ndarray( 'float64', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); - -xbuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -ybuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -zbuf = new Int32Array( xbuf.length ); - -x = ndarray( 'int32', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'int32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -z = ndarray( 'int32', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); diff --git a/examples/sin.js b/examples/sin.js deleted file mode 100644 index 8cd4871..0000000 --- a/examples/sin.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int8Array = require( '@stdlib/array-int8' ); -var sin = require( '@stdlib/math-base-special-sin' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/strided-dtypes' ); -var dispatch = require( './../lib' ); - -function apply( arrays, fcn ) { - var opts; - var xo; - var yo; - var sx; - var sy; - var sh; - var N; - var x; - var y; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - xo = x.order; - yo = y.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - v = fcn( x.get.apply( x, sx ) ); - - opts.order = yo; - sy = ind2sub( sh, i, opts ); - sy.push( v ); - y.set.apply( y, sy ); - } -} - -var fcns = [ - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply -]; - -var types = [ - dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float64, - dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.float64, - dtypes.uint32, dtypes.float64, - dtypes.int16, dtypes.float64, - dtypes.int16, dtypes.float32, - dtypes.uint16, dtypes.float64, - dtypes.uint16, dtypes.float32, - dtypes.int8, dtypes.float64, - dtypes.int8, dtypes.float32, - dtypes.uint8, dtypes.float64, - dtypes.uint8, dtypes.float32, - dtypes.uint8c, dtypes.float64, - dtypes.uint8c, dtypes.float32 -]; - -var data = [ - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin -]; - -var sine = dispatch( fcns, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); - -xbuf = new Int8Array( [ 1, 2, 3, 4, 5 ] ); -ybuf = new Float32Array( xbuf.length ); - -x = ndarray( 'int8', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'float32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); diff --git a/examples/unary.js b/examples/unary.js deleted file mode 100644 index e9c3fb4..0000000 --- a/examples/unary.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -var unary = require( '@stdlib/ndarray-base-unary' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var dispatch = require( './../lib' ); - -var types = [ 'float64', 'float64' ]; - -var data = [ - abs -]; - -var absolute = dispatch( unary, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -absolute( x, y ); -console.log( ybuf ); -// => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 610167d..e8f79c8 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..359fc1e --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@esm/index.mjs";function l(r,e,t,s,i,n,o,d,m){var l,a,h,f;for(l=n,h=0;h [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0Mq5s', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0Mq3A', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0Mq5u', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0Mq5v', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0Mq5w', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format( '0Mq0h' ) );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format( '0Mq0i' ) );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format( '0Mq0k' ) );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format( '0Mq0l' ) );\n\t\t\t}\n\t\t\tthrow new Error( format( '0Mq0m' ) );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( v.dtype ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format( '0Mq0p' ) );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n"],"names":["indexOfTypes","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","i","j","dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","out","push","resolveEnum","types2enums","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","dtype","slice"],"mappings":";;01BA6EA,SAASA,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,KAAgBE,EAAGI,GADdE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,CACN,CACD,OAAQ,CACT,CCKA,SAASU,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,sFAAuFV,IAErH,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAQ,UAE1B,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAQ,UAE1B,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAQ,eAI1B,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAQ,UAG3B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAQ,UAG1B,OADAX,EA5GD,SAAsBA,GACrB,IAAIkB,EACAtB,EAGJ,IADAsB,EAAM,GACAtB,EAAI,EAAGA,EAAII,EAAMgB,OAAQpB,IAC9BsB,EAAIC,KAAMC,EAAapB,EAAOJ,KAE/B,OAAOsB,CACR,CAmGSG,CAAarB,GAgBrB,WACC,IAAIsB,EACAC,EACAC,EACAC,EACAC,EACAC,EACA/B,EAGJ,IADA4B,EAAOI,UAAUZ,UACHd,EAAQ,CACrB,GAAKsB,EAAOtB,EACX,MAAM,IAAIa,MAAOJ,EAAQ,UAE1B,MAAM,IAAII,MAAOJ,EAAQ,SACzB,CAGD,IAFAW,EAAS,GACTC,EAAS,GACH3B,EAAI,EAAGA,EAAIM,EAAON,IAAM,CAE7B,IAAMiC,EADNH,EAAIE,UAAWhC,IAEd,MAAKA,EAAIO,EACF,IAAIO,UAAWC,EAAQ,6EAA8Ee,IAErG,IAAIhB,UAAWC,EAAQ,8EAA+Ee,IAG9GJ,EAAOH,KAAMO,GACbH,EAAOJ,KAAMC,EAAaM,EAAEI,OAC5B,CAKD,IAHAL,EAAMzC,EAAcsB,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGkB,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAIb,UAAWC,EAAQ,UAI7BgB,EADIpB,GAGAR,EAAM0B,GAGNxB,EACJ0B,EAAGL,EAAQrB,EAAMwB,IAEjBE,EAAGL,GAEJ,GAAc,IAATlB,EACJ,OAAOkB,EAAQjB,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOkB,EAAOS,MAAO5B,EACrB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 291641d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Create an ndarray function interface which performs multiple dispatch. -* -* @module @stdlib/ndarray-dispatch -* -* @example -* var dispatch = require( '@stdlib/ndarray-dispatch' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/index_of_types.js b/lib/index_of_types.js deleted file mode 100644 index fda2297..0000000 --- a/lib/index_of_types.js +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found). -* -* ## Notes -* -* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types). -* - The function assumes that `x` is stored in row-major order. -* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`. -* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value. -* -* @private -* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension) -* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension) -* @param {ArrayLikeObject} x - input two-dimensional reference array -* @param {integer} strideX1 - `x` stride length along first dimension -* @param {integer} strideX2 - `x` stride length along second dimension -* @param {NonNegativeInteger} offsetX - `x` starting index -* @param {ArrayLikeObject} y - search array -* @param {integer} strideY - `y` stride length -* @param {NonNegativeInteger} offsetY - `y` starting index -* @returns {integer} row index (if found) and `-1` otherwise -* -* @example -* // Define a reference array to search: -* var types = [ -* 'float64', 'float64', 'float64', -* 'float32', 'float32', 'float32', -* 'uint32', 'uint32', 'float64', -* 'int32', 'int32', 'float64', -* 'uint16', 'uint16', 'float64', -* 'int16', 'int16', 'float64', -* 'uint8', 'uint8', 'float64', -* 'int8', 'int8', 'float64' -* ]; -* -* // Define reference array dimensions: -* var N = 8; // rows -* var M = 3; // columns -* -* // Define a search array: -* y1 = [ -* 'float32', 'float32', 'float32', -* ]; -* -* // Find the list of types: -* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 ); -* // returns 1 -* -// Define a search array: -* y2 = [ -* 'float32', 'float32', 'float64', -* ]; -* -* // Find the list of types: -* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 ); -* // returns -1 -*/ -function indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len - var ix; - var iy; - var i; - var j; - - // Search for the first row which matches `y`... - ix = offsetX; - for ( i = 0; i < N; i++ ) { - iy = offsetY; - for ( j = 0; j < M; j++ ) { - if ( x[ ix+(j*strideX2) ] !== y[ iy ] ) { - break; - } - iy += strideY; - } - // If we successfully iterated over all columns, then that means we've found a match... - if ( j === M ) { - return i; - } - ix += strideX1; - } - return -1; -} - - -// EXPORTS // - -module.exports = indexOfTypes; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 7653329..0000000 --- a/lib/main.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isFunctionArray = require( '@stdlib/assert-is-function-array' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var resolveEnum = require( '@stdlib/ndarray-base-dtype-resolve-enum' ); -var indexOfTypes = require( './index_of_types.js' ); - - -// FUNCTIONS // - -/** -* Returns a list of data type enumeration constants. -* -* @private -* @param {Collection} types - list of types -* @returns {IntegerArray} list of data type enumeration constants -*/ -function types2enums( types ) { - var out; - var i; - - out = []; - for ( i = 0; i < types.length; i++ ) { - out.push( resolveEnum( types[ i ] ) ); - } - return out; -} - - -// MAIN // - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param {(FunctionArray|Function)} fcns - list of ndarray functions -* @param {Collection} types - one-dimensional list of ndarray argument data types -* @param {(Collection|null)} data - ndarray function data (e.g., callbacks) -* @param {PositiveInteger} nargs - total number of ndarray function interface arguments -* @param {NonNegativeInteger} nin - number of input ndarrays -* @param {NonNegativeInteger} nout - number of output ndarrays -* @throws {TypeError} first argument must be either a function or an array of functions -* @throws {TypeError} second argument must be an array-like object -* @throws {TypeError} third argument must be an array-like object or `null` -* @throws {Error} third and first arguments must have the same number of elements -* @throws {TypeError} fourth argument must be a positive integer -* @throws {TypeError} fifth argument must be a nonnegative integer -* @throws {TypeError} sixth argument must be a nonnegative integer -* @throws {Error} fourth argument must equal the specified number of input and output arrays -* @throws {Error} number of types must match the number of functions times the total number of array arguments for each function -* @throws {Error} interface must accept at least one input and/or output ndarray -* @returns {Function} ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function dispatch( fcns, types, data, nargs, nin, nout ) { - var narrays; - var nfcns; - var fcn; - - if ( isFunction( fcns ) ) { - fcn = fcns; - } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( '0Mq5s', fcns ) ); - } - if ( !isCollection( types ) ) { - throw new TypeError( format( '0Mq3A', types ) ); - } - if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); - } - if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( '0Mq5u', nargs ) ); - } - if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( '0Mq5v', nin ) ); - } - if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( '0Mq5w', nout ) ); - } - narrays = nin + nout; - if ( narrays === 0 ) { - throw new Error( format( '0Mq0h' ) ); - } - if ( nargs !== narrays ) { - throw new Error( format( '0Mq0i' ) ); - } - if ( fcn ) { - nfcns = types.length / narrays; - if ( !isInteger( nfcns ) ) { - throw new Error( format( '0Mq0j' ) ); - } - } else { - nfcns = fcns.length; - if ( types.length !== nfcns*narrays ) { - throw new Error( format( '0Mq0j' ) ); - } - } - if ( data && data.length !== nfcns ) { - throw new Error( format( '0Mq0k' ) ); - } - types = types2enums( types ); - return dispatcher; - - /** - * ndarray function interface which performs multiple dispatch. - * - * @private - * @param {ndarrayLike} x - ndarray - * @param {...ndarrayLike} args - ndarray arguments - * @throws {Error} insufficient arguments - * @throws {Error} too many arguments - * @throws {TypeError} input array arguments must be ndarray-like objects - * @throws {TypeError} output array arguments must be ndarray-like objects - * @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types - * @returns {(ndarrayLike|Array|void)} destination array(s) - */ - function dispatcher() { - var arrays; - var dtypes; - var argc; - var idx; - var v; - var f; - var i; - - argc = arguments.length; - if ( argc !== nargs ) { - if ( argc < nargs ) { - throw new Error( format( '0Mq0l' ) ); - } - throw new Error( format( '0Mq0m' ) ); - } - arrays = []; - dtypes = []; - for ( i = 0; i < nargs; i++ ) { - v = arguments[ i ]; - if ( !isndarrayLike( v ) ) { - if ( i < nin ) { - throw new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) ); - } else { - throw new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) ); - } - } - arrays.push( v ); - dtypes.push( resolveEnum( v.dtype ) ); - } - // Resolve the ndarray function satisfying the input array types: - idx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len - - // Check whether we were able to successfully resolve an ndarray function: - if ( idx < 0 ) { - throw new TypeError( format( '0Mq0p' ) ); - } - // Retrieve the ndarray function: - if ( fcn ) { - f = fcn; - } else { - f = fcns[ idx ]; - } - // Evaluate the ndarray function: - if ( data ) { - f( arrays, data[ idx ] ); - } else { - f( arrays ); - } - if ( nout === 1 ) { - return arrays[ narrays-1 ]; - } - if ( nout === 0 ) { - return; - } - return arrays.slice( nin ); - } -} - - -// EXPORTS // - -module.exports = dispatch; diff --git a/package.json b/package.json index 8da4654..aab393c 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Create an ndarray function interface which performs multiple dispatch.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,55 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@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-ndarray-like": "^0.0.x", - "@stdlib/assert-is-nonnegative-integer": "^0.0.x", - "@stdlib/assert-is-positive-integer": "^0.0.x", - "@stdlib/ndarray-base-dtype-resolve-enum": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/array-int32": "^0.0.x", - "@stdlib/array-int8": "^0.0.x", - "@stdlib/array-uint8": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/math-base-assert-is-nan": "^0.0.x", - "@stdlib/math-base-special-abs": "^0.0.x", - "@stdlib/math-base-special-pow": "^0.0.x", - "@stdlib/math-base-special-sin": "^0.0.x", - "@stdlib/ndarray-base-buffer-dtype": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/ndarray-base-unary": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/ndarray-dtypes": "^0.0.x", - "@stdlib/ndarray-ind2sub": "^0.0.x", - "@stdlib/strided-dtypes": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "ndarray", @@ -98,7 +26,6 @@ "multimethod", "multimethods" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..d17478d --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/fixtures/binary.js b/test/fixtures/binary.js deleted file mode 100644 index a60dfa2..0000000 --- a/test/fixtures/binary.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Binary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @returns {number} sum -*/ -function binary( x, y ) { - return x + y; -} - - -// EXPORTS // - -module.exports = binary; diff --git a/test/fixtures/fill.js b/test/fixtures/fill.js deleted file mode 100644 index 41b2958..0000000 --- a/test/fixtures/fill.js +++ /dev/null @@ -1,76 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which fills one or more ndarrays. -* -* @private -* @param {*} value - fill value -* @returns {Function} ndarray function -*/ -function fill( value ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - */ - function ndarrayFcn( arrays ) { - var opts; - var sub; - var arr; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - opts = { - 'order': '' - }; - for ( j = 0; j < M; j++ ) { - arr = arrays[ j ]; - opts.order = arrays[ j ].order; - for ( i = 0; i < N; i++ ) { - sub = ind2sub( sh, i, opts ); - sub.push( value ); - arr.set.apply( arr, sub ); - } - } - } -} - - -// EXPORTS // - -module.exports = fill; diff --git a/test/fixtures/foreach.js b/test/fixtures/foreach.js deleted file mode 100644 index a426290..0000000 --- a/test/fixtures/foreach.js +++ /dev/null @@ -1,72 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function forEach( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - fcn.apply( null, args ); - } -} - - -// EXPORTS // - -module.exports = forEach; diff --git a/test/fixtures/map1n.js b/test/fixtures/map1n.js deleted file mode 100644 index 614196b..0000000 --- a/test/fixtures/map1n.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function which maps the return value of a callback to `N` arrays. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function map1N( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var v; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - v = fcn(); - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - sub.push( v ); - arrays[ j ].set.apply( arrays[ j ], sub ); - } - } -} - - -// EXPORTS // - -module.exports = map1N; diff --git a/test/fixtures/nullary.js b/test/fixtures/nullary.js deleted file mode 100644 index 4f22126..0000000 --- a/test/fixtures/nullary.js +++ /dev/null @@ -1,36 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Nullary callback. -* -* @private -* @returns {number} value -*/ -function nullary() { - return 3.0; -} - - -// EXPORTS // - -module.exports = nullary; diff --git a/test/fixtures/quaternary.js b/test/fixtures/quaternary.js deleted file mode 100644 index 548437b..0000000 --- a/test/fixtures/quaternary.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quaternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @returns {number} sum -*/ -function quaternary( x, y, z, w ) { - return x + y + z + w; -} - - -// EXPORTS // - -module.exports = quaternary; diff --git a/test/fixtures/quinary.js b/test/fixtures/quinary.js deleted file mode 100644 index 36068de..0000000 --- a/test/fixtures/quinary.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quinary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @param {number} u - input value -* @returns {number} sum -*/ -function quinary( x, y, z, w, u ) { - return x + y + z + w + u; -} - - -// EXPORTS // - -module.exports = quinary; diff --git a/test/fixtures/sum.js b/test/fixtures/sum.js deleted file mode 100644 index efdbb1b..0000000 --- a/test/fixtures/sum.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which computes the sum across one or more ndarrays. -* -* @private -* @param {Object} ctx - context -* @param {number} ctx.sum - initial sum -* @returns {Function} ndarray function -*/ -function wrapper( ctx ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - * @param {Function} [fcn] - callback - */ - function ndarrayFcn( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var f; - var i; - var j; - - if ( arguments.length > 1 ) { - f = fcn; - } - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - if ( f ) { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - ctx.sum += f.apply( null, args ); - } - } else { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - ctx.sum += arrays[ j ].get.apply( arrays[ j ], sub ); - } - } - } - } -} - - -// EXPORTS // - -module.exports = wrapper; diff --git a/test/fixtures/ternary.js b/test/fixtures/ternary.js deleted file mode 100644 index 0595d5f..0000000 --- a/test/fixtures/ternary.js +++ /dev/null @@ -1,39 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Ternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @returns {number} sum -*/ -function ternary( x, y, z ) { - return x + y + z; -} - - -// EXPORTS // - -module.exports = ternary; diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d6c2c8e..0000000 --- a/test/test.js +++ /dev/null @@ -1,363 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var fill = require( './fixtures/fill.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either a function or an array of functions as a first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( value, types, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object as a second argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided either an array-like object or `null` as a third argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - dispatch( unary, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a positive integer for a fourth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 0, - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a fifth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, value, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a sixth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, 1, value ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function array)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var fcns = [ unary, unary, unary ]; - var data = [ abs, abs, abs ]; - dispatch( fcns, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function argument)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs, abs, abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the length of `data` argument does not match the number of ndarray functions', function test( t ) { - var values; - var i; - - values = [ - [], - [ abs, abs ], - [ abs, abs, abs ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var fcns = [ unary ]; - dispatch( fcns, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the fourth argument is incompatible with the number of input and output ndarrays', function test( t ) { - var values; - var i; - - values = [ - 0, - 1, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of specified input and output ndarrays is zero', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var types = [ 'float64' ]; - dispatch( fill( 3 ), types, null, 1, 0, 0 ); - } -}); - -tape( 'the function returns an ndarray function interface', function test( t ) { - var types; - var data; - var f; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - f = dispatch( unary, types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ unary ], types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( fill( 3 ), types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ fill( 3 ) ], types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.two_arrays.js b/test/test.two_arrays.js deleted file mode 100644 index 071500e..0000000 --- a/test/test.two_arrays.js +++ /dev/null @@ -1,808 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var dtype = require( '@stdlib/ndarray-base-buffer-dtype' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var forEach = require( './fixtures/foreach.js' ); -var map1N = require( './fixtures/map1n.js' ); -var fill = require( './fixtures/fill.js' ); -var sum = require( './fixtures/sum.js' ); - - -// TESTS // - -tape( 'the function returns a function which throws an error if not provided an ndarray for the first argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var ybuf = new Float64Array( 10 ); - var y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( value, y ); - }; - } -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the second argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var xbuf = new Float64Array( 10 ); - var x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( x, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided insufficient arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var f; - var x; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [], - [ x ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided too many arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var ybuf; - var f; - var x; - var y; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [ x, y, y ], - [ x, y, y, y ], - [ x, y, y, y, y ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if unable to resolve a ndarray function supporting the provided array argument data types', function test( t ) { - var values; - var types; - var data; - var xbuf; - var fcn; - var x; - var i; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ abs, abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 4 ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - values = [ - new Uint8Array( 4 ), - new Int32Array( 4 ), - [ 0, 0, 0, 0 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided an array having data type: ' + dtype( values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var y = ndarray( dtype( value ), value, [ value.length ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - }; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only input arrays)', function test( t ) { - var types; - var xbuf; - var ybuf; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only output arrays)', function test( t ) { - var expected; - var types; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only input arrays)', function test( t ) { - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var ctx; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcns = [ - sum( ctx ), - sum( ctx ) - ]; - fcn = dispatch( fcns, types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only output arrays)', function test( t ) { - var expected; - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcns = [ - fill( 3.0 ), - fill( 4.0 ) - ]; - fcn = dispatch( fcns, types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - - fcn = dispatch( forEach, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - - fcn = dispatch( map1N, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - fcns = [ - forEach, - forEach - ]; - fcn = dispatch( fcns, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - fcns = [ - map1N, - map1N - ]; - fcn = dispatch( fcns, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - fcns = [ - unary, - unary - ]; - fcn = dispatch( fcns, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which returns one or more output arrays, if one or more output arrays is specified, and otherwise returns `undefined`', function test( t ) { - var types; - var data; - var xbuf; - var ybuf; - var out; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - // No output arrays... - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, void 0, 'returns expected value' ); - - // One output array... - data = [ - abs, - abs - ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - fcn = dispatch( fill( 3.0 ), types, null, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - // Two output arrays... - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.end(); -}); From 75944687b67df2d9bfa5d47a86882888090dbc7f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Jun 2023 09:51:11 +0000 Subject: [PATCH 038/109] Transform error messages --- lib/main.js | 28 ++++++++++++++-------------- package.json | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/main.js b/lib/main.js index a19fa68..7653329 100644 --- a/lib/main.js +++ b/lib/main.js @@ -27,7 +27,7 @@ var isFunctionArray = require( '@stdlib/assert-is-function-array' ); var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var resolveEnum = require( '@stdlib/ndarray-base-dtype-resolve-enum' ); var indexOfTypes = require( './index_of_types.js' ); @@ -111,43 +111,43 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { if ( isFunction( fcns ) ) { fcn = fcns; } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) ); + throw new TypeError( format( '0Mq5s', fcns ) ); } if ( !isCollection( types ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) ); + throw new TypeError( format( '0Mq3A', types ) ); } if ( !isCollection( data ) && data !== null ) { throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); } if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) ); + throw new TypeError( format( '0Mq5u', nargs ) ); } if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) ); + throw new TypeError( format( '0Mq5v', nin ) ); } if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) ); + throw new TypeError( format( '0Mq5w', nout ) ); } narrays = nin + nout; if ( narrays === 0 ) { - throw new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' ); + throw new Error( format( '0Mq0h' ) ); } if ( nargs !== narrays ) { - throw new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' ); + throw new Error( format( '0Mq0i' ) ); } if ( fcn ) { nfcns = types.length / narrays; if ( !isInteger( nfcns ) ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format( '0Mq0j' ) ); } } else { nfcns = fcns.length; if ( types.length !== nfcns*narrays ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format( '0Mq0j' ) ); } } if ( data && data.length !== nfcns ) { - throw new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' ); + throw new Error( format( '0Mq0k' ) ); } types = types2enums( types ); return dispatcher; @@ -177,9 +177,9 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { argc = arguments.length; if ( argc !== nargs ) { if ( argc < nargs ) { - throw new Error( 'invalid invocation. Insufficient arguments.' ); + throw new Error( format( '0Mq0l' ) ); } - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format( '0Mq0m' ) ); } arrays = []; dtypes = []; @@ -200,7 +200,7 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { // Check whether we were able to successfully resolve an ndarray function: if ( idx < 0 ) { - throw new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' ); + throw new TypeError( format( '0Mq0p' ) ); } // Retrieve the ndarray function: if ( fcn ) { diff --git a/package.json b/package.json index 5161a39..0bf3078 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/assert-is-nonnegative-integer": "^0.0.7", "@stdlib/assert-is-positive-integer": "^0.0.7", "@stdlib/ndarray-base-dtype-resolve-enum": "^0.0.1", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/types": "^0.0.14" }, "devDependencies": { From 65182b111dfe687fa17e690193022f915cdbfb4a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Jun 2023 18:09:43 +0000 Subject: [PATCH 039/109] Remove files --- index.d.ts | 334 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6516 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index e8f79c8..0000000 --- a/index.d.ts +++ /dev/null @@ -1,334 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* ndarray function. -* -* @param arrays - array containing input and output ndarrays -* @param data - ndarray function data (e.g., a callback) -* -* @example -* var numel = require( `@stdlib/ndarray/base/numel` ); -* var ind2sub = require( `@stdlib/ndarray/ind2sub` ); -* -* function ndarrayFcn( arrays, fcn ) { -* var xord; -* var yord; -* var opts; -* var sub; -* var sh; -* var N; -* var x; -* var y; -* var v; -* var i; -* -* x = arrays[ 0 ]; -* y = arrays[ 1 ]; -* sh = x.shape; -* N = numel( sh ); -* if ( N <= 0 ) { -* return; -* } -* xord = x.order; -* yord = y.order; -* opts = {}; -* opts.order = xord; -* for ( i = 0; i < N; i++ ) { -* // Convert a linear index to subscripts: -* opts.order = xord; -* sub = ind2sub( sh, i, opts ); -* -* // Retrieve an element from `x`: -* v = x.get.apply( x, sub ); -* -* // Convert a linear index to subscripts: -* opts.order = yord; -* sub = ind2sub( sh, i, opts ); -* -* // Append the result of applying the callback: -* sub.push( fcn( v ) ); -* -* // Assign the result to an element in `y`: -* y.set.apply( y, sub ); -* } -* } -*/ -type ndarrayFcn = ( arrays: Array, data?: any ) => void; - -/** -* Interface describing an ndarray function dispatcher. -*/ -interface Dispatcher { - /** - * Invokes an ndarray function based on the provided array data type(s). - * - * @param x - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array - * - * @example - * var nullary = require( `@stdlib/ndarray/base/nullary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function value() { - * return 3.14; - * } - * - * var types = [ 'float64' ]; - * var data = [ value ]; - * - * var fcn = dispatch( nullary, types, data, 1, 0, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( 5 ); - * var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x ); - * // xbuf => [ 3.14, 3.14, 3.14, 3.14, 3.14 ] - */ - ( x: ndarray ): ndarray | void; - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var unary = require( `@stdlib/ndarray/base/unary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * var abs = require( `@stdlib/math/base/special/abs` ); - * - * var types = [ 'float64', 'float64' ]; - * var data = [ abs ]; - * - * var fcn = dispatch( unary, types, data, 2, 1, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - * var ybuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y ); - * // ybuf => [ 1.0, 2.0, 3.0 ] - */ - ( x: ndarray, y: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var ternary = require( `@stdlib/ndarray/base/ternary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add2( x, y ) { - * return x + y; - * } - * - * var types = [ 'float64', 'float64', 'float64' ]; - * var data = [ add2 ]; - * - * var fcn = dispatch( ternary, types, data, 3, 2, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z ); - * // zbuf => [ 2.0, 4.0, 6.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quaternary = require( `@stdlib/ndarray/base/quaternary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add3( x, y, z ) { - * return x + y + z; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add3 ]; - * - * var fcn = dispatch( quaternary, types, data, 4, 3, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w ); - * // wbuf => [ 3.0, 6.0, 9.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @param args - ndarray arguments - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quinary = require( `@stdlib/ndarray/base/quinary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add4( x, y, z, w ) { - * return x + y + z + w; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add4 ]; - * - * var fcn = dispatch( quinary, types, data, 5, 4, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ubuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var u = ndarray( 'float64', ubuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w, u ); - * // ubuf => [ 4.0, 8.0, 12.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray, ...args: Array ): ndarray | void; // tslint:disable-line:max-line-length unified-signatures -} - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param fcns - list of ndarray functions -* @param types - one-dimensional list of ndarray argument data types -* @param data - ndarray function data (e.g., callbacks) -* @param nargs - total number of ndarray function interface arguments -* @param nin - number of input ndarrays -* @param nout - number of output ndarrays -* @throws first argument must be either a function or an array of functions -* @throws second argument must be an array-like object -* @throws third argument must be an array-like object or `null` -* @throws third and first arguments must have the same number of elements -* @throws fourth argument must be a positive integer -* @throws fifth argument must be a nonnegative integer -* @throws sixth argument must be a nonnegative integer -* @throws fourth argument must equal the specified number of input and output arrays -* @throws number of types must match the number of functions times the total number of array arguments for each function -* @throws interface must accept at least one input and/or output ndarray -* @returns ndarray function interface -* -* @example -* var unary = require( `@stdlib/ndarray/base/unary` ); -* var abs = require( `@stdlib/math/base/special/abs` ); -* var Float64Array = require( `@stdlib/array/float64` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var fcn = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* fcn( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function dispatch( fcns: ndarrayFcn | ArrayLike, types: ArrayLike, data: ArrayLike | null, nargs: number, nin: number, nout: number ): Dispatcher; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = dispatch; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 359fc1e..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@esm/index.mjs";function l(r,e,t,s,i,n,o,d,m){var l,a,h,f;for(l=n,h=0;h [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0Mq5s', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0Mq3A', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0Mq5u', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0Mq5v', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0Mq5w', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format( '0Mq0h' ) );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format( '0Mq0i' ) );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format( '0Mq0k' ) );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format( '0Mq0l' ) );\n\t\t\t}\n\t\t\tthrow new Error( format( '0Mq0m' ) );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( v.dtype ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format( '0Mq0p' ) );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n"],"names":["indexOfTypes","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","i","j","dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","out","push","resolveEnum","types2enums","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","dtype","slice"],"mappings":";;01BA6EA,SAASA,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,KAAgBE,EAAGI,GADdE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,CACN,CACD,OAAQ,CACT,CCKA,SAASU,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,sFAAuFV,IAErH,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAQ,UAE1B,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAQ,UAE1B,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAQ,eAI1B,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAQ,UAG3B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAQ,UAG1B,OADAX,EA5GD,SAAsBA,GACrB,IAAIkB,EACAtB,EAGJ,IADAsB,EAAM,GACAtB,EAAI,EAAGA,EAAII,EAAMgB,OAAQpB,IAC9BsB,EAAIC,KAAMC,EAAapB,EAAOJ,KAE/B,OAAOsB,CACR,CAmGSG,CAAarB,GAgBrB,WACC,IAAIsB,EACAC,EACAC,EACAC,EACAC,EACAC,EACA/B,EAGJ,IADA4B,EAAOI,UAAUZ,UACHd,EAAQ,CACrB,GAAKsB,EAAOtB,EACX,MAAM,IAAIa,MAAOJ,EAAQ,UAE1B,MAAM,IAAII,MAAOJ,EAAQ,SACzB,CAGD,IAFAW,EAAS,GACTC,EAAS,GACH3B,EAAI,EAAGA,EAAIM,EAAON,IAAM,CAE7B,IAAMiC,EADNH,EAAIE,UAAWhC,IAEd,MAAKA,EAAIO,EACF,IAAIO,UAAWC,EAAQ,6EAA8Ee,IAErG,IAAIhB,UAAWC,EAAQ,8EAA+Ee,IAG9GJ,EAAOH,KAAMO,GACbH,EAAOJ,KAAMC,EAAaM,EAAEI,OAC5B,CAKD,IAHAL,EAAMzC,EAAcsB,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGkB,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAIb,UAAWC,EAAQ,UAI7BgB,EADIpB,GAGAR,EAAM0B,GAGNxB,EACJ0B,EAAGL,EAAQrB,EAAMwB,IAEjBE,EAAGL,GAEJ,GAAc,IAATlB,EACJ,OAAOkB,EAAQjB,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOkB,EAAOS,MAAO5B,EACrB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d17478d..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 422466febea9675c8629f20b8b49d41b10753d76 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Jun 2023 18:10:46 +0000 Subject: [PATCH 040/109] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 59 +- benchmark/benchmark.dispatch_size.js | 156 - benchmark/benchmark.js | 81 - branches.md | 53 - docs/repl.txt | 87 - docs/types/test.ts | 641 --- examples/add.js | 121 - examples/sin.js | 142 - examples/unary.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/index_of_types.js | 106 - lib/main.js | 230 - package.json | 77 +- stats.html | 6177 +++++++++++++++++++++ test/fixtures/binary.js | 38 - test/fixtures/fill.js | 76 - test/fixtures/foreach.js | 72 - test/fixtures/map1n.js | 74 - test/fixtures/nullary.js | 36 - test/fixtures/quaternary.js | 40 - test/fixtures/quinary.js | 41 - test/fixtures/sum.js | 98 - test/fixtures/ternary.js | 39 - test/test.js | 363 -- test/test.two_arrays.js | 808 --- 51 files changed, 6211 insertions(+), 6598 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.dispatch_size.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/add.js delete mode 100644 examples/sin.js delete mode 100644 examples/unary.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/index_of_types.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/fixtures/binary.js delete mode 100644 test/fixtures/fill.js delete mode 100644 test/fixtures/foreach.js delete mode 100644 test/fixtures/map1n.js delete mode 100644 test/fixtures/nullary.js delete mode 100644 test/fixtures/quaternary.js delete mode 100644 test/fixtures/quinary.js delete mode 100644 test/fixtures/sum.js delete mode 100644 test/fixtures/ternary.js delete mode 100644 test/test.js delete mode 100644 test/test.two_arrays.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 02b9261..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-06-01T06:28:32.926Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ac0b7cd..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 920b304..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 34e41d6..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '43 7 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 3e8e2db..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -291,7 +284,7 @@ console.log( ybuf ); ## 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. +This package is part of [stdlib][stdlib], a standard library 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]. @@ -353,11 +346,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm diff --git a/benchmark/benchmark.dispatch_size.js b/benchmark/benchmark.dispatch_size.js deleted file mode 100644 index 3bd0418..0000000 --- a/benchmark/benchmark.dispatch_size.js +++ /dev/null @@ -1,156 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib/main.js' ); - - -// FUNCTIONS // - -/** -* Evaluates the identity function. -* -* @private -* @param {*} v - value -* @returns {*} input value -*/ -function identity( v ) { - return v; -} - -/** -* Dummy function which throws an error. -* -* @private -* @throws {Error} unexpected error -*/ -function throwError() { - throw new Error( 'unexpected error' ); -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} size - dispatch size -* @returns {Function} benchmark function -*/ -function createBenchmark( size ) { - var types; - var data; - var fcn; - var x; - var y; - var t; - var i; - - types = []; - - // Create dummy types... - for ( i = 0; i < (size-1)*2; i += 2 ) { - t = 'foo' + i; - types.push( t ); - types.push( t ); - } - // Append test types: - types.push( 'float64' ); - types.push( 'float64' ); - - // Define a list of callbacks: - data = []; - for ( i = 0; i < size-1; i++ ) { - data.push( throwError ); - } - // Append a test callback: - data.push( identity ); - - // Create the dispatcher: - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - // Create sample arrays: - x = new Float64Array( 1 ); - y = new Float64Array( x.length ); - - x = ndarray( 'float64', x, [ 1 ], [ 1 ], 0, 'row-major' ); - y = ndarray( 'float64', y, [ 1 ], [ 1 ], 0, 'row-major' ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var z; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x.data[ 0 ] = i; - z = fcn( x, y ); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var size; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - size = pow( 2, i ); - f = createBenchmark( size ); - bench( pkg+':size='+size, f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index a70dc5c..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::fcns_array', function benchmark( b ) { - var types; - var fcns; - var data; - var out; - var i; - - fcns = [ unary ]; - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( fcns, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::fcn_arg', function benchmark( b ) { - var types; - var data; - var out; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( unary, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 6c1b20d..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch" -%% click B href "https://github.com/stdlib-js/ndarray-dispatch/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-dispatch/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-dispatch/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-dispatch/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-dispatch/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch -[production-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 02fe150..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,87 +0,0 @@ - -{{alias}}( fcns, types, data, nargs, nin, nout ) - Returns an ndarray function interface which performs multiple dispatch. - - An ndarray function interface has the following signature: - - f( x, y, ... ) - - where - - - x: ndarray. - - y: ndarray. - - ...: additional ndarrays. - - The number of parameters is derived from `nargs`, the number of input - ndarrays is derived from `nin`, and the number of output ndarrays is derived - from `nout`. - - Parameters - ---------- - fcns: Function|ArrayLikeObject - List of ndarray functions. An ndarray function should have the following - signature: - - f( arrays, data ) - - where - - - arrays: array containing input and output ndarrays. - - data: ndarray function data (e.g., a callback). - - For convenience, a single ndarray function may be provided which will be - invoked whenever the ndarray argument data types match a sequence of - types in `types`. Providing a single ndarray function is particularly - convenient for the case where, regardless of array data types, - traversing arrays remains the same, but the ndarray function `data` - differs (e.g., callbacks which differ based on the array data types). - - types: ArrayLikeObject - One-dimensional list of ndarray argument data types. - - data: ArrayLikeObject|null - ndarray function data (e.g., callbacks). If `null`, a returned ndarray - function interface does **not** provide a `data` argument to an invoked - ndarray function. - - nargs: integer - Total number of ndarray function interface arguments. - - nin: integer - Number of input ndarrays. - - nout: integer - Number of output ndarrays. - - Returns - ------- - fcn: Function - ndarray function interface. - - Examples - -------- - // Define ndarray argument data types: - > var t = [ 'float64', 'float64', 'float32', 'float32' ]; - - // Define a list of ndarray function data (callbacks): - > var d = [ {{alias:@stdlib/math/base/special/abs}}, {{alias:@stdlib/math/base/special/absf}} ]; - - // Create an ndarray function interface for applying unary callbacks: - > var f = {{alias}}( {{alias:@stdlib/ndarray/base/unary}}, t, d, 2, 1, 1 ); - - // Create an input ndarray: - > var xbuf = new {{alias:@stdlib/array/float64}}( [ -1.0, -2.0, -3.0, -4.0 ] ); - > var x = {{alias:@stdlib/ndarray/ctor}}( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Create an output ndarray: - > var ybuf = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 0.0, 0.0 ] ); - > var y = {{alias:@stdlib/ndarray/ctor}}( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Compute the element-wise absolute value: - > f( x, y ); - > ybuf - [ 1.0, 2.0, 3.0, 4.0 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 397185e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,641 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// tslint:disable:max-file-line-count - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import dispatch = require( './index' ); - - -// FUNCTIONS // - -/** -* Nullary callback. -* -* @return input value -*/ -function nullary(): any { - return 5.0; -} - -/** -* Unary callback. -* -* @param x - input value -* @return input value -*/ -function unary( x: any ): any { - return x; -} - -/** -* Binary callback. -* -* @param x - input value -* @param y - input value -* @return output value -*/ -function binary( x: number, y: number ): number { - return x + y; -} - -/** -* Ternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @return output value -*/ -function ternary( x: number, y: number, z: number ): number { - return x + y + z; -} - -/** -* Quaternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @param w - input value -* @return output value -*/ -function quaternary( x: number, y: number, z: number, w: number ): number { - return x + y + z + w; -} - -/** -* Mock `ind2sub` function. -* -* @param shape - dimensions -* @param idx - linear index -* @param opts - options -* @return subscripts -*/ -function ind2sub( shape: ArrayLike, idx: number, opts?: any ): Array { // tslint:disable-line:max-line-length - let out; - let i; - - out = []; - if ( typeof opts === 'object' && opts !== null && opts.order === 'row-major' ) { // tslint:disable-line:max-line-length no-unsafe-any - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } else { - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } - return out; -} - -/** -* Mock ndarray function. -* -* @param arrays - ndarrays -* @param fcn - callback -*/ -function ndarrayFcn( arrays: Array, fcn: ( x: any ) => any ): void { - let xord; - let yord; - let opts; - let sub; - let sh; - let N; - let x; - let y; - let v; - let i; - - x = arrays[ 0 ]; - y = arrays[ 1 ]; - sh = x.shape; - if ( sh.length === 0 ) { - return; - } - N = 1; - for ( i = 0; i < sh.length; i += 1 ) { - N *= sh[ i ]; - } - xord = x.order; - yord = y.order; - opts = { - 'order': '' - }; - opts.order = xord; - for ( i = 0; i < N; i += 1 ) { - // Convert a linear index to subscripts: - opts.order = xord; - sub = ind2sub( sh, i, opts ); - - // Retrieve an element from `x`: - v = x.get.apply( x, sub ); - - // Convert a linear index to subscripts: - opts.order = yord; - sub = ind2sub( sh, i, opts ); - - // Append the result of applying the callback: - sub[ sub.length ] = fcn( v ) as number; - - // Assign the result to an element in `y`: - y.set.apply( y, sub ); - } -} - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a dispatch function... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, 1 ); // $ExpectType Dispatcher - dispatch( [ ndarrayFcn ], types, data, 2, 1, 1 ); // $ExpectType Dispatcher -} - -// The compiler throws an error if the function is provided a first argument which is not either an ndarray function or an array-like object containing ndarray functions... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( '10', types, data, 2, 1, 1 ); // $ExpectError - dispatch( 10, types, data, 2, 1, 1 ); // $ExpectError - dispatch( true, types, data, 2, 1, 1 ); // $ExpectError - dispatch( false, types, data, 2, 1, 1 ); // $ExpectError - dispatch( null, types, data, 2, 1, 1 ); // $ExpectError - dispatch( undefined, types, data, 2, 1, 1 ); // $ExpectError - dispatch( [ '1' ], types, data, 2, 1, 1 ); // $ExpectError - dispatch( {}, types, data, 2, 1, 1 ); // $ExpectError - dispatch( ( x: number ): number => x, types, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object... -{ - const data = [ unary ]; - - dispatch( ndarrayFcn, 10, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, true, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, false, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, null, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, undefined, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, {}, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object or null... -{ - const types = [ 'float64', 'float64' ]; - - dispatch( ndarrayFcn, types, 10, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, true, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, false, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, undefined, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, {}, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, '10', 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, true, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, false, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, null, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, undefined, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, [ '1' ], 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, {}, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, ( x: number ): number => x, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, '10', 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, true, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, false, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, null, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, undefined, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, [ '1' ], 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, {}, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, ( x: number ): number => x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, '10' ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, true ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, false ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, null ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, undefined ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, [ '1' ] ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, {} ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch(); // $ExpectError - dispatch( ndarrayFcn ); // $ExpectError - dispatch( ndarrayFcn, types ); // $ExpectError - dispatch( ndarrayFcn, types, data ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, 1, 0 ); // $ExpectError -} - -// The function returns a dispatch function... -{ - const x = array(); - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const t1 = [ 'float64' ]; - const d1 = [ nullary ]; - const f1 = dispatch( ndarrayFcn, t1, d1, 1, 1, 0 ); - f1( x ); // $ExpectType void | ndarray - - const t2 = [ 'float64', 'float64' ]; - const d2 = [ unary ]; - const f2 = dispatch( ndarrayFcn, t2, d2, 2, 1, 1 ); - f2( x, y ); // $ExpectType void | ndarray - - const t3 = [ 'float64', 'float64', 'float64' ]; - const d3 = [ binary ]; - const f3 = dispatch( ndarrayFcn, t3, d3, 3, 2, 1 ); - f3( x, y, z ); // $ExpectType void | ndarray - - const t4 = [ 'float64', 'float64', 'float64', 'float64' ]; - const d4 = [ ternary ]; - const f4 = dispatch( ndarrayFcn, t4, d4, 4, 3, 1 ); - f4( x, y, z, w ); // $ExpectType void | ndarray - - const t5 = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const d5 = [ quaternary ]; - const f5 = dispatch( ndarrayFcn, t5, d5, 5, 4, 1 ); - f5( x, y, z, w, u ); // $ExpectType void | ndarray -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (1 ndarray)... -{ - const types = [ 'float64' ]; - const data = [ nullary ]; - - const f = dispatch( ndarrayFcn, types, data, 1, 0, 1 ); - f( '10' ); // $ExpectError - f( 10 ); // $ExpectError - f( true ); // $ExpectError - f( false ); // $ExpectError - f( null ); // $ExpectError - f( undefined ); // $ExpectError - f( [ '1' ] ); // $ExpectError - f( {} ); // $ExpectError - f( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( 10, y ); // $ExpectError - f( '10', y ); // $ExpectError - f( true, y ); // $ExpectError - f( false, y ); // $ExpectError - f( null, y ); // $ExpectError - f( undefined, y ); // $ExpectError - f( [ '1' ], y ); // $ExpectError - f( {}, y ); // $ExpectError - f( ( x: number ): number => x, y ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const x = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( x, 10 ); // $ExpectError - f( x, '10' ); // $ExpectError - f( x, true ); // $ExpectError - f( x, false ); // $ExpectError - f( x, null ); // $ExpectError - f( x, undefined ); // $ExpectError - f( x, [ '1' ] ); // $ExpectError - f( x, {} ); // $ExpectError - f( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( 10, y, z ); // $ExpectError - f( '10', y, z ); // $ExpectError - f( true, y, z ); // $ExpectError - f( false, y, z ); // $ExpectError - f( null, y, z ); // $ExpectError - f( undefined, y, z ); // $ExpectError - f( [ '1' ], y, z ); // $ExpectError - f( {}, y, z ); // $ExpectError - f( ( x: number ): number => x, y, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, 10, z ); // $ExpectError - f( x, '10', z ); // $ExpectError - f( x, true, z ); // $ExpectError - f( x, false, z ); // $ExpectError - f( x, null, z ); // $ExpectError - f( x, undefined, z ); // $ExpectError - f( x, [ '1' ], z ); // $ExpectError - f( x, {}, z ); // $ExpectError - f( x, ( x: number ): number => x, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, y, '10' ); // $ExpectError - f( x, y, true ); // $ExpectError - f( x, y, false ); // $ExpectError - f( x, y, null ); // $ExpectError - f( x, y, undefined ); // $ExpectError - f( x, y, [ '1' ] ); // $ExpectError - f( x, y, {} ); // $ExpectError - f( x, y, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( 10, y, z, w ); // $ExpectError - f( '10', y, z, w ); // $ExpectError - f( true, y, z, w ); // $ExpectError - f( false, y, z, w ); // $ExpectError - f( null, y, z, w ); // $ExpectError - f( undefined, y, z, w ); // $ExpectError - f( [ '1' ], y, z, w ); // $ExpectError - f( {}, y, z, w ); // $ExpectError - f( ( x: number ): number => x, y, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, 10, z, w ); // $ExpectError - f( x, '10', z, w ); // $ExpectError - f( x, true, z, w ); // $ExpectError - f( x, false, z, w ); // $ExpectError - f( x, null, z, w ); // $ExpectError - f( x, undefined, z, w ); // $ExpectError - f( x, [ '1' ], z, w ); // $ExpectError - f( x, {}, z, w ); // $ExpectError - f( x, ( x: number ): number => x, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, 10, w ); // $ExpectError - f( x, y, '10', w ); // $ExpectError - f( x, y, true, w ); // $ExpectError - f( x, y, false, w ); // $ExpectError - f( x, y, null, w ); // $ExpectError - f( x, y, undefined, w ); // $ExpectError - f( x, y, [ '1' ], w ); // $ExpectError - f( x, y, {}, w ); // $ExpectError - f( x, y, ( x: number ): number => x, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, z, 10 ); // $ExpectError - f( x, y, z, '10' ); // $ExpectError - f( x, y, z, true ); // $ExpectError - f( x, y, z, false ); // $ExpectError - f( x, y, z, null ); // $ExpectError - f( x, y, z, undefined ); // $ExpectError - f( x, y, z, [ '1' ] ); // $ExpectError - f( x, y, z, {} ); // $ExpectError - f( x, y, z, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( 10, y, z, w, u ); // $ExpectError - f( '10', y, z, w, u ); // $ExpectError - f( true, y, z, w, u ); // $ExpectError - f( false, y, z, w, u ); // $ExpectError - f( null, y, z, w, u ); // $ExpectError - f( undefined, y, z, w, u ); // $ExpectError - f( [ '1' ], y, z, w, u ); // $ExpectError - f( {}, y, z, w, u ); // $ExpectError - f( ( x: number ): number => x, y, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, 10, z, w, u ); // $ExpectError - f( x, '10', z, w, u ); // $ExpectError - f( x, true, z, w, u ); // $ExpectError - f( x, false, z, w, u ); // $ExpectError - f( x, null, z, w, u ); // $ExpectError - f( x, undefined, z, w, u ); // $ExpectError - f( x, [ '1' ], z, w, u ); // $ExpectError - f( x, {}, z, w, u ); // $ExpectError - f( x, ( x: number ): number => x, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, 10, w, u ); // $ExpectError - f( x, y, '10', w, u ); // $ExpectError - f( x, y, true, w, u ); // $ExpectError - f( x, y, false, w, u ); // $ExpectError - f( x, y, null, w, u ); // $ExpectError - f( x, y, undefined, w, u ); // $ExpectError - f( x, y, [ '1' ], w, u ); // $ExpectError - f( x, y, {}, w, u ); // $ExpectError - f( x, y, ( x: number ): number => x, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, 10, u ); // $ExpectError - f( x, y, z, '10', u ); // $ExpectError - f( x, y, z, true, u ); // $ExpectError - f( x, y, z, false, u ); // $ExpectError - f( x, y, z, null, u ); // $ExpectError - f( x, y, z, undefined, u ); // $ExpectError - f( x, y, z, [ '1' ], u ); // $ExpectError - f( x, y, z, {}, u ); // $ExpectError - f( x, y, z, ( x: number ): number => x, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fifth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, w, 10 ); // $ExpectError - f( x, y, z, w, '10' ); // $ExpectError - f( x, y, z, w, true ); // $ExpectError - f( x, y, z, w, false ); // $ExpectError - f( x, y, z, w, null ); // $ExpectError - f( x, y, z, w, undefined ); // $ExpectError - f( x, y, z, w, [ '1' ] ); // $ExpectError - f( x, y, z, w, {} ); // $ExpectError - f( x, y, z, w, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/add.js b/examples/add.js deleted file mode 100644 index 775b711..0000000 --- a/examples/add.js +++ /dev/null @@ -1,121 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var dispatch = require( './../lib' ); - -function add2( arrays ) { - var opts; - var xo; - var yo; - var zo; - var sx; - var sy; - var sz; - var sh; - var N; - var x; - var y; - var z; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - z = arrays[ 2 ]; - xo = x.order; - yo = y.order; - zo = z.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - opts.order = yo; - sy = ind2sub( sh, i, opts ); - v = x.get.apply( x, sx ) + y.get.apply( y, sy ); - - opts.order = zo; - sz = ind2sub( sh, i, opts ); - sz.push( v ); - z.set.apply( z, sz ); - } -} - -var fcns = [ - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2 -]; - -var types = [ - dtypes.float64, dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.int32, dtypes.int32, - dtypes.uint32, dtypes.uint32, dtypes.uint32, - dtypes.int16, dtypes.int16, dtypes.int16, - dtypes.uint16, dtypes.uint16, dtypes.uint16, - dtypes.int8, dtypes.int8, dtypes.int8, - dtypes.uint8, dtypes.uint8, dtypes.uint8, - dtypes.uint8c, dtypes.uint8c, dtypes.uint8c -]; - -var add = dispatch( fcns, types, null, 3, 2, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var zbuf = new Float64Array( xbuf.length ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var z = ndarray( 'float64', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); - -xbuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -ybuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -zbuf = new Int32Array( xbuf.length ); - -x = ndarray( 'int32', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'int32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -z = ndarray( 'int32', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); diff --git a/examples/sin.js b/examples/sin.js deleted file mode 100644 index 8cd4871..0000000 --- a/examples/sin.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int8Array = require( '@stdlib/array-int8' ); -var sin = require( '@stdlib/math-base-special-sin' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/strided-dtypes' ); -var dispatch = require( './../lib' ); - -function apply( arrays, fcn ) { - var opts; - var xo; - var yo; - var sx; - var sy; - var sh; - var N; - var x; - var y; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - xo = x.order; - yo = y.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - v = fcn( x.get.apply( x, sx ) ); - - opts.order = yo; - sy = ind2sub( sh, i, opts ); - sy.push( v ); - y.set.apply( y, sy ); - } -} - -var fcns = [ - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply -]; - -var types = [ - dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float64, - dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.float64, - dtypes.uint32, dtypes.float64, - dtypes.int16, dtypes.float64, - dtypes.int16, dtypes.float32, - dtypes.uint16, dtypes.float64, - dtypes.uint16, dtypes.float32, - dtypes.int8, dtypes.float64, - dtypes.int8, dtypes.float32, - dtypes.uint8, dtypes.float64, - dtypes.uint8, dtypes.float32, - dtypes.uint8c, dtypes.float64, - dtypes.uint8c, dtypes.float32 -]; - -var data = [ - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin -]; - -var sine = dispatch( fcns, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); - -xbuf = new Int8Array( [ 1, 2, 3, 4, 5 ] ); -ybuf = new Float32Array( xbuf.length ); - -x = ndarray( 'int8', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'float32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); diff --git a/examples/unary.js b/examples/unary.js deleted file mode 100644 index e9c3fb4..0000000 --- a/examples/unary.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -var unary = require( '@stdlib/ndarray-base-unary' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var dispatch = require( './../lib' ); - -var types = [ 'float64', 'float64' ]; - -var data = [ - abs -]; - -var absolute = dispatch( unary, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -absolute( x, y ); -console.log( ybuf ); -// => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 610167d..e8f79c8 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..359fc1e --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@esm/index.mjs";function l(r,e,t,s,i,n,o,d,m){var l,a,h,f;for(l=n,h=0;h [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0Mq5s', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0Mq3A', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0Mq5u', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0Mq5v', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0Mq5w', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format( '0Mq0h' ) );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format( '0Mq0i' ) );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format( '0Mq0k' ) );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format( '0Mq0l' ) );\n\t\t\t}\n\t\t\tthrow new Error( format( '0Mq0m' ) );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( v.dtype ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format( '0Mq0p' ) );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n"],"names":["indexOfTypes","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","i","j","dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","out","push","resolveEnum","types2enums","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","dtype","slice"],"mappings":";;01BA6EA,SAASA,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,KAAgBE,EAAGI,GADdE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,CACN,CACD,OAAQ,CACT,CCKA,SAASU,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,sFAAuFV,IAErH,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAQ,UAE1B,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAQ,UAE1B,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAQ,eAI1B,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAQ,UAG3B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAQ,UAG1B,OADAX,EA5GD,SAAsBA,GACrB,IAAIkB,EACAtB,EAGJ,IADAsB,EAAM,GACAtB,EAAI,EAAGA,EAAII,EAAMgB,OAAQpB,IAC9BsB,EAAIC,KAAMC,EAAapB,EAAOJ,KAE/B,OAAOsB,CACR,CAmGSG,CAAarB,GAgBrB,WACC,IAAIsB,EACAC,EACAC,EACAC,EACAC,EACAC,EACA/B,EAGJ,IADA4B,EAAOI,UAAUZ,UACHd,EAAQ,CACrB,GAAKsB,EAAOtB,EACX,MAAM,IAAIa,MAAOJ,EAAQ,UAE1B,MAAM,IAAII,MAAOJ,EAAQ,SACzB,CAGD,IAFAW,EAAS,GACTC,EAAS,GACH3B,EAAI,EAAGA,EAAIM,EAAON,IAAM,CAE7B,IAAMiC,EADNH,EAAIE,UAAWhC,IAEd,MAAKA,EAAIO,EACF,IAAIO,UAAWC,EAAQ,6EAA8Ee,IAErG,IAAIhB,UAAWC,EAAQ,8EAA+Ee,IAG9GJ,EAAOH,KAAMO,GACbH,EAAOJ,KAAMC,EAAaM,EAAEI,OAC5B,CAKD,IAHAL,EAAMzC,EAAcsB,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGkB,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAIb,UAAWC,EAAQ,UAI7BgB,EADIpB,GAGAR,EAAM0B,GAGNxB,EACJ0B,EAAGL,EAAQrB,EAAMwB,IAEjBE,EAAGL,GAEJ,GAAc,IAATlB,EACJ,OAAOkB,EAAQjB,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOkB,EAAOS,MAAO5B,EACrB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 291641d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Create an ndarray function interface which performs multiple dispatch. -* -* @module @stdlib/ndarray-dispatch -* -* @example -* var dispatch = require( '@stdlib/ndarray-dispatch' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/index_of_types.js b/lib/index_of_types.js deleted file mode 100644 index fda2297..0000000 --- a/lib/index_of_types.js +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found). -* -* ## Notes -* -* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types). -* - The function assumes that `x` is stored in row-major order. -* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`. -* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value. -* -* @private -* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension) -* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension) -* @param {ArrayLikeObject} x - input two-dimensional reference array -* @param {integer} strideX1 - `x` stride length along first dimension -* @param {integer} strideX2 - `x` stride length along second dimension -* @param {NonNegativeInteger} offsetX - `x` starting index -* @param {ArrayLikeObject} y - search array -* @param {integer} strideY - `y` stride length -* @param {NonNegativeInteger} offsetY - `y` starting index -* @returns {integer} row index (if found) and `-1` otherwise -* -* @example -* // Define a reference array to search: -* var types = [ -* 'float64', 'float64', 'float64', -* 'float32', 'float32', 'float32', -* 'uint32', 'uint32', 'float64', -* 'int32', 'int32', 'float64', -* 'uint16', 'uint16', 'float64', -* 'int16', 'int16', 'float64', -* 'uint8', 'uint8', 'float64', -* 'int8', 'int8', 'float64' -* ]; -* -* // Define reference array dimensions: -* var N = 8; // rows -* var M = 3; // columns -* -* // Define a search array: -* y1 = [ -* 'float32', 'float32', 'float32', -* ]; -* -* // Find the list of types: -* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 ); -* // returns 1 -* -// Define a search array: -* y2 = [ -* 'float32', 'float32', 'float64', -* ]; -* -* // Find the list of types: -* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 ); -* // returns -1 -*/ -function indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len - var ix; - var iy; - var i; - var j; - - // Search for the first row which matches `y`... - ix = offsetX; - for ( i = 0; i < N; i++ ) { - iy = offsetY; - for ( j = 0; j < M; j++ ) { - if ( x[ ix+(j*strideX2) ] !== y[ iy ] ) { - break; - } - iy += strideY; - } - // If we successfully iterated over all columns, then that means we've found a match... - if ( j === M ) { - return i; - } - ix += strideX1; - } - return -1; -} - - -// EXPORTS // - -module.exports = indexOfTypes; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 7653329..0000000 --- a/lib/main.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isFunctionArray = require( '@stdlib/assert-is-function-array' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var resolveEnum = require( '@stdlib/ndarray-base-dtype-resolve-enum' ); -var indexOfTypes = require( './index_of_types.js' ); - - -// FUNCTIONS // - -/** -* Returns a list of data type enumeration constants. -* -* @private -* @param {Collection} types - list of types -* @returns {IntegerArray} list of data type enumeration constants -*/ -function types2enums( types ) { - var out; - var i; - - out = []; - for ( i = 0; i < types.length; i++ ) { - out.push( resolveEnum( types[ i ] ) ); - } - return out; -} - - -// MAIN // - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param {(FunctionArray|Function)} fcns - list of ndarray functions -* @param {Collection} types - one-dimensional list of ndarray argument data types -* @param {(Collection|null)} data - ndarray function data (e.g., callbacks) -* @param {PositiveInteger} nargs - total number of ndarray function interface arguments -* @param {NonNegativeInteger} nin - number of input ndarrays -* @param {NonNegativeInteger} nout - number of output ndarrays -* @throws {TypeError} first argument must be either a function or an array of functions -* @throws {TypeError} second argument must be an array-like object -* @throws {TypeError} third argument must be an array-like object or `null` -* @throws {Error} third and first arguments must have the same number of elements -* @throws {TypeError} fourth argument must be a positive integer -* @throws {TypeError} fifth argument must be a nonnegative integer -* @throws {TypeError} sixth argument must be a nonnegative integer -* @throws {Error} fourth argument must equal the specified number of input and output arrays -* @throws {Error} number of types must match the number of functions times the total number of array arguments for each function -* @throws {Error} interface must accept at least one input and/or output ndarray -* @returns {Function} ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function dispatch( fcns, types, data, nargs, nin, nout ) { - var narrays; - var nfcns; - var fcn; - - if ( isFunction( fcns ) ) { - fcn = fcns; - } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( '0Mq5s', fcns ) ); - } - if ( !isCollection( types ) ) { - throw new TypeError( format( '0Mq3A', types ) ); - } - if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); - } - if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( '0Mq5u', nargs ) ); - } - if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( '0Mq5v', nin ) ); - } - if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( '0Mq5w', nout ) ); - } - narrays = nin + nout; - if ( narrays === 0 ) { - throw new Error( format( '0Mq0h' ) ); - } - if ( nargs !== narrays ) { - throw new Error( format( '0Mq0i' ) ); - } - if ( fcn ) { - nfcns = types.length / narrays; - if ( !isInteger( nfcns ) ) { - throw new Error( format( '0Mq0j' ) ); - } - } else { - nfcns = fcns.length; - if ( types.length !== nfcns*narrays ) { - throw new Error( format( '0Mq0j' ) ); - } - } - if ( data && data.length !== nfcns ) { - throw new Error( format( '0Mq0k' ) ); - } - types = types2enums( types ); - return dispatcher; - - /** - * ndarray function interface which performs multiple dispatch. - * - * @private - * @param {ndarrayLike} x - ndarray - * @param {...ndarrayLike} args - ndarray arguments - * @throws {Error} insufficient arguments - * @throws {Error} too many arguments - * @throws {TypeError} input array arguments must be ndarray-like objects - * @throws {TypeError} output array arguments must be ndarray-like objects - * @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types - * @returns {(ndarrayLike|Array|void)} destination array(s) - */ - function dispatcher() { - var arrays; - var dtypes; - var argc; - var idx; - var v; - var f; - var i; - - argc = arguments.length; - if ( argc !== nargs ) { - if ( argc < nargs ) { - throw new Error( format( '0Mq0l' ) ); - } - throw new Error( format( '0Mq0m' ) ); - } - arrays = []; - dtypes = []; - for ( i = 0; i < nargs; i++ ) { - v = arguments[ i ]; - if ( !isndarrayLike( v ) ) { - if ( i < nin ) { - throw new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) ); - } else { - throw new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) ); - } - } - arrays.push( v ); - dtypes.push( resolveEnum( v.dtype ) ); - } - // Resolve the ndarray function satisfying the input array types: - idx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len - - // Check whether we were able to successfully resolve an ndarray function: - if ( idx < 0 ) { - throw new TypeError( format( '0Mq0p' ) ); - } - // Retrieve the ndarray function: - if ( fcn ) { - f = fcn; - } else { - f = fcns[ idx ]; - } - // Evaluate the ndarray function: - if ( data ) { - f( arrays, data[ idx ] ); - } else { - f( arrays ); - } - if ( nout === 1 ) { - return arrays[ narrays-1 ]; - } - if ( nout === 0 ) { - return; - } - return arrays.slice( nin ); - } -} - - -// EXPORTS // - -module.exports = dispatch; diff --git a/package.json b/package.json index 0bf3078..9d3bbf2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Create an ndarray function interface which performs multiple dispatch.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,55 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-collection": "^0.0.8", - "@stdlib/assert-is-function": "^0.0.8", - "@stdlib/assert-is-function-array": "^0.0.7", - "@stdlib/assert-is-integer": "^0.0.8", - "@stdlib/assert-is-ndarray-like": "^0.0.6", - "@stdlib/assert-is-nonnegative-integer": "^0.0.7", - "@stdlib/assert-is-positive-integer": "^0.0.7", - "@stdlib/ndarray-base-dtype-resolve-enum": "^0.0.1", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/types": "^0.0.14" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.0.6", - "@stdlib/array-float64": "^0.0.6", - "@stdlib/array-int32": "^0.0.6", - "@stdlib/array-int8": "^0.0.6", - "@stdlib/array-uint8": "^0.0.7", - "@stdlib/bench": "^0.0.12", - "@stdlib/math-base-assert-is-nan": "^0.0.8", - "@stdlib/math-base-special-abs": "^0.0.6", - "@stdlib/math-base-special-pow": "^0.0.7", - "@stdlib/math-base-special-sin": "^0.0.6", - "@stdlib/ndarray-base-buffer-dtype": "^0.0.6", - "@stdlib/ndarray-base-numel": "^0.0.8", - "@stdlib/ndarray-base-unary": "^0.0.6", - "@stdlib/ndarray-ctor": "^0.0.10", - "@stdlib/ndarray-dtypes": "^0.0.9", - "@stdlib/ndarray-ind2sub": "^0.0.7", - "@stdlib/strided-dtypes": "^0.0.8", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "ndarray", @@ -98,7 +26,6 @@ "multimethod", "multimethods" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..d011977 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/fixtures/binary.js b/test/fixtures/binary.js deleted file mode 100644 index a60dfa2..0000000 --- a/test/fixtures/binary.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Binary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @returns {number} sum -*/ -function binary( x, y ) { - return x + y; -} - - -// EXPORTS // - -module.exports = binary; diff --git a/test/fixtures/fill.js b/test/fixtures/fill.js deleted file mode 100644 index 41b2958..0000000 --- a/test/fixtures/fill.js +++ /dev/null @@ -1,76 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which fills one or more ndarrays. -* -* @private -* @param {*} value - fill value -* @returns {Function} ndarray function -*/ -function fill( value ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - */ - function ndarrayFcn( arrays ) { - var opts; - var sub; - var arr; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - opts = { - 'order': '' - }; - for ( j = 0; j < M; j++ ) { - arr = arrays[ j ]; - opts.order = arrays[ j ].order; - for ( i = 0; i < N; i++ ) { - sub = ind2sub( sh, i, opts ); - sub.push( value ); - arr.set.apply( arr, sub ); - } - } - } -} - - -// EXPORTS // - -module.exports = fill; diff --git a/test/fixtures/foreach.js b/test/fixtures/foreach.js deleted file mode 100644 index a426290..0000000 --- a/test/fixtures/foreach.js +++ /dev/null @@ -1,72 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function forEach( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - fcn.apply( null, args ); - } -} - - -// EXPORTS // - -module.exports = forEach; diff --git a/test/fixtures/map1n.js b/test/fixtures/map1n.js deleted file mode 100644 index 614196b..0000000 --- a/test/fixtures/map1n.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function which maps the return value of a callback to `N` arrays. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function map1N( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var v; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - v = fcn(); - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - sub.push( v ); - arrays[ j ].set.apply( arrays[ j ], sub ); - } - } -} - - -// EXPORTS // - -module.exports = map1N; diff --git a/test/fixtures/nullary.js b/test/fixtures/nullary.js deleted file mode 100644 index 4f22126..0000000 --- a/test/fixtures/nullary.js +++ /dev/null @@ -1,36 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Nullary callback. -* -* @private -* @returns {number} value -*/ -function nullary() { - return 3.0; -} - - -// EXPORTS // - -module.exports = nullary; diff --git a/test/fixtures/quaternary.js b/test/fixtures/quaternary.js deleted file mode 100644 index 548437b..0000000 --- a/test/fixtures/quaternary.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quaternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @returns {number} sum -*/ -function quaternary( x, y, z, w ) { - return x + y + z + w; -} - - -// EXPORTS // - -module.exports = quaternary; diff --git a/test/fixtures/quinary.js b/test/fixtures/quinary.js deleted file mode 100644 index 36068de..0000000 --- a/test/fixtures/quinary.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quinary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @param {number} u - input value -* @returns {number} sum -*/ -function quinary( x, y, z, w, u ) { - return x + y + z + w + u; -} - - -// EXPORTS // - -module.exports = quinary; diff --git a/test/fixtures/sum.js b/test/fixtures/sum.js deleted file mode 100644 index efdbb1b..0000000 --- a/test/fixtures/sum.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which computes the sum across one or more ndarrays. -* -* @private -* @param {Object} ctx - context -* @param {number} ctx.sum - initial sum -* @returns {Function} ndarray function -*/ -function wrapper( ctx ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - * @param {Function} [fcn] - callback - */ - function ndarrayFcn( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var f; - var i; - var j; - - if ( arguments.length > 1 ) { - f = fcn; - } - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - if ( f ) { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - ctx.sum += f.apply( null, args ); - } - } else { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - ctx.sum += arrays[ j ].get.apply( arrays[ j ], sub ); - } - } - } - } -} - - -// EXPORTS // - -module.exports = wrapper; diff --git a/test/fixtures/ternary.js b/test/fixtures/ternary.js deleted file mode 100644 index 0595d5f..0000000 --- a/test/fixtures/ternary.js +++ /dev/null @@ -1,39 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Ternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @returns {number} sum -*/ -function ternary( x, y, z ) { - return x + y + z; -} - - -// EXPORTS // - -module.exports = ternary; diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d6c2c8e..0000000 --- a/test/test.js +++ /dev/null @@ -1,363 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var fill = require( './fixtures/fill.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either a function or an array of functions as a first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( value, types, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object as a second argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided either an array-like object or `null` as a third argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - dispatch( unary, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a positive integer for a fourth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 0, - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a fifth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, value, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a sixth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, 1, value ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function array)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var fcns = [ unary, unary, unary ]; - var data = [ abs, abs, abs ]; - dispatch( fcns, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function argument)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs, abs, abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the length of `data` argument does not match the number of ndarray functions', function test( t ) { - var values; - var i; - - values = [ - [], - [ abs, abs ], - [ abs, abs, abs ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var fcns = [ unary ]; - dispatch( fcns, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the fourth argument is incompatible with the number of input and output ndarrays', function test( t ) { - var values; - var i; - - values = [ - 0, - 1, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of specified input and output ndarrays is zero', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var types = [ 'float64' ]; - dispatch( fill( 3 ), types, null, 1, 0, 0 ); - } -}); - -tape( 'the function returns an ndarray function interface', function test( t ) { - var types; - var data; - var f; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - f = dispatch( unary, types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ unary ], types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( fill( 3 ), types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ fill( 3 ) ], types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.two_arrays.js b/test/test.two_arrays.js deleted file mode 100644 index 071500e..0000000 --- a/test/test.two_arrays.js +++ /dev/null @@ -1,808 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var dtype = require( '@stdlib/ndarray-base-buffer-dtype' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var forEach = require( './fixtures/foreach.js' ); -var map1N = require( './fixtures/map1n.js' ); -var fill = require( './fixtures/fill.js' ); -var sum = require( './fixtures/sum.js' ); - - -// TESTS // - -tape( 'the function returns a function which throws an error if not provided an ndarray for the first argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var ybuf = new Float64Array( 10 ); - var y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( value, y ); - }; - } -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the second argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var xbuf = new Float64Array( 10 ); - var x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( x, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided insufficient arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var f; - var x; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [], - [ x ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided too many arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var ybuf; - var f; - var x; - var y; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [ x, y, y ], - [ x, y, y, y ], - [ x, y, y, y, y ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if unable to resolve a ndarray function supporting the provided array argument data types', function test( t ) { - var values; - var types; - var data; - var xbuf; - var fcn; - var x; - var i; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ abs, abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 4 ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - values = [ - new Uint8Array( 4 ), - new Int32Array( 4 ), - [ 0, 0, 0, 0 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided an array having data type: ' + dtype( values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var y = ndarray( dtype( value ), value, [ value.length ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - }; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only input arrays)', function test( t ) { - var types; - var xbuf; - var ybuf; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only output arrays)', function test( t ) { - var expected; - var types; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only input arrays)', function test( t ) { - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var ctx; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcns = [ - sum( ctx ), - sum( ctx ) - ]; - fcn = dispatch( fcns, types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only output arrays)', function test( t ) { - var expected; - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcns = [ - fill( 3.0 ), - fill( 4.0 ) - ]; - fcn = dispatch( fcns, types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - - fcn = dispatch( forEach, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - - fcn = dispatch( map1N, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - fcns = [ - forEach, - forEach - ]; - fcn = dispatch( fcns, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - fcns = [ - map1N, - map1N - ]; - fcn = dispatch( fcns, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - fcns = [ - unary, - unary - ]; - fcn = dispatch( fcns, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which returns one or more output arrays, if one or more output arrays is specified, and otherwise returns `undefined`', function test( t ) { - var types; - var data; - var xbuf; - var ybuf; - var out; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - // No output arrays... - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, void 0, 'returns expected value' ); - - // One output array... - data = [ - abs, - abs - ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - fcn = dispatch( fill( 3.0 ), types, null, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - // Two output arrays... - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.end(); -}); From 7ed0935f094a567e066a9ec5eb86144766740d58 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jul 2023 09:16:01 +0000 Subject: [PATCH 041/109] Transform error messages --- lib/main.js | 28 ++++++++++++++-------------- package.json | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/main.js b/lib/main.js index a19fa68..7653329 100644 --- a/lib/main.js +++ b/lib/main.js @@ -27,7 +27,7 @@ var isFunctionArray = require( '@stdlib/assert-is-function-array' ); var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var resolveEnum = require( '@stdlib/ndarray-base-dtype-resolve-enum' ); var indexOfTypes = require( './index_of_types.js' ); @@ -111,43 +111,43 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { if ( isFunction( fcns ) ) { fcn = fcns; } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) ); + throw new TypeError( format( '0Mq5s', fcns ) ); } if ( !isCollection( types ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) ); + throw new TypeError( format( '0Mq3A', types ) ); } if ( !isCollection( data ) && data !== null ) { throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); } if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) ); + throw new TypeError( format( '0Mq5u', nargs ) ); } if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) ); + throw new TypeError( format( '0Mq5v', nin ) ); } if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) ); + throw new TypeError( format( '0Mq5w', nout ) ); } narrays = nin + nout; if ( narrays === 0 ) { - throw new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' ); + throw new Error( format( '0Mq0h' ) ); } if ( nargs !== narrays ) { - throw new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' ); + throw new Error( format( '0Mq0i' ) ); } if ( fcn ) { nfcns = types.length / narrays; if ( !isInteger( nfcns ) ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format( '0Mq0j' ) ); } } else { nfcns = fcns.length; if ( types.length !== nfcns*narrays ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format( '0Mq0j' ) ); } } if ( data && data.length !== nfcns ) { - throw new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' ); + throw new Error( format( '0Mq0k' ) ); } types = types2enums( types ); return dispatcher; @@ -177,9 +177,9 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { argc = arguments.length; if ( argc !== nargs ) { if ( argc < nargs ) { - throw new Error( 'invalid invocation. Insufficient arguments.' ); + throw new Error( format( '0Mq0l' ) ); } - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format( '0Mq0m' ) ); } arrays = []; dtypes = []; @@ -200,7 +200,7 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { // Check whether we were able to successfully resolve an ndarray function: if ( idx < 0 ) { - throw new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' ); + throw new TypeError( format( '0Mq0p' ) ); } // Retrieve the ndarray function: if ( fcn ) { diff --git a/package.json b/package.json index 5161a39..0bf3078 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "@stdlib/assert-is-nonnegative-integer": "^0.0.7", "@stdlib/assert-is-positive-integer": "^0.0.7", "@stdlib/ndarray-base-dtype-resolve-enum": "^0.0.1", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/types": "^0.0.14" }, "devDependencies": { From 53503e4dcd3b4d7dfc3e6b369304db76f8da47ac Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jul 2023 18:23:25 +0000 Subject: [PATCH 042/109] Remove files --- index.d.ts | 334 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6516 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index e8f79c8..0000000 --- a/index.d.ts +++ /dev/null @@ -1,334 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* ndarray function. -* -* @param arrays - array containing input and output ndarrays -* @param data - ndarray function data (e.g., a callback) -* -* @example -* var numel = require( `@stdlib/ndarray/base/numel` ); -* var ind2sub = require( `@stdlib/ndarray/ind2sub` ); -* -* function ndarrayFcn( arrays, fcn ) { -* var xord; -* var yord; -* var opts; -* var sub; -* var sh; -* var N; -* var x; -* var y; -* var v; -* var i; -* -* x = arrays[ 0 ]; -* y = arrays[ 1 ]; -* sh = x.shape; -* N = numel( sh ); -* if ( N <= 0 ) { -* return; -* } -* xord = x.order; -* yord = y.order; -* opts = {}; -* opts.order = xord; -* for ( i = 0; i < N; i++ ) { -* // Convert a linear index to subscripts: -* opts.order = xord; -* sub = ind2sub( sh, i, opts ); -* -* // Retrieve an element from `x`: -* v = x.get.apply( x, sub ); -* -* // Convert a linear index to subscripts: -* opts.order = yord; -* sub = ind2sub( sh, i, opts ); -* -* // Append the result of applying the callback: -* sub.push( fcn( v ) ); -* -* // Assign the result to an element in `y`: -* y.set.apply( y, sub ); -* } -* } -*/ -type ndarrayFcn = ( arrays: Array, data?: any ) => void; - -/** -* Interface describing an ndarray function dispatcher. -*/ -interface Dispatcher { - /** - * Invokes an ndarray function based on the provided array data type(s). - * - * @param x - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array - * - * @example - * var nullary = require( `@stdlib/ndarray/base/nullary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function value() { - * return 3.14; - * } - * - * var types = [ 'float64' ]; - * var data = [ value ]; - * - * var fcn = dispatch( nullary, types, data, 1, 0, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( 5 ); - * var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x ); - * // xbuf => [ 3.14, 3.14, 3.14, 3.14, 3.14 ] - */ - ( x: ndarray ): ndarray | void; - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var unary = require( `@stdlib/ndarray/base/unary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * var abs = require( `@stdlib/math/base/special/abs` ); - * - * var types = [ 'float64', 'float64' ]; - * var data = [ abs ]; - * - * var fcn = dispatch( unary, types, data, 2, 1, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - * var ybuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y ); - * // ybuf => [ 1.0, 2.0, 3.0 ] - */ - ( x: ndarray, y: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var ternary = require( `@stdlib/ndarray/base/ternary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add2( x, y ) { - * return x + y; - * } - * - * var types = [ 'float64', 'float64', 'float64' ]; - * var data = [ add2 ]; - * - * var fcn = dispatch( ternary, types, data, 3, 2, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z ); - * // zbuf => [ 2.0, 4.0, 6.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quaternary = require( `@stdlib/ndarray/base/quaternary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add3( x, y, z ) { - * return x + y + z; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add3 ]; - * - * var fcn = dispatch( quaternary, types, data, 4, 3, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w ); - * // wbuf => [ 3.0, 6.0, 9.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @param args - ndarray arguments - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quinary = require( `@stdlib/ndarray/base/quinary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add4( x, y, z, w ) { - * return x + y + z + w; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add4 ]; - * - * var fcn = dispatch( quinary, types, data, 5, 4, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ubuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var u = ndarray( 'float64', ubuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w, u ); - * // ubuf => [ 4.0, 8.0, 12.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray, ...args: Array ): ndarray | void; // tslint:disable-line:max-line-length unified-signatures -} - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param fcns - list of ndarray functions -* @param types - one-dimensional list of ndarray argument data types -* @param data - ndarray function data (e.g., callbacks) -* @param nargs - total number of ndarray function interface arguments -* @param nin - number of input ndarrays -* @param nout - number of output ndarrays -* @throws first argument must be either a function or an array of functions -* @throws second argument must be an array-like object -* @throws third argument must be an array-like object or `null` -* @throws third and first arguments must have the same number of elements -* @throws fourth argument must be a positive integer -* @throws fifth argument must be a nonnegative integer -* @throws sixth argument must be a nonnegative integer -* @throws fourth argument must equal the specified number of input and output arrays -* @throws number of types must match the number of functions times the total number of array arguments for each function -* @throws interface must accept at least one input and/or output ndarray -* @returns ndarray function interface -* -* @example -* var unary = require( `@stdlib/ndarray/base/unary` ); -* var abs = require( `@stdlib/math/base/special/abs` ); -* var Float64Array = require( `@stdlib/array/float64` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var fcn = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* fcn( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function dispatch( fcns: ndarrayFcn | ArrayLike, types: ArrayLike, data: ArrayLike | null, nargs: number, nin: number, nout: number ): Dispatcher; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = dispatch; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 359fc1e..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@esm/index.mjs";function l(r,e,t,s,i,n,o,d,m){var l,a,h,f;for(l=n,h=0;h [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0Mq5s', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0Mq3A', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0Mq5u', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0Mq5v', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0Mq5w', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format( '0Mq0h' ) );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format( '0Mq0i' ) );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format( '0Mq0k' ) );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format( '0Mq0l' ) );\n\t\t\t}\n\t\t\tthrow new Error( format( '0Mq0m' ) );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( v.dtype ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format( '0Mq0p' ) );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n"],"names":["indexOfTypes","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","i","j","dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","out","push","resolveEnum","types2enums","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","dtype","slice"],"mappings":";;01BA6EA,SAASA,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,KAAgBE,EAAGI,GADdE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,CACN,CACD,OAAQ,CACT,CCKA,SAASU,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,sFAAuFV,IAErH,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAQ,UAE1B,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAQ,UAE1B,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAQ,eAI1B,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAQ,UAG3B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAQ,UAG1B,OADAX,EA5GD,SAAsBA,GACrB,IAAIkB,EACAtB,EAGJ,IADAsB,EAAM,GACAtB,EAAI,EAAGA,EAAII,EAAMgB,OAAQpB,IAC9BsB,EAAIC,KAAMC,EAAapB,EAAOJ,KAE/B,OAAOsB,CACR,CAmGSG,CAAarB,GAgBrB,WACC,IAAIsB,EACAC,EACAC,EACAC,EACAC,EACAC,EACA/B,EAGJ,IADA4B,EAAOI,UAAUZ,UACHd,EAAQ,CACrB,GAAKsB,EAAOtB,EACX,MAAM,IAAIa,MAAOJ,EAAQ,UAE1B,MAAM,IAAII,MAAOJ,EAAQ,SACzB,CAGD,IAFAW,EAAS,GACTC,EAAS,GACH3B,EAAI,EAAGA,EAAIM,EAAON,IAAM,CAE7B,IAAMiC,EADNH,EAAIE,UAAWhC,IAEd,MAAKA,EAAIO,EACF,IAAIO,UAAWC,EAAQ,6EAA8Ee,IAErG,IAAIhB,UAAWC,EAAQ,8EAA+Ee,IAG9GJ,EAAOH,KAAMO,GACbH,EAAOJ,KAAMC,EAAaM,EAAEI,OAC5B,CAKD,IAHAL,EAAMzC,EAAcsB,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGkB,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAIb,UAAWC,EAAQ,UAI7BgB,EADIpB,GAGAR,EAAM0B,GAGNxB,EACJ0B,EAAGL,EAAQrB,EAAMwB,IAEjBE,EAAGL,GAEJ,GAAc,IAATlB,EACJ,OAAOkB,EAAQjB,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOkB,EAAOS,MAAO5B,EACrB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d011977..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 42e7e03212addec642903f0a8efffdffb885c392 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Jul 2023 18:24:28 +0000 Subject: [PATCH 043/109] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 59 +- benchmark/benchmark.dispatch_size.js | 156 - benchmark/benchmark.js | 81 - branches.md | 53 - docs/repl.txt | 87 - docs/types/test.ts | 641 --- examples/add.js | 121 - examples/sin.js | 142 - examples/unary.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/index_of_types.js | 106 - lib/main.js | 230 - package.json | 77 +- stats.html | 6177 +++++++++++++++++++++ test/fixtures/binary.js | 38 - test/fixtures/fill.js | 76 - test/fixtures/foreach.js | 72 - test/fixtures/map1n.js | 74 - test/fixtures/nullary.js | 36 - test/fixtures/quaternary.js | 40 - test/fixtures/quinary.js | 41 - test/fixtures/sum.js | 98 - test/fixtures/ternary.js | 39 - test/test.js | 363 -- test/test.two_arrays.js | 808 --- 51 files changed, 6211 insertions(+), 6598 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.dispatch_size.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/add.js delete mode 100644 examples/sin.js delete mode 100644 examples/unary.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/index_of_types.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/fixtures/binary.js delete mode 100644 test/fixtures/fill.js delete mode 100644 test/fixtures/foreach.js delete mode 100644 test/fixtures/map1n.js delete mode 100644 test/fixtures/nullary.js delete mode 100644 test/fixtures/quaternary.js delete mode 100644 test/fixtures/quinary.js delete mode 100644 test/fixtures/sum.js delete mode 100644 test/fixtures/ternary.js delete mode 100644 test/test.js delete mode 100644 test/test.two_arrays.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 3b29b47..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-07-01T06:19:23.286Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ac0b7cd..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 920b304..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 34e41d6..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '43 7 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 3e8e2db..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -291,7 +284,7 @@ console.log( ybuf ); ## 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. +This package is part of [stdlib][stdlib], a standard library 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]. @@ -353,11 +346,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm diff --git a/benchmark/benchmark.dispatch_size.js b/benchmark/benchmark.dispatch_size.js deleted file mode 100644 index 3bd0418..0000000 --- a/benchmark/benchmark.dispatch_size.js +++ /dev/null @@ -1,156 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib/main.js' ); - - -// FUNCTIONS // - -/** -* Evaluates the identity function. -* -* @private -* @param {*} v - value -* @returns {*} input value -*/ -function identity( v ) { - return v; -} - -/** -* Dummy function which throws an error. -* -* @private -* @throws {Error} unexpected error -*/ -function throwError() { - throw new Error( 'unexpected error' ); -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} size - dispatch size -* @returns {Function} benchmark function -*/ -function createBenchmark( size ) { - var types; - var data; - var fcn; - var x; - var y; - var t; - var i; - - types = []; - - // Create dummy types... - for ( i = 0; i < (size-1)*2; i += 2 ) { - t = 'foo' + i; - types.push( t ); - types.push( t ); - } - // Append test types: - types.push( 'float64' ); - types.push( 'float64' ); - - // Define a list of callbacks: - data = []; - for ( i = 0; i < size-1; i++ ) { - data.push( throwError ); - } - // Append a test callback: - data.push( identity ); - - // Create the dispatcher: - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - // Create sample arrays: - x = new Float64Array( 1 ); - y = new Float64Array( x.length ); - - x = ndarray( 'float64', x, [ 1 ], [ 1 ], 0, 'row-major' ); - y = ndarray( 'float64', y, [ 1 ], [ 1 ], 0, 'row-major' ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var z; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x.data[ 0 ] = i; - z = fcn( x, y ); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var size; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - size = pow( 2, i ); - f = createBenchmark( size ); - bench( pkg+':size='+size, f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index a70dc5c..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::fcns_array', function benchmark( b ) { - var types; - var fcns; - var data; - var out; - var i; - - fcns = [ unary ]; - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( fcns, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::fcn_arg', function benchmark( b ) { - var types; - var data; - var out; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( unary, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 6c1b20d..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch" -%% click B href "https://github.com/stdlib-js/ndarray-dispatch/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-dispatch/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-dispatch/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-dispatch/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-dispatch/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch -[production-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 02fe150..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,87 +0,0 @@ - -{{alias}}( fcns, types, data, nargs, nin, nout ) - Returns an ndarray function interface which performs multiple dispatch. - - An ndarray function interface has the following signature: - - f( x, y, ... ) - - where - - - x: ndarray. - - y: ndarray. - - ...: additional ndarrays. - - The number of parameters is derived from `nargs`, the number of input - ndarrays is derived from `nin`, and the number of output ndarrays is derived - from `nout`. - - Parameters - ---------- - fcns: Function|ArrayLikeObject - List of ndarray functions. An ndarray function should have the following - signature: - - f( arrays, data ) - - where - - - arrays: array containing input and output ndarrays. - - data: ndarray function data (e.g., a callback). - - For convenience, a single ndarray function may be provided which will be - invoked whenever the ndarray argument data types match a sequence of - types in `types`. Providing a single ndarray function is particularly - convenient for the case where, regardless of array data types, - traversing arrays remains the same, but the ndarray function `data` - differs (e.g., callbacks which differ based on the array data types). - - types: ArrayLikeObject - One-dimensional list of ndarray argument data types. - - data: ArrayLikeObject|null - ndarray function data (e.g., callbacks). If `null`, a returned ndarray - function interface does **not** provide a `data` argument to an invoked - ndarray function. - - nargs: integer - Total number of ndarray function interface arguments. - - nin: integer - Number of input ndarrays. - - nout: integer - Number of output ndarrays. - - Returns - ------- - fcn: Function - ndarray function interface. - - Examples - -------- - // Define ndarray argument data types: - > var t = [ 'float64', 'float64', 'float32', 'float32' ]; - - // Define a list of ndarray function data (callbacks): - > var d = [ {{alias:@stdlib/math/base/special/abs}}, {{alias:@stdlib/math/base/special/absf}} ]; - - // Create an ndarray function interface for applying unary callbacks: - > var f = {{alias}}( {{alias:@stdlib/ndarray/base/unary}}, t, d, 2, 1, 1 ); - - // Create an input ndarray: - > var xbuf = new {{alias:@stdlib/array/float64}}( [ -1.0, -2.0, -3.0, -4.0 ] ); - > var x = {{alias:@stdlib/ndarray/ctor}}( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Create an output ndarray: - > var ybuf = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 0.0, 0.0 ] ); - > var y = {{alias:@stdlib/ndarray/ctor}}( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Compute the element-wise absolute value: - > f( x, y ); - > ybuf - [ 1.0, 2.0, 3.0, 4.0 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 397185e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,641 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// tslint:disable:max-file-line-count - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import dispatch = require( './index' ); - - -// FUNCTIONS // - -/** -* Nullary callback. -* -* @return input value -*/ -function nullary(): any { - return 5.0; -} - -/** -* Unary callback. -* -* @param x - input value -* @return input value -*/ -function unary( x: any ): any { - return x; -} - -/** -* Binary callback. -* -* @param x - input value -* @param y - input value -* @return output value -*/ -function binary( x: number, y: number ): number { - return x + y; -} - -/** -* Ternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @return output value -*/ -function ternary( x: number, y: number, z: number ): number { - return x + y + z; -} - -/** -* Quaternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @param w - input value -* @return output value -*/ -function quaternary( x: number, y: number, z: number, w: number ): number { - return x + y + z + w; -} - -/** -* Mock `ind2sub` function. -* -* @param shape - dimensions -* @param idx - linear index -* @param opts - options -* @return subscripts -*/ -function ind2sub( shape: ArrayLike, idx: number, opts?: any ): Array { // tslint:disable-line:max-line-length - let out; - let i; - - out = []; - if ( typeof opts === 'object' && opts !== null && opts.order === 'row-major' ) { // tslint:disable-line:max-line-length no-unsafe-any - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } else { - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } - return out; -} - -/** -* Mock ndarray function. -* -* @param arrays - ndarrays -* @param fcn - callback -*/ -function ndarrayFcn( arrays: Array, fcn: ( x: any ) => any ): void { - let xord; - let yord; - let opts; - let sub; - let sh; - let N; - let x; - let y; - let v; - let i; - - x = arrays[ 0 ]; - y = arrays[ 1 ]; - sh = x.shape; - if ( sh.length === 0 ) { - return; - } - N = 1; - for ( i = 0; i < sh.length; i += 1 ) { - N *= sh[ i ]; - } - xord = x.order; - yord = y.order; - opts = { - 'order': '' - }; - opts.order = xord; - for ( i = 0; i < N; i += 1 ) { - // Convert a linear index to subscripts: - opts.order = xord; - sub = ind2sub( sh, i, opts ); - - // Retrieve an element from `x`: - v = x.get.apply( x, sub ); - - // Convert a linear index to subscripts: - opts.order = yord; - sub = ind2sub( sh, i, opts ); - - // Append the result of applying the callback: - sub[ sub.length ] = fcn( v ) as number; - - // Assign the result to an element in `y`: - y.set.apply( y, sub ); - } -} - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a dispatch function... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, 1 ); // $ExpectType Dispatcher - dispatch( [ ndarrayFcn ], types, data, 2, 1, 1 ); // $ExpectType Dispatcher -} - -// The compiler throws an error if the function is provided a first argument which is not either an ndarray function or an array-like object containing ndarray functions... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( '10', types, data, 2, 1, 1 ); // $ExpectError - dispatch( 10, types, data, 2, 1, 1 ); // $ExpectError - dispatch( true, types, data, 2, 1, 1 ); // $ExpectError - dispatch( false, types, data, 2, 1, 1 ); // $ExpectError - dispatch( null, types, data, 2, 1, 1 ); // $ExpectError - dispatch( undefined, types, data, 2, 1, 1 ); // $ExpectError - dispatch( [ '1' ], types, data, 2, 1, 1 ); // $ExpectError - dispatch( {}, types, data, 2, 1, 1 ); // $ExpectError - dispatch( ( x: number ): number => x, types, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object... -{ - const data = [ unary ]; - - dispatch( ndarrayFcn, 10, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, true, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, false, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, null, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, undefined, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, {}, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object or null... -{ - const types = [ 'float64', 'float64' ]; - - dispatch( ndarrayFcn, types, 10, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, true, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, false, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, undefined, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, {}, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, '10', 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, true, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, false, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, null, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, undefined, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, [ '1' ], 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, {}, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, ( x: number ): number => x, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, '10', 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, true, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, false, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, null, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, undefined, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, [ '1' ], 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, {}, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, ( x: number ): number => x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, '10' ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, true ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, false ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, null ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, undefined ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, [ '1' ] ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, {} ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch(); // $ExpectError - dispatch( ndarrayFcn ); // $ExpectError - dispatch( ndarrayFcn, types ); // $ExpectError - dispatch( ndarrayFcn, types, data ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, 1, 0 ); // $ExpectError -} - -// The function returns a dispatch function... -{ - const x = array(); - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const t1 = [ 'float64' ]; - const d1 = [ nullary ]; - const f1 = dispatch( ndarrayFcn, t1, d1, 1, 1, 0 ); - f1( x ); // $ExpectType void | ndarray - - const t2 = [ 'float64', 'float64' ]; - const d2 = [ unary ]; - const f2 = dispatch( ndarrayFcn, t2, d2, 2, 1, 1 ); - f2( x, y ); // $ExpectType void | ndarray - - const t3 = [ 'float64', 'float64', 'float64' ]; - const d3 = [ binary ]; - const f3 = dispatch( ndarrayFcn, t3, d3, 3, 2, 1 ); - f3( x, y, z ); // $ExpectType void | ndarray - - const t4 = [ 'float64', 'float64', 'float64', 'float64' ]; - const d4 = [ ternary ]; - const f4 = dispatch( ndarrayFcn, t4, d4, 4, 3, 1 ); - f4( x, y, z, w ); // $ExpectType void | ndarray - - const t5 = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const d5 = [ quaternary ]; - const f5 = dispatch( ndarrayFcn, t5, d5, 5, 4, 1 ); - f5( x, y, z, w, u ); // $ExpectType void | ndarray -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (1 ndarray)... -{ - const types = [ 'float64' ]; - const data = [ nullary ]; - - const f = dispatch( ndarrayFcn, types, data, 1, 0, 1 ); - f( '10' ); // $ExpectError - f( 10 ); // $ExpectError - f( true ); // $ExpectError - f( false ); // $ExpectError - f( null ); // $ExpectError - f( undefined ); // $ExpectError - f( [ '1' ] ); // $ExpectError - f( {} ); // $ExpectError - f( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( 10, y ); // $ExpectError - f( '10', y ); // $ExpectError - f( true, y ); // $ExpectError - f( false, y ); // $ExpectError - f( null, y ); // $ExpectError - f( undefined, y ); // $ExpectError - f( [ '1' ], y ); // $ExpectError - f( {}, y ); // $ExpectError - f( ( x: number ): number => x, y ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const x = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( x, 10 ); // $ExpectError - f( x, '10' ); // $ExpectError - f( x, true ); // $ExpectError - f( x, false ); // $ExpectError - f( x, null ); // $ExpectError - f( x, undefined ); // $ExpectError - f( x, [ '1' ] ); // $ExpectError - f( x, {} ); // $ExpectError - f( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( 10, y, z ); // $ExpectError - f( '10', y, z ); // $ExpectError - f( true, y, z ); // $ExpectError - f( false, y, z ); // $ExpectError - f( null, y, z ); // $ExpectError - f( undefined, y, z ); // $ExpectError - f( [ '1' ], y, z ); // $ExpectError - f( {}, y, z ); // $ExpectError - f( ( x: number ): number => x, y, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, 10, z ); // $ExpectError - f( x, '10', z ); // $ExpectError - f( x, true, z ); // $ExpectError - f( x, false, z ); // $ExpectError - f( x, null, z ); // $ExpectError - f( x, undefined, z ); // $ExpectError - f( x, [ '1' ], z ); // $ExpectError - f( x, {}, z ); // $ExpectError - f( x, ( x: number ): number => x, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, y, '10' ); // $ExpectError - f( x, y, true ); // $ExpectError - f( x, y, false ); // $ExpectError - f( x, y, null ); // $ExpectError - f( x, y, undefined ); // $ExpectError - f( x, y, [ '1' ] ); // $ExpectError - f( x, y, {} ); // $ExpectError - f( x, y, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( 10, y, z, w ); // $ExpectError - f( '10', y, z, w ); // $ExpectError - f( true, y, z, w ); // $ExpectError - f( false, y, z, w ); // $ExpectError - f( null, y, z, w ); // $ExpectError - f( undefined, y, z, w ); // $ExpectError - f( [ '1' ], y, z, w ); // $ExpectError - f( {}, y, z, w ); // $ExpectError - f( ( x: number ): number => x, y, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, 10, z, w ); // $ExpectError - f( x, '10', z, w ); // $ExpectError - f( x, true, z, w ); // $ExpectError - f( x, false, z, w ); // $ExpectError - f( x, null, z, w ); // $ExpectError - f( x, undefined, z, w ); // $ExpectError - f( x, [ '1' ], z, w ); // $ExpectError - f( x, {}, z, w ); // $ExpectError - f( x, ( x: number ): number => x, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, 10, w ); // $ExpectError - f( x, y, '10', w ); // $ExpectError - f( x, y, true, w ); // $ExpectError - f( x, y, false, w ); // $ExpectError - f( x, y, null, w ); // $ExpectError - f( x, y, undefined, w ); // $ExpectError - f( x, y, [ '1' ], w ); // $ExpectError - f( x, y, {}, w ); // $ExpectError - f( x, y, ( x: number ): number => x, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, z, 10 ); // $ExpectError - f( x, y, z, '10' ); // $ExpectError - f( x, y, z, true ); // $ExpectError - f( x, y, z, false ); // $ExpectError - f( x, y, z, null ); // $ExpectError - f( x, y, z, undefined ); // $ExpectError - f( x, y, z, [ '1' ] ); // $ExpectError - f( x, y, z, {} ); // $ExpectError - f( x, y, z, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( 10, y, z, w, u ); // $ExpectError - f( '10', y, z, w, u ); // $ExpectError - f( true, y, z, w, u ); // $ExpectError - f( false, y, z, w, u ); // $ExpectError - f( null, y, z, w, u ); // $ExpectError - f( undefined, y, z, w, u ); // $ExpectError - f( [ '1' ], y, z, w, u ); // $ExpectError - f( {}, y, z, w, u ); // $ExpectError - f( ( x: number ): number => x, y, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, 10, z, w, u ); // $ExpectError - f( x, '10', z, w, u ); // $ExpectError - f( x, true, z, w, u ); // $ExpectError - f( x, false, z, w, u ); // $ExpectError - f( x, null, z, w, u ); // $ExpectError - f( x, undefined, z, w, u ); // $ExpectError - f( x, [ '1' ], z, w, u ); // $ExpectError - f( x, {}, z, w, u ); // $ExpectError - f( x, ( x: number ): number => x, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, 10, w, u ); // $ExpectError - f( x, y, '10', w, u ); // $ExpectError - f( x, y, true, w, u ); // $ExpectError - f( x, y, false, w, u ); // $ExpectError - f( x, y, null, w, u ); // $ExpectError - f( x, y, undefined, w, u ); // $ExpectError - f( x, y, [ '1' ], w, u ); // $ExpectError - f( x, y, {}, w, u ); // $ExpectError - f( x, y, ( x: number ): number => x, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, 10, u ); // $ExpectError - f( x, y, z, '10', u ); // $ExpectError - f( x, y, z, true, u ); // $ExpectError - f( x, y, z, false, u ); // $ExpectError - f( x, y, z, null, u ); // $ExpectError - f( x, y, z, undefined, u ); // $ExpectError - f( x, y, z, [ '1' ], u ); // $ExpectError - f( x, y, z, {}, u ); // $ExpectError - f( x, y, z, ( x: number ): number => x, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fifth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, w, 10 ); // $ExpectError - f( x, y, z, w, '10' ); // $ExpectError - f( x, y, z, w, true ); // $ExpectError - f( x, y, z, w, false ); // $ExpectError - f( x, y, z, w, null ); // $ExpectError - f( x, y, z, w, undefined ); // $ExpectError - f( x, y, z, w, [ '1' ] ); // $ExpectError - f( x, y, z, w, {} ); // $ExpectError - f( x, y, z, w, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/add.js b/examples/add.js deleted file mode 100644 index 775b711..0000000 --- a/examples/add.js +++ /dev/null @@ -1,121 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var dispatch = require( './../lib' ); - -function add2( arrays ) { - var opts; - var xo; - var yo; - var zo; - var sx; - var sy; - var sz; - var sh; - var N; - var x; - var y; - var z; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - z = arrays[ 2 ]; - xo = x.order; - yo = y.order; - zo = z.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - opts.order = yo; - sy = ind2sub( sh, i, opts ); - v = x.get.apply( x, sx ) + y.get.apply( y, sy ); - - opts.order = zo; - sz = ind2sub( sh, i, opts ); - sz.push( v ); - z.set.apply( z, sz ); - } -} - -var fcns = [ - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2 -]; - -var types = [ - dtypes.float64, dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.int32, dtypes.int32, - dtypes.uint32, dtypes.uint32, dtypes.uint32, - dtypes.int16, dtypes.int16, dtypes.int16, - dtypes.uint16, dtypes.uint16, dtypes.uint16, - dtypes.int8, dtypes.int8, dtypes.int8, - dtypes.uint8, dtypes.uint8, dtypes.uint8, - dtypes.uint8c, dtypes.uint8c, dtypes.uint8c -]; - -var add = dispatch( fcns, types, null, 3, 2, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var zbuf = new Float64Array( xbuf.length ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var z = ndarray( 'float64', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); - -xbuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -ybuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -zbuf = new Int32Array( xbuf.length ); - -x = ndarray( 'int32', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'int32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -z = ndarray( 'int32', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); diff --git a/examples/sin.js b/examples/sin.js deleted file mode 100644 index 8cd4871..0000000 --- a/examples/sin.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int8Array = require( '@stdlib/array-int8' ); -var sin = require( '@stdlib/math-base-special-sin' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/strided-dtypes' ); -var dispatch = require( './../lib' ); - -function apply( arrays, fcn ) { - var opts; - var xo; - var yo; - var sx; - var sy; - var sh; - var N; - var x; - var y; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - xo = x.order; - yo = y.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - v = fcn( x.get.apply( x, sx ) ); - - opts.order = yo; - sy = ind2sub( sh, i, opts ); - sy.push( v ); - y.set.apply( y, sy ); - } -} - -var fcns = [ - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply -]; - -var types = [ - dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float64, - dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.float64, - dtypes.uint32, dtypes.float64, - dtypes.int16, dtypes.float64, - dtypes.int16, dtypes.float32, - dtypes.uint16, dtypes.float64, - dtypes.uint16, dtypes.float32, - dtypes.int8, dtypes.float64, - dtypes.int8, dtypes.float32, - dtypes.uint8, dtypes.float64, - dtypes.uint8, dtypes.float32, - dtypes.uint8c, dtypes.float64, - dtypes.uint8c, dtypes.float32 -]; - -var data = [ - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin -]; - -var sine = dispatch( fcns, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); - -xbuf = new Int8Array( [ 1, 2, 3, 4, 5 ] ); -ybuf = new Float32Array( xbuf.length ); - -x = ndarray( 'int8', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'float32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); diff --git a/examples/unary.js b/examples/unary.js deleted file mode 100644 index e9c3fb4..0000000 --- a/examples/unary.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -var unary = require( '@stdlib/ndarray-base-unary' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var dispatch = require( './../lib' ); - -var types = [ 'float64', 'float64' ]; - -var data = [ - abs -]; - -var absolute = dispatch( unary, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -absolute( x, y ); -console.log( ybuf ); -// => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 610167d..e8f79c8 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..359fc1e --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@esm/index.mjs";function l(r,e,t,s,i,n,o,d,m){var l,a,h,f;for(l=n,h=0;h [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0Mq5s', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0Mq3A', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0Mq5u', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0Mq5v', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0Mq5w', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format( '0Mq0h' ) );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format( '0Mq0i' ) );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format( '0Mq0k' ) );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format( '0Mq0l' ) );\n\t\t\t}\n\t\t\tthrow new Error( format( '0Mq0m' ) );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( v.dtype ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format( '0Mq0p' ) );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n"],"names":["indexOfTypes","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","i","j","dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","out","push","resolveEnum","types2enums","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","dtype","slice"],"mappings":";;01BA6EA,SAASA,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,KAAgBE,EAAGI,GADdE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,CACN,CACD,OAAQ,CACT,CCKA,SAASU,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,sFAAuFV,IAErH,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAQ,UAE1B,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAQ,UAE1B,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAQ,eAI1B,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAQ,UAG3B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAQ,UAG1B,OADAX,EA5GD,SAAsBA,GACrB,IAAIkB,EACAtB,EAGJ,IADAsB,EAAM,GACAtB,EAAI,EAAGA,EAAII,EAAMgB,OAAQpB,IAC9BsB,EAAIC,KAAMC,EAAapB,EAAOJ,KAE/B,OAAOsB,CACR,CAmGSG,CAAarB,GAgBrB,WACC,IAAIsB,EACAC,EACAC,EACAC,EACAC,EACAC,EACA/B,EAGJ,IADA4B,EAAOI,UAAUZ,UACHd,EAAQ,CACrB,GAAKsB,EAAOtB,EACX,MAAM,IAAIa,MAAOJ,EAAQ,UAE1B,MAAM,IAAII,MAAOJ,EAAQ,SACzB,CAGD,IAFAW,EAAS,GACTC,EAAS,GACH3B,EAAI,EAAGA,EAAIM,EAAON,IAAM,CAE7B,IAAMiC,EADNH,EAAIE,UAAWhC,IAEd,MAAKA,EAAIO,EACF,IAAIO,UAAWC,EAAQ,6EAA8Ee,IAErG,IAAIhB,UAAWC,EAAQ,8EAA+Ee,IAG9GJ,EAAOH,KAAMO,GACbH,EAAOJ,KAAMC,EAAaM,EAAEI,OAC5B,CAKD,IAHAL,EAAMzC,EAAcsB,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGkB,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAIb,UAAWC,EAAQ,UAI7BgB,EADIpB,GAGAR,EAAM0B,GAGNxB,EACJ0B,EAAGL,EAAQrB,EAAMwB,IAEjBE,EAAGL,GAEJ,GAAc,IAATlB,EACJ,OAAOkB,EAAQjB,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOkB,EAAOS,MAAO5B,EACrB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 291641d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Create an ndarray function interface which performs multiple dispatch. -* -* @module @stdlib/ndarray-dispatch -* -* @example -* var dispatch = require( '@stdlib/ndarray-dispatch' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/index_of_types.js b/lib/index_of_types.js deleted file mode 100644 index fda2297..0000000 --- a/lib/index_of_types.js +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found). -* -* ## Notes -* -* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types). -* - The function assumes that `x` is stored in row-major order. -* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`. -* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value. -* -* @private -* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension) -* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension) -* @param {ArrayLikeObject} x - input two-dimensional reference array -* @param {integer} strideX1 - `x` stride length along first dimension -* @param {integer} strideX2 - `x` stride length along second dimension -* @param {NonNegativeInteger} offsetX - `x` starting index -* @param {ArrayLikeObject} y - search array -* @param {integer} strideY - `y` stride length -* @param {NonNegativeInteger} offsetY - `y` starting index -* @returns {integer} row index (if found) and `-1` otherwise -* -* @example -* // Define a reference array to search: -* var types = [ -* 'float64', 'float64', 'float64', -* 'float32', 'float32', 'float32', -* 'uint32', 'uint32', 'float64', -* 'int32', 'int32', 'float64', -* 'uint16', 'uint16', 'float64', -* 'int16', 'int16', 'float64', -* 'uint8', 'uint8', 'float64', -* 'int8', 'int8', 'float64' -* ]; -* -* // Define reference array dimensions: -* var N = 8; // rows -* var M = 3; // columns -* -* // Define a search array: -* y1 = [ -* 'float32', 'float32', 'float32', -* ]; -* -* // Find the list of types: -* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 ); -* // returns 1 -* -// Define a search array: -* y2 = [ -* 'float32', 'float32', 'float64', -* ]; -* -* // Find the list of types: -* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 ); -* // returns -1 -*/ -function indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len - var ix; - var iy; - var i; - var j; - - // Search for the first row which matches `y`... - ix = offsetX; - for ( i = 0; i < N; i++ ) { - iy = offsetY; - for ( j = 0; j < M; j++ ) { - if ( x[ ix+(j*strideX2) ] !== y[ iy ] ) { - break; - } - iy += strideY; - } - // If we successfully iterated over all columns, then that means we've found a match... - if ( j === M ) { - return i; - } - ix += strideX1; - } - return -1; -} - - -// EXPORTS // - -module.exports = indexOfTypes; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 7653329..0000000 --- a/lib/main.js +++ /dev/null @@ -1,230 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isFunctionArray = require( '@stdlib/assert-is-function-array' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var resolveEnum = require( '@stdlib/ndarray-base-dtype-resolve-enum' ); -var indexOfTypes = require( './index_of_types.js' ); - - -// FUNCTIONS // - -/** -* Returns a list of data type enumeration constants. -* -* @private -* @param {Collection} types - list of types -* @returns {IntegerArray} list of data type enumeration constants -*/ -function types2enums( types ) { - var out; - var i; - - out = []; - for ( i = 0; i < types.length; i++ ) { - out.push( resolveEnum( types[ i ] ) ); - } - return out; -} - - -// MAIN // - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param {(FunctionArray|Function)} fcns - list of ndarray functions -* @param {Collection} types - one-dimensional list of ndarray argument data types -* @param {(Collection|null)} data - ndarray function data (e.g., callbacks) -* @param {PositiveInteger} nargs - total number of ndarray function interface arguments -* @param {NonNegativeInteger} nin - number of input ndarrays -* @param {NonNegativeInteger} nout - number of output ndarrays -* @throws {TypeError} first argument must be either a function or an array of functions -* @throws {TypeError} second argument must be an array-like object -* @throws {TypeError} third argument must be an array-like object or `null` -* @throws {Error} third and first arguments must have the same number of elements -* @throws {TypeError} fourth argument must be a positive integer -* @throws {TypeError} fifth argument must be a nonnegative integer -* @throws {TypeError} sixth argument must be a nonnegative integer -* @throws {Error} fourth argument must equal the specified number of input and output arrays -* @throws {Error} number of types must match the number of functions times the total number of array arguments for each function -* @throws {Error} interface must accept at least one input and/or output ndarray -* @returns {Function} ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function dispatch( fcns, types, data, nargs, nin, nout ) { - var narrays; - var nfcns; - var fcn; - - if ( isFunction( fcns ) ) { - fcn = fcns; - } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( '0Mq5s', fcns ) ); - } - if ( !isCollection( types ) ) { - throw new TypeError( format( '0Mq3A', types ) ); - } - if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); - } - if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( '0Mq5u', nargs ) ); - } - if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( '0Mq5v', nin ) ); - } - if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( '0Mq5w', nout ) ); - } - narrays = nin + nout; - if ( narrays === 0 ) { - throw new Error( format( '0Mq0h' ) ); - } - if ( nargs !== narrays ) { - throw new Error( format( '0Mq0i' ) ); - } - if ( fcn ) { - nfcns = types.length / narrays; - if ( !isInteger( nfcns ) ) { - throw new Error( format( '0Mq0j' ) ); - } - } else { - nfcns = fcns.length; - if ( types.length !== nfcns*narrays ) { - throw new Error( format( '0Mq0j' ) ); - } - } - if ( data && data.length !== nfcns ) { - throw new Error( format( '0Mq0k' ) ); - } - types = types2enums( types ); - return dispatcher; - - /** - * ndarray function interface which performs multiple dispatch. - * - * @private - * @param {ndarrayLike} x - ndarray - * @param {...ndarrayLike} args - ndarray arguments - * @throws {Error} insufficient arguments - * @throws {Error} too many arguments - * @throws {TypeError} input array arguments must be ndarray-like objects - * @throws {TypeError} output array arguments must be ndarray-like objects - * @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types - * @returns {(ndarrayLike|Array|void)} destination array(s) - */ - function dispatcher() { - var arrays; - var dtypes; - var argc; - var idx; - var v; - var f; - var i; - - argc = arguments.length; - if ( argc !== nargs ) { - if ( argc < nargs ) { - throw new Error( format( '0Mq0l' ) ); - } - throw new Error( format( '0Mq0m' ) ); - } - arrays = []; - dtypes = []; - for ( i = 0; i < nargs; i++ ) { - v = arguments[ i ]; - if ( !isndarrayLike( v ) ) { - if ( i < nin ) { - throw new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) ); - } else { - throw new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) ); - } - } - arrays.push( v ); - dtypes.push( resolveEnum( v.dtype ) ); - } - // Resolve the ndarray function satisfying the input array types: - idx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len - - // Check whether we were able to successfully resolve an ndarray function: - if ( idx < 0 ) { - throw new TypeError( format( '0Mq0p' ) ); - } - // Retrieve the ndarray function: - if ( fcn ) { - f = fcn; - } else { - f = fcns[ idx ]; - } - // Evaluate the ndarray function: - if ( data ) { - f( arrays, data[ idx ] ); - } else { - f( arrays ); - } - if ( nout === 1 ) { - return arrays[ narrays-1 ]; - } - if ( nout === 0 ) { - return; - } - return arrays.slice( nin ); - } -} - - -// EXPORTS // - -module.exports = dispatch; diff --git a/package.json b/package.json index 0bf3078..9d3bbf2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.6", "description": "Create an ndarray function interface which performs multiple dispatch.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,55 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-collection": "^0.0.8", - "@stdlib/assert-is-function": "^0.0.8", - "@stdlib/assert-is-function-array": "^0.0.7", - "@stdlib/assert-is-integer": "^0.0.8", - "@stdlib/assert-is-ndarray-like": "^0.0.6", - "@stdlib/assert-is-nonnegative-integer": "^0.0.7", - "@stdlib/assert-is-positive-integer": "^0.0.7", - "@stdlib/ndarray-base-dtype-resolve-enum": "^0.0.1", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/types": "^0.0.14" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.0.6", - "@stdlib/array-float64": "^0.0.6", - "@stdlib/array-int32": "^0.0.6", - "@stdlib/array-int8": "^0.0.6", - "@stdlib/array-uint8": "^0.0.7", - "@stdlib/bench": "^0.0.12", - "@stdlib/math-base-assert-is-nan": "^0.0.8", - "@stdlib/math-base-special-abs": "^0.0.6", - "@stdlib/math-base-special-pow": "^0.0.7", - "@stdlib/math-base-special-sin": "^0.0.6", - "@stdlib/ndarray-base-buffer-dtype": "^0.0.6", - "@stdlib/ndarray-base-numel": "^0.0.8", - "@stdlib/ndarray-base-unary": "^0.0.6", - "@stdlib/ndarray-ctor": "^0.0.10", - "@stdlib/ndarray-dtypes": "^0.0.9", - "@stdlib/ndarray-ind2sub": "^0.0.7", - "@stdlib/strided-dtypes": "^0.0.8", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "ndarray", @@ -98,7 +26,6 @@ "multimethod", "multimethods" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..53c7cfe --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/fixtures/binary.js b/test/fixtures/binary.js deleted file mode 100644 index a60dfa2..0000000 --- a/test/fixtures/binary.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Binary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @returns {number} sum -*/ -function binary( x, y ) { - return x + y; -} - - -// EXPORTS // - -module.exports = binary; diff --git a/test/fixtures/fill.js b/test/fixtures/fill.js deleted file mode 100644 index 41b2958..0000000 --- a/test/fixtures/fill.js +++ /dev/null @@ -1,76 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which fills one or more ndarrays. -* -* @private -* @param {*} value - fill value -* @returns {Function} ndarray function -*/ -function fill( value ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - */ - function ndarrayFcn( arrays ) { - var opts; - var sub; - var arr; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - opts = { - 'order': '' - }; - for ( j = 0; j < M; j++ ) { - arr = arrays[ j ]; - opts.order = arrays[ j ].order; - for ( i = 0; i < N; i++ ) { - sub = ind2sub( sh, i, opts ); - sub.push( value ); - arr.set.apply( arr, sub ); - } - } - } -} - - -// EXPORTS // - -module.exports = fill; diff --git a/test/fixtures/foreach.js b/test/fixtures/foreach.js deleted file mode 100644 index a426290..0000000 --- a/test/fixtures/foreach.js +++ /dev/null @@ -1,72 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function forEach( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - fcn.apply( null, args ); - } -} - - -// EXPORTS // - -module.exports = forEach; diff --git a/test/fixtures/map1n.js b/test/fixtures/map1n.js deleted file mode 100644 index 614196b..0000000 --- a/test/fixtures/map1n.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function which maps the return value of a callback to `N` arrays. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function map1N( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var v; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - v = fcn(); - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - sub.push( v ); - arrays[ j ].set.apply( arrays[ j ], sub ); - } - } -} - - -// EXPORTS // - -module.exports = map1N; diff --git a/test/fixtures/nullary.js b/test/fixtures/nullary.js deleted file mode 100644 index 4f22126..0000000 --- a/test/fixtures/nullary.js +++ /dev/null @@ -1,36 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Nullary callback. -* -* @private -* @returns {number} value -*/ -function nullary() { - return 3.0; -} - - -// EXPORTS // - -module.exports = nullary; diff --git a/test/fixtures/quaternary.js b/test/fixtures/quaternary.js deleted file mode 100644 index 548437b..0000000 --- a/test/fixtures/quaternary.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quaternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @returns {number} sum -*/ -function quaternary( x, y, z, w ) { - return x + y + z + w; -} - - -// EXPORTS // - -module.exports = quaternary; diff --git a/test/fixtures/quinary.js b/test/fixtures/quinary.js deleted file mode 100644 index 36068de..0000000 --- a/test/fixtures/quinary.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quinary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @param {number} u - input value -* @returns {number} sum -*/ -function quinary( x, y, z, w, u ) { - return x + y + z + w + u; -} - - -// EXPORTS // - -module.exports = quinary; diff --git a/test/fixtures/sum.js b/test/fixtures/sum.js deleted file mode 100644 index efdbb1b..0000000 --- a/test/fixtures/sum.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which computes the sum across one or more ndarrays. -* -* @private -* @param {Object} ctx - context -* @param {number} ctx.sum - initial sum -* @returns {Function} ndarray function -*/ -function wrapper( ctx ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - * @param {Function} [fcn] - callback - */ - function ndarrayFcn( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var f; - var i; - var j; - - if ( arguments.length > 1 ) { - f = fcn; - } - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - if ( f ) { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - ctx.sum += f.apply( null, args ); - } - } else { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - ctx.sum += arrays[ j ].get.apply( arrays[ j ], sub ); - } - } - } - } -} - - -// EXPORTS // - -module.exports = wrapper; diff --git a/test/fixtures/ternary.js b/test/fixtures/ternary.js deleted file mode 100644 index 0595d5f..0000000 --- a/test/fixtures/ternary.js +++ /dev/null @@ -1,39 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Ternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @returns {number} sum -*/ -function ternary( x, y, z ) { - return x + y + z; -} - - -// EXPORTS // - -module.exports = ternary; diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d6c2c8e..0000000 --- a/test/test.js +++ /dev/null @@ -1,363 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var fill = require( './fixtures/fill.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either a function or an array of functions as a first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( value, types, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object as a second argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided either an array-like object or `null` as a third argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - dispatch( unary, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a positive integer for a fourth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 0, - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a fifth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, value, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a sixth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, 1, value ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function array)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var fcns = [ unary, unary, unary ]; - var data = [ abs, abs, abs ]; - dispatch( fcns, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function argument)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs, abs, abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the length of `data` argument does not match the number of ndarray functions', function test( t ) { - var values; - var i; - - values = [ - [], - [ abs, abs ], - [ abs, abs, abs ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var fcns = [ unary ]; - dispatch( fcns, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the fourth argument is incompatible with the number of input and output ndarrays', function test( t ) { - var values; - var i; - - values = [ - 0, - 1, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of specified input and output ndarrays is zero', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var types = [ 'float64' ]; - dispatch( fill( 3 ), types, null, 1, 0, 0 ); - } -}); - -tape( 'the function returns an ndarray function interface', function test( t ) { - var types; - var data; - var f; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - f = dispatch( unary, types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ unary ], types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( fill( 3 ), types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ fill( 3 ) ], types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.two_arrays.js b/test/test.two_arrays.js deleted file mode 100644 index 071500e..0000000 --- a/test/test.two_arrays.js +++ /dev/null @@ -1,808 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var dtype = require( '@stdlib/ndarray-base-buffer-dtype' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var forEach = require( './fixtures/foreach.js' ); -var map1N = require( './fixtures/map1n.js' ); -var fill = require( './fixtures/fill.js' ); -var sum = require( './fixtures/sum.js' ); - - -// TESTS // - -tape( 'the function returns a function which throws an error if not provided an ndarray for the first argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var ybuf = new Float64Array( 10 ); - var y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( value, y ); - }; - } -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the second argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var xbuf = new Float64Array( 10 ); - var x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( x, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided insufficient arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var f; - var x; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [], - [ x ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided too many arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var ybuf; - var f; - var x; - var y; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [ x, y, y ], - [ x, y, y, y ], - [ x, y, y, y, y ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if unable to resolve a ndarray function supporting the provided array argument data types', function test( t ) { - var values; - var types; - var data; - var xbuf; - var fcn; - var x; - var i; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ abs, abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 4 ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - values = [ - new Uint8Array( 4 ), - new Int32Array( 4 ), - [ 0, 0, 0, 0 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided an array having data type: ' + dtype( values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var y = ndarray( dtype( value ), value, [ value.length ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - }; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only input arrays)', function test( t ) { - var types; - var xbuf; - var ybuf; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only output arrays)', function test( t ) { - var expected; - var types; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only input arrays)', function test( t ) { - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var ctx; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcns = [ - sum( ctx ), - sum( ctx ) - ]; - fcn = dispatch( fcns, types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only output arrays)', function test( t ) { - var expected; - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcns = [ - fill( 3.0 ), - fill( 4.0 ) - ]; - fcn = dispatch( fcns, types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - - fcn = dispatch( forEach, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - - fcn = dispatch( map1N, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - fcns = [ - forEach, - forEach - ]; - fcn = dispatch( fcns, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - fcns = [ - map1N, - map1N - ]; - fcn = dispatch( fcns, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - fcns = [ - unary, - unary - ]; - fcn = dispatch( fcns, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which returns one or more output arrays, if one or more output arrays is specified, and otherwise returns `undefined`', function test( t ) { - var types; - var data; - var xbuf; - var ybuf; - var out; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - // No output arrays... - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, void 0, 'returns expected value' ); - - // One output array... - data = [ - abs, - abs - ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - fcn = dispatch( fill( 3.0 ), types, null, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - // Two output arrays... - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.end(); -}); From 585a5382c91a825466e86d37e4a6ebc25a1de3d6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 10 Oct 2023 06:13:24 +0000 Subject: [PATCH 044/109] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f2ae25b..b0977fa 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/assert-is-positive-integer": "^0.1.0", "@stdlib/ndarray-base-dtype-resolve-enum": "^0.1.0", "@stdlib/ndarray-dtype": "github:stdlib-js/ndarray-dtype#main", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.1.0" }, "devDependencies": { From d9f68f50014eb104d662ca346ede1f22d95affa4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 10 Oct 2023 07:13:44 +0000 Subject: [PATCH 045/109] Remove files --- index.d.ts | 334 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6516 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index e8f79c8..0000000 --- a/index.d.ts +++ /dev/null @@ -1,334 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* ndarray function. -* -* @param arrays - array containing input and output ndarrays -* @param data - ndarray function data (e.g., a callback) -* -* @example -* var numel = require( `@stdlib/ndarray/base/numel` ); -* var ind2sub = require( `@stdlib/ndarray/ind2sub` ); -* -* function ndarrayFcn( arrays, fcn ) { -* var xord; -* var yord; -* var opts; -* var sub; -* var sh; -* var N; -* var x; -* var y; -* var v; -* var i; -* -* x = arrays[ 0 ]; -* y = arrays[ 1 ]; -* sh = x.shape; -* N = numel( sh ); -* if ( N <= 0 ) { -* return; -* } -* xord = x.order; -* yord = y.order; -* opts = {}; -* opts.order = xord; -* for ( i = 0; i < N; i++ ) { -* // Convert a linear index to subscripts: -* opts.order = xord; -* sub = ind2sub( sh, i, opts ); -* -* // Retrieve an element from `x`: -* v = x.get.apply( x, sub ); -* -* // Convert a linear index to subscripts: -* opts.order = yord; -* sub = ind2sub( sh, i, opts ); -* -* // Append the result of applying the callback: -* sub.push( fcn( v ) ); -* -* // Assign the result to an element in `y`: -* y.set.apply( y, sub ); -* } -* } -*/ -type ndarrayFcn = ( arrays: Array, data?: any ) => void; - -/** -* Interface describing an ndarray function dispatcher. -*/ -interface Dispatcher { - /** - * Invokes an ndarray function based on the provided array data type(s). - * - * @param x - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array - * - * @example - * var nullary = require( `@stdlib/ndarray/base/nullary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function value() { - * return 3.14; - * } - * - * var types = [ 'float64' ]; - * var data = [ value ]; - * - * var fcn = dispatch( nullary, types, data, 1, 0, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( 5 ); - * var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x ); - * // xbuf => [ 3.14, 3.14, 3.14, 3.14, 3.14 ] - */ - ( x: ndarray ): ndarray | void; - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var unary = require( `@stdlib/ndarray/base/unary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * var abs = require( `@stdlib/math/base/special/abs` ); - * - * var types = [ 'float64', 'float64' ]; - * var data = [ abs ]; - * - * var fcn = dispatch( unary, types, data, 2, 1, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - * var ybuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y ); - * // ybuf => [ 1.0, 2.0, 3.0 ] - */ - ( x: ndarray, y: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var ternary = require( `@stdlib/ndarray/base/ternary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add2( x, y ) { - * return x + y; - * } - * - * var types = [ 'float64', 'float64', 'float64' ]; - * var data = [ add2 ]; - * - * var fcn = dispatch( ternary, types, data, 3, 2, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z ); - * // zbuf => [ 2.0, 4.0, 6.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quaternary = require( `@stdlib/ndarray/base/quaternary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add3( x, y, z ) { - * return x + y + z; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add3 ]; - * - * var fcn = dispatch( quaternary, types, data, 4, 3, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w ); - * // wbuf => [ 3.0, 6.0, 9.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @param args - ndarray arguments - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quinary = require( `@stdlib/ndarray/base/quinary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add4( x, y, z, w ) { - * return x + y + z + w; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add4 ]; - * - * var fcn = dispatch( quinary, types, data, 5, 4, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ubuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var u = ndarray( 'float64', ubuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w, u ); - * // ubuf => [ 4.0, 8.0, 12.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray, ...args: Array ): ndarray | void; // tslint:disable-line:max-line-length unified-signatures -} - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param fcns - list of ndarray functions -* @param types - one-dimensional list of ndarray argument data types -* @param data - ndarray function data (e.g., callbacks) -* @param nargs - total number of ndarray function interface arguments -* @param nin - number of input ndarrays -* @param nout - number of output ndarrays -* @throws first argument must be either a function or an array of functions -* @throws second argument must be an array-like object -* @throws third argument must be an array-like object or `null` -* @throws third and first arguments must have the same number of elements -* @throws fourth argument must be a positive integer -* @throws fifth argument must be a nonnegative integer -* @throws sixth argument must be a nonnegative integer -* @throws fourth argument must equal the specified number of input and output arrays -* @throws number of types must match the number of functions times the total number of array arguments for each function -* @throws interface must accept at least one input and/or output ndarray -* @returns ndarray function interface -* -* @example -* var unary = require( `@stdlib/ndarray/base/unary` ); -* var abs = require( `@stdlib/math/base/special/abs` ); -* var Float64Array = require( `@stdlib/array/float64` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var fcn = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* fcn( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function dispatch( fcns: ndarrayFcn | ArrayLike, types: ArrayLike, data: ArrayLike | null, nargs: number, nin: number, nout: number ): Dispatcher; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = dispatch; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 359fc1e..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@esm/index.mjs";function l(r,e,t,s,i,n,o,d,m){var l,a,h,f;for(l=n,h=0;h [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0Mq5s', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0Mq3A', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0Mq5u', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0Mq5v', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0Mq5w', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format( '0Mq0h' ) );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format( '0Mq0i' ) );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format( '0Mq0j' ) );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format( '0Mq0k' ) );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format( '0Mq0l' ) );\n\t\t\t}\n\t\t\tthrow new Error( format( '0Mq0m' ) );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( v.dtype ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format( '0Mq0p' ) );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n"],"names":["indexOfTypes","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","i","j","dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","out","push","resolveEnum","types2enums","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","dtype","slice"],"mappings":";;01BA6EA,SAASA,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,KAAgBE,EAAGI,GADdE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,CACN,CACD,OAAQ,CACT,CCKA,SAASU,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,sFAAuFV,IAErH,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAQ,UAE1B,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAQ,UAE1B,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAQ,eAI1B,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAQ,UAG3B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAQ,UAG1B,OADAX,EA5GD,SAAsBA,GACrB,IAAIkB,EACAtB,EAGJ,IADAsB,EAAM,GACAtB,EAAI,EAAGA,EAAII,EAAMgB,OAAQpB,IAC9BsB,EAAIC,KAAMC,EAAapB,EAAOJ,KAE/B,OAAOsB,CACR,CAmGSG,CAAarB,GAgBrB,WACC,IAAIsB,EACAC,EACAC,EACAC,EACAC,EACAC,EACA/B,EAGJ,IADA4B,EAAOI,UAAUZ,UACHd,EAAQ,CACrB,GAAKsB,EAAOtB,EACX,MAAM,IAAIa,MAAOJ,EAAQ,UAE1B,MAAM,IAAII,MAAOJ,EAAQ,SACzB,CAGD,IAFAW,EAAS,GACTC,EAAS,GACH3B,EAAI,EAAGA,EAAIM,EAAON,IAAM,CAE7B,IAAMiC,EADNH,EAAIE,UAAWhC,IAEd,MAAKA,EAAIO,EACF,IAAIO,UAAWC,EAAQ,6EAA8Ee,IAErG,IAAIhB,UAAWC,EAAQ,8EAA+Ee,IAG9GJ,EAAOH,KAAMO,GACbH,EAAOJ,KAAMC,EAAaM,EAAEI,OAC5B,CAKD,IAHAL,EAAMzC,EAAcsB,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGkB,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAIb,UAAWC,EAAQ,UAI7BgB,EADIpB,GAGAR,EAAM0B,GAGNxB,EACJ0B,EAAGL,EAAQrB,EAAMwB,IAEjBE,EAAGL,GAEJ,GAAc,IAATlB,EACJ,OAAOkB,EAAQjB,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOkB,EAAOS,MAAO5B,EACrB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 53c7cfe..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From e5724ef557f9524a01cfd2d2b295580fa67bf380 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 10 Oct 2023 07:14:51 +0000 Subject: [PATCH 046/109] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 247 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 59 +- benchmark/benchmark.dispatch_size.js | 156 - benchmark/benchmark.js | 81 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 87 - docs/types/test.ts | 641 --- examples/add.js | 121 - examples/sin.js | 142 - examples/unary.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/index_of_types.js | 106 - lib/main.js | 231 - package.json | 78 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 363 -- test/fixtures/binary.js | 38 - test/fixtures/fill.js | 76 - test/fixtures/foreach.js | 72 - test/fixtures/map1n.js | 74 - test/fixtures/nullary.js | 36 - test/fixtures/quaternary.js | 40 - test/fixtures/quinary.js | 41 - test/fixtures/sum.js | 98 - test/fixtures/ternary.js | 39 - test/test.js | 363 -- test/test.two_arrays.js | 814 --- 55 files changed, 6211 insertions(+), 7063 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.dispatch_size.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/add.js delete mode 100644 examples/sin.js delete mode 100644 examples/unary.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/index_of_types.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/fixtures/binary.js delete mode 100644 test/fixtures/fill.js delete mode 100644 test/fixtures/foreach.js delete mode 100644 test/fixtures/map1n.js delete mode 100644 test/fixtures/nullary.js delete mode 100644 test/fixtures/quaternary.js delete mode 100644 test/fixtures/quinary.js delete mode 100644 test/fixtures/sum.js delete mode 100644 test/fixtures/ternary.js delete mode 100644 test/test.js delete mode 100644 test/test.two_arrays.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ac0b7cd..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 5e92c3e..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index d3aefd6..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '43 7 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -302,7 +295,7 @@ console.log( ybuf ); ## 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. +This package is part of [stdlib][stdlib], a standard library 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]. @@ -364,11 +357,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm diff --git a/benchmark/benchmark.dispatch_size.js b/benchmark/benchmark.dispatch_size.js deleted file mode 100644 index 3bd0418..0000000 --- a/benchmark/benchmark.dispatch_size.js +++ /dev/null @@ -1,156 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib/main.js' ); - - -// FUNCTIONS // - -/** -* Evaluates the identity function. -* -* @private -* @param {*} v - value -* @returns {*} input value -*/ -function identity( v ) { - return v; -} - -/** -* Dummy function which throws an error. -* -* @private -* @throws {Error} unexpected error -*/ -function throwError() { - throw new Error( 'unexpected error' ); -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} size - dispatch size -* @returns {Function} benchmark function -*/ -function createBenchmark( size ) { - var types; - var data; - var fcn; - var x; - var y; - var t; - var i; - - types = []; - - // Create dummy types... - for ( i = 0; i < (size-1)*2; i += 2 ) { - t = 'foo' + i; - types.push( t ); - types.push( t ); - } - // Append test types: - types.push( 'float64' ); - types.push( 'float64' ); - - // Define a list of callbacks: - data = []; - for ( i = 0; i < size-1; i++ ) { - data.push( throwError ); - } - // Append a test callback: - data.push( identity ); - - // Create the dispatcher: - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - // Create sample arrays: - x = new Float64Array( 1 ); - y = new Float64Array( x.length ); - - x = ndarray( 'float64', x, [ 1 ], [ 1 ], 0, 'row-major' ); - y = ndarray( 'float64', y, [ 1 ], [ 1 ], 0, 'row-major' ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var z; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x.data[ 0 ] = i; - z = fcn( x, y ); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var size; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - size = pow( 2, i ); - f = createBenchmark( size ); - bench( pkg+':size='+size, f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index a70dc5c..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::fcns_array', function benchmark( b ) { - var types; - var fcns; - var data; - var out; - var i; - - fcns = [ unary ]; - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( fcns, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::fcn_arg', function benchmark( b ) { - var types; - var data; - var out; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( unary, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 6c1b20d..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch" -%% click B href "https://github.com/stdlib-js/ndarray-dispatch/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-dispatch/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-dispatch/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-dispatch/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-dispatch/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch -[production-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 1295a44..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import dispatch from '../docs/types/index'; -export = dispatch; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index b0f04cf..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var y=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var b=y(function(D,w){ -function k(i,r,e,u,f,m,n,o,l){var h,t,s,a;for(h=m,s=0;s [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( 'invalid invocation. Insufficient arguments.' );\n\t\t\t}\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = dispatch;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an ndarray function interface which performs multiple dispatch.\n*\n* @module @stdlib/ndarray-dispatch\n*\n* @example\n* var dispatch = require( '@stdlib/ndarray-dispatch' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var unary = require( '@stdlib/ndarray-base-unary' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var types = [\n* 'float64', 'float64'\n* ];\n*\n* var data = [\n* abs\n* ];\n*\n* var absolute = dispatch( unary, types, data, 2, 1, 1 );\n*\n* // ...\n*\n* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] );\n* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] );\n*\n* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' );\n* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' );\n*\n* absolute( x, y );\n* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA6EA,SAASC,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,EAAU,CAClF,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,CAAU,IAAME,EAAGI,CAAG,EADjBE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,CACP,CACA,MAAO,EACR,CAKAL,EAAO,QAAUC,ICzGjB,IAAAc,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAoB,QAAS,oCAAqC,EAClEC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAkB,QAAS,kCAAmC,EAC9DC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAc,QAAS,yCAA0C,EACjEC,EAAe,IAYnB,SAASC,EAAaC,EAAQ,CAC7B,IAAIC,EACAC,EAGJ,IADAD,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIF,EAAM,OAAQE,IAC9BD,EAAI,KAAMJ,EAAaG,EAAOE,CAAE,CAAE,CAAE,EAErC,OAAOD,CACR,CAqDA,SAASE,EAAUC,EAAMJ,EAAOK,EAAMC,EAAOC,EAAKC,EAAO,CACxD,IAAIC,EACAC,EACAC,EAEJ,GAAKnB,EAAYY,CAAK,EACrBO,EAAMP,UACK,CAACb,EAAiBa,CAAK,EAClC,MAAM,IAAI,UAAWT,EAAQ,oGAAqGS,CAAK,CAAE,EAE1I,GAAK,CAACX,EAAcO,CAAM,EACzB,MAAM,IAAI,UAAWL,EAAQ,+EAAgFK,CAAM,CAAE,EAEtH,GAAK,CAACP,EAAcY,CAAK,GAAKA,IAAS,KACtC,MAAM,IAAI,UAAWV,EAAQ,sFAAuFU,CAAK,CAAE,EAE5H,GAAK,CAAChB,EAAmBiB,CAAM,EAC9B,MAAM,IAAI,UAAWX,EAAQ,6EAA8EW,CAAM,CAAE,EAEpH,GAAK,CAAClB,EAAsBmB,CAAI,EAC/B,MAAM,IAAI,UAAWZ,EAAQ,+EAAgFY,CAAI,CAAE,EAEpH,GAAK,CAACnB,EAAsBoB,CAAK,EAChC,MAAM,IAAI,UAAWb,EAAQ,+EAAgFa,CAAK,CAAE,EAGrH,GADAC,EAAUF,EAAMC,EACXC,IAAY,EAChB,MAAM,IAAI,MAAO,4IAA6I,EAE/J,GAAKH,IAAUG,EACd,MAAM,IAAI,MAAO,4FAA6F,EAE/G,GAAKE,GAEJ,GADAD,EAAQV,EAAM,OAASS,EAClB,CAACnB,EAAWoB,CAAM,EACtB,MAAM,IAAI,MAAO,8IAA+I,UAGjKA,EAAQN,EAAK,OACRJ,EAAM,SAAWU,EAAMD,EAC3B,MAAM,IAAI,MAAO,8IAA+I,EAGlK,GAAKJ,GAAQA,EAAK,SAAWK,EAC5B,MAAM,IAAI,MAAO,mGAAoG,EAEtH,OAAAV,EAAQD,EAAaC,CAAM,EACpBY,EAeP,SAASA,GAAa,CACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EAGJ,GADAa,EAAO,UAAU,OACZA,IAAST,EACb,MAAKS,EAAOT,EACL,IAAI,MAAO,6CAA8C,EAE1D,IAAI,MAAO,yCAA0C,EAI5D,IAFAO,EAAS,CAAC,EACVC,EAAS,CAAC,EACJZ,EAAI,EAAGA,EAAII,EAAOJ,IAAM,CAE7B,GADAe,EAAI,UAAWf,CAAE,EACZ,CAACR,EAAeuB,CAAE,EACtB,MAAKf,EAAIK,EACF,IAAI,UAAWZ,EAAQ,6EAA8EsB,CAAE,CAAE,EAEzG,IAAI,UAAWtB,EAAQ,8EAA+EsB,CAAE,CAAE,EAGlHJ,EAAO,KAAMI,CAAE,EACfH,EAAO,KAAMjB,EAAaD,EAAUqB,CAAE,CAAE,CAAE,CAC3C,CAKA,GAHAD,EAAMlB,EAAcY,EAAOD,EAAST,EAAOS,EAAS,EAAG,EAAGK,EAAQ,EAAG,CAAE,EAGlEE,EAAM,EACV,MAAM,IAAI,UAAW,6GAA8G,EAcpI,GAXKL,EACJO,EAAIP,EAEJO,EAAId,EAAMY,CAAI,EAGVX,EACJa,EAAGL,EAAQR,EAAMW,CAAI,CAAE,EAEvBE,EAAGL,CAAO,EAENL,IAAS,EACb,OAAOK,EAAQJ,EAAQ,CAAE,EAE1B,GAAKD,IAAS,EAGd,OAAOK,EAAO,MAAON,CAAI,CAC1B,CACD,CAKApB,EAAO,QAAUgB,IC9KjB,IAAIgB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_index_of_types", "__commonJSMin", "exports", "module", "indexOfTypes", "N", "M", "x", "strideX1", "strideX2", "offsetX", "y", "strideY", "offsetY", "ix", "iy", "i", "j", "require_main", "__commonJSMin", "exports", "module", "isNonNegativeInteger", "isPositiveInteger", "isInteger", "isFunctionArray", "isFunction", "isCollection", "isndarrayLike", "format", "getDType", "resolveEnum", "indexOfTypes", "types2enums", "types", "out", "i", "dispatch", "fcns", "data", "nargs", "nin", "nout", "narrays", "nfcns", "fcn", "dispatcher", "arrays", "dtypes", "argc", "idx", "v", "f", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 02fe150..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,87 +0,0 @@ - -{{alias}}( fcns, types, data, nargs, nin, nout ) - Returns an ndarray function interface which performs multiple dispatch. - - An ndarray function interface has the following signature: - - f( x, y, ... ) - - where - - - x: ndarray. - - y: ndarray. - - ...: additional ndarrays. - - The number of parameters is derived from `nargs`, the number of input - ndarrays is derived from `nin`, and the number of output ndarrays is derived - from `nout`. - - Parameters - ---------- - fcns: Function|ArrayLikeObject - List of ndarray functions. An ndarray function should have the following - signature: - - f( arrays, data ) - - where - - - arrays: array containing input and output ndarrays. - - data: ndarray function data (e.g., a callback). - - For convenience, a single ndarray function may be provided which will be - invoked whenever the ndarray argument data types match a sequence of - types in `types`. Providing a single ndarray function is particularly - convenient for the case where, regardless of array data types, - traversing arrays remains the same, but the ndarray function `data` - differs (e.g., callbacks which differ based on the array data types). - - types: ArrayLikeObject - One-dimensional list of ndarray argument data types. - - data: ArrayLikeObject|null - ndarray function data (e.g., callbacks). If `null`, a returned ndarray - function interface does **not** provide a `data` argument to an invoked - ndarray function. - - nargs: integer - Total number of ndarray function interface arguments. - - nin: integer - Number of input ndarrays. - - nout: integer - Number of output ndarrays. - - Returns - ------- - fcn: Function - ndarray function interface. - - Examples - -------- - // Define ndarray argument data types: - > var t = [ 'float64', 'float64', 'float32', 'float32' ]; - - // Define a list of ndarray function data (callbacks): - > var d = [ {{alias:@stdlib/math/base/special/abs}}, {{alias:@stdlib/math/base/special/absf}} ]; - - // Create an ndarray function interface for applying unary callbacks: - > var f = {{alias}}( {{alias:@stdlib/ndarray/base/unary}}, t, d, 2, 1, 1 ); - - // Create an input ndarray: - > var xbuf = new {{alias:@stdlib/array/float64}}( [ -1.0, -2.0, -3.0, -4.0 ] ); - > var x = {{alias:@stdlib/ndarray/ctor}}( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Create an output ndarray: - > var ybuf = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 0.0, 0.0 ] ); - > var y = {{alias:@stdlib/ndarray/ctor}}( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Compute the element-wise absolute value: - > f( x, y ); - > ybuf - [ 1.0, 2.0, 3.0, 4.0 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 397185e..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,641 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// tslint:disable:max-file-line-count - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import dispatch = require( './index' ); - - -// FUNCTIONS // - -/** -* Nullary callback. -* -* @return input value -*/ -function nullary(): any { - return 5.0; -} - -/** -* Unary callback. -* -* @param x - input value -* @return input value -*/ -function unary( x: any ): any { - return x; -} - -/** -* Binary callback. -* -* @param x - input value -* @param y - input value -* @return output value -*/ -function binary( x: number, y: number ): number { - return x + y; -} - -/** -* Ternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @return output value -*/ -function ternary( x: number, y: number, z: number ): number { - return x + y + z; -} - -/** -* Quaternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @param w - input value -* @return output value -*/ -function quaternary( x: number, y: number, z: number, w: number ): number { - return x + y + z + w; -} - -/** -* Mock `ind2sub` function. -* -* @param shape - dimensions -* @param idx - linear index -* @param opts - options -* @return subscripts -*/ -function ind2sub( shape: ArrayLike, idx: number, opts?: any ): Array { // tslint:disable-line:max-line-length - let out; - let i; - - out = []; - if ( typeof opts === 'object' && opts !== null && opts.order === 'row-major' ) { // tslint:disable-line:max-line-length no-unsafe-any - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } else { - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } - return out; -} - -/** -* Mock ndarray function. -* -* @param arrays - ndarrays -* @param fcn - callback -*/ -function ndarrayFcn( arrays: Array, fcn: ( x: any ) => any ): void { - let xord; - let yord; - let opts; - let sub; - let sh; - let N; - let x; - let y; - let v; - let i; - - x = arrays[ 0 ]; - y = arrays[ 1 ]; - sh = x.shape; - if ( sh.length === 0 ) { - return; - } - N = 1; - for ( i = 0; i < sh.length; i += 1 ) { - N *= sh[ i ]; - } - xord = x.order; - yord = y.order; - opts = { - 'order': '' - }; - opts.order = xord; - for ( i = 0; i < N; i += 1 ) { - // Convert a linear index to subscripts: - opts.order = xord; - sub = ind2sub( sh, i, opts ); - - // Retrieve an element from `x`: - v = x.get.apply( x, sub ); - - // Convert a linear index to subscripts: - opts.order = yord; - sub = ind2sub( sh, i, opts ); - - // Append the result of applying the callback: - sub[ sub.length ] = fcn( v ) as number; - - // Assign the result to an element in `y`: - y.set.apply( y, sub ); - } -} - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a dispatch function... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, 1 ); // $ExpectType Dispatcher - dispatch( [ ndarrayFcn ], types, data, 2, 1, 1 ); // $ExpectType Dispatcher -} - -// The compiler throws an error if the function is provided a first argument which is not either an ndarray function or an array-like object containing ndarray functions... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( '10', types, data, 2, 1, 1 ); // $ExpectError - dispatch( 10, types, data, 2, 1, 1 ); // $ExpectError - dispatch( true, types, data, 2, 1, 1 ); // $ExpectError - dispatch( false, types, data, 2, 1, 1 ); // $ExpectError - dispatch( null, types, data, 2, 1, 1 ); // $ExpectError - dispatch( undefined, types, data, 2, 1, 1 ); // $ExpectError - dispatch( [ '1' ], types, data, 2, 1, 1 ); // $ExpectError - dispatch( {}, types, data, 2, 1, 1 ); // $ExpectError - dispatch( ( x: number ): number => x, types, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object... -{ - const data = [ unary ]; - - dispatch( ndarrayFcn, 10, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, true, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, false, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, null, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, undefined, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, {}, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object or null... -{ - const types = [ 'float64', 'float64' ]; - - dispatch( ndarrayFcn, types, 10, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, true, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, false, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, undefined, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, {}, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, '10', 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, true, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, false, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, null, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, undefined, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, [ '1' ], 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, {}, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, ( x: number ): number => x, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, '10', 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, true, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, false, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, null, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, undefined, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, [ '1' ], 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, {}, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, ( x: number ): number => x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, '10' ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, true ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, false ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, null ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, undefined ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, [ '1' ] ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, {} ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch(); // $ExpectError - dispatch( ndarrayFcn ); // $ExpectError - dispatch( ndarrayFcn, types ); // $ExpectError - dispatch( ndarrayFcn, types, data ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, 1, 0 ); // $ExpectError -} - -// The function returns a dispatch function... -{ - const x = array(); - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const t1 = [ 'float64' ]; - const d1 = [ nullary ]; - const f1 = dispatch( ndarrayFcn, t1, d1, 1, 1, 0 ); - f1( x ); // $ExpectType void | ndarray - - const t2 = [ 'float64', 'float64' ]; - const d2 = [ unary ]; - const f2 = dispatch( ndarrayFcn, t2, d2, 2, 1, 1 ); - f2( x, y ); // $ExpectType void | ndarray - - const t3 = [ 'float64', 'float64', 'float64' ]; - const d3 = [ binary ]; - const f3 = dispatch( ndarrayFcn, t3, d3, 3, 2, 1 ); - f3( x, y, z ); // $ExpectType void | ndarray - - const t4 = [ 'float64', 'float64', 'float64', 'float64' ]; - const d4 = [ ternary ]; - const f4 = dispatch( ndarrayFcn, t4, d4, 4, 3, 1 ); - f4( x, y, z, w ); // $ExpectType void | ndarray - - const t5 = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const d5 = [ quaternary ]; - const f5 = dispatch( ndarrayFcn, t5, d5, 5, 4, 1 ); - f5( x, y, z, w, u ); // $ExpectType void | ndarray -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (1 ndarray)... -{ - const types = [ 'float64' ]; - const data = [ nullary ]; - - const f = dispatch( ndarrayFcn, types, data, 1, 0, 1 ); - f( '10' ); // $ExpectError - f( 10 ); // $ExpectError - f( true ); // $ExpectError - f( false ); // $ExpectError - f( null ); // $ExpectError - f( undefined ); // $ExpectError - f( [ '1' ] ); // $ExpectError - f( {} ); // $ExpectError - f( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( 10, y ); // $ExpectError - f( '10', y ); // $ExpectError - f( true, y ); // $ExpectError - f( false, y ); // $ExpectError - f( null, y ); // $ExpectError - f( undefined, y ); // $ExpectError - f( [ '1' ], y ); // $ExpectError - f( {}, y ); // $ExpectError - f( ( x: number ): number => x, y ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const x = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( x, 10 ); // $ExpectError - f( x, '10' ); // $ExpectError - f( x, true ); // $ExpectError - f( x, false ); // $ExpectError - f( x, null ); // $ExpectError - f( x, undefined ); // $ExpectError - f( x, [ '1' ] ); // $ExpectError - f( x, {} ); // $ExpectError - f( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( 10, y, z ); // $ExpectError - f( '10', y, z ); // $ExpectError - f( true, y, z ); // $ExpectError - f( false, y, z ); // $ExpectError - f( null, y, z ); // $ExpectError - f( undefined, y, z ); // $ExpectError - f( [ '1' ], y, z ); // $ExpectError - f( {}, y, z ); // $ExpectError - f( ( x: number ): number => x, y, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, 10, z ); // $ExpectError - f( x, '10', z ); // $ExpectError - f( x, true, z ); // $ExpectError - f( x, false, z ); // $ExpectError - f( x, null, z ); // $ExpectError - f( x, undefined, z ); // $ExpectError - f( x, [ '1' ], z ); // $ExpectError - f( x, {}, z ); // $ExpectError - f( x, ( x: number ): number => x, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, y, '10' ); // $ExpectError - f( x, y, true ); // $ExpectError - f( x, y, false ); // $ExpectError - f( x, y, null ); // $ExpectError - f( x, y, undefined ); // $ExpectError - f( x, y, [ '1' ] ); // $ExpectError - f( x, y, {} ); // $ExpectError - f( x, y, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( 10, y, z, w ); // $ExpectError - f( '10', y, z, w ); // $ExpectError - f( true, y, z, w ); // $ExpectError - f( false, y, z, w ); // $ExpectError - f( null, y, z, w ); // $ExpectError - f( undefined, y, z, w ); // $ExpectError - f( [ '1' ], y, z, w ); // $ExpectError - f( {}, y, z, w ); // $ExpectError - f( ( x: number ): number => x, y, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, 10, z, w ); // $ExpectError - f( x, '10', z, w ); // $ExpectError - f( x, true, z, w ); // $ExpectError - f( x, false, z, w ); // $ExpectError - f( x, null, z, w ); // $ExpectError - f( x, undefined, z, w ); // $ExpectError - f( x, [ '1' ], z, w ); // $ExpectError - f( x, {}, z, w ); // $ExpectError - f( x, ( x: number ): number => x, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, 10, w ); // $ExpectError - f( x, y, '10', w ); // $ExpectError - f( x, y, true, w ); // $ExpectError - f( x, y, false, w ); // $ExpectError - f( x, y, null, w ); // $ExpectError - f( x, y, undefined, w ); // $ExpectError - f( x, y, [ '1' ], w ); // $ExpectError - f( x, y, {}, w ); // $ExpectError - f( x, y, ( x: number ): number => x, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, z, 10 ); // $ExpectError - f( x, y, z, '10' ); // $ExpectError - f( x, y, z, true ); // $ExpectError - f( x, y, z, false ); // $ExpectError - f( x, y, z, null ); // $ExpectError - f( x, y, z, undefined ); // $ExpectError - f( x, y, z, [ '1' ] ); // $ExpectError - f( x, y, z, {} ); // $ExpectError - f( x, y, z, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( 10, y, z, w, u ); // $ExpectError - f( '10', y, z, w, u ); // $ExpectError - f( true, y, z, w, u ); // $ExpectError - f( false, y, z, w, u ); // $ExpectError - f( null, y, z, w, u ); // $ExpectError - f( undefined, y, z, w, u ); // $ExpectError - f( [ '1' ], y, z, w, u ); // $ExpectError - f( {}, y, z, w, u ); // $ExpectError - f( ( x: number ): number => x, y, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, 10, z, w, u ); // $ExpectError - f( x, '10', z, w, u ); // $ExpectError - f( x, true, z, w, u ); // $ExpectError - f( x, false, z, w, u ); // $ExpectError - f( x, null, z, w, u ); // $ExpectError - f( x, undefined, z, w, u ); // $ExpectError - f( x, [ '1' ], z, w, u ); // $ExpectError - f( x, {}, z, w, u ); // $ExpectError - f( x, ( x: number ): number => x, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, 10, w, u ); // $ExpectError - f( x, y, '10', w, u ); // $ExpectError - f( x, y, true, w, u ); // $ExpectError - f( x, y, false, w, u ); // $ExpectError - f( x, y, null, w, u ); // $ExpectError - f( x, y, undefined, w, u ); // $ExpectError - f( x, y, [ '1' ], w, u ); // $ExpectError - f( x, y, {}, w, u ); // $ExpectError - f( x, y, ( x: number ): number => x, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, 10, u ); // $ExpectError - f( x, y, z, '10', u ); // $ExpectError - f( x, y, z, true, u ); // $ExpectError - f( x, y, z, false, u ); // $ExpectError - f( x, y, z, null, u ); // $ExpectError - f( x, y, z, undefined, u ); // $ExpectError - f( x, y, z, [ '1' ], u ); // $ExpectError - f( x, y, z, {}, u ); // $ExpectError - f( x, y, z, ( x: number ): number => x, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fifth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, w, 10 ); // $ExpectError - f( x, y, z, w, '10' ); // $ExpectError - f( x, y, z, w, true ); // $ExpectError - f( x, y, z, w, false ); // $ExpectError - f( x, y, z, w, null ); // $ExpectError - f( x, y, z, w, undefined ); // $ExpectError - f( x, y, z, w, [ '1' ] ); // $ExpectError - f( x, y, z, w, {} ); // $ExpectError - f( x, y, z, w, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/add.js b/examples/add.js deleted file mode 100644 index 775b711..0000000 --- a/examples/add.js +++ /dev/null @@ -1,121 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var dispatch = require( './../lib' ); - -function add2( arrays ) { - var opts; - var xo; - var yo; - var zo; - var sx; - var sy; - var sz; - var sh; - var N; - var x; - var y; - var z; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - z = arrays[ 2 ]; - xo = x.order; - yo = y.order; - zo = z.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - opts.order = yo; - sy = ind2sub( sh, i, opts ); - v = x.get.apply( x, sx ) + y.get.apply( y, sy ); - - opts.order = zo; - sz = ind2sub( sh, i, opts ); - sz.push( v ); - z.set.apply( z, sz ); - } -} - -var fcns = [ - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2 -]; - -var types = [ - dtypes.float64, dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.int32, dtypes.int32, - dtypes.uint32, dtypes.uint32, dtypes.uint32, - dtypes.int16, dtypes.int16, dtypes.int16, - dtypes.uint16, dtypes.uint16, dtypes.uint16, - dtypes.int8, dtypes.int8, dtypes.int8, - dtypes.uint8, dtypes.uint8, dtypes.uint8, - dtypes.uint8c, dtypes.uint8c, dtypes.uint8c -]; - -var add = dispatch( fcns, types, null, 3, 2, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var zbuf = new Float64Array( xbuf.length ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var z = ndarray( 'float64', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); - -xbuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -ybuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -zbuf = new Int32Array( xbuf.length ); - -x = ndarray( 'int32', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'int32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -z = ndarray( 'int32', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); diff --git a/examples/sin.js b/examples/sin.js deleted file mode 100644 index 8cd4871..0000000 --- a/examples/sin.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int8Array = require( '@stdlib/array-int8' ); -var sin = require( '@stdlib/math-base-special-sin' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/strided-dtypes' ); -var dispatch = require( './../lib' ); - -function apply( arrays, fcn ) { - var opts; - var xo; - var yo; - var sx; - var sy; - var sh; - var N; - var x; - var y; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - xo = x.order; - yo = y.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - v = fcn( x.get.apply( x, sx ) ); - - opts.order = yo; - sy = ind2sub( sh, i, opts ); - sy.push( v ); - y.set.apply( y, sy ); - } -} - -var fcns = [ - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply -]; - -var types = [ - dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float64, - dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.float64, - dtypes.uint32, dtypes.float64, - dtypes.int16, dtypes.float64, - dtypes.int16, dtypes.float32, - dtypes.uint16, dtypes.float64, - dtypes.uint16, dtypes.float32, - dtypes.int8, dtypes.float64, - dtypes.int8, dtypes.float32, - dtypes.uint8, dtypes.float64, - dtypes.uint8, dtypes.float32, - dtypes.uint8c, dtypes.float64, - dtypes.uint8c, dtypes.float32 -]; - -var data = [ - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin -]; - -var sine = dispatch( fcns, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); - -xbuf = new Int8Array( [ 1, 2, 3, 4, 5 ] ); -ybuf = new Float32Array( xbuf.length ); - -x = ndarray( 'int8', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'float32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); diff --git a/examples/unary.js b/examples/unary.js deleted file mode 100644 index e9c3fb4..0000000 --- a/examples/unary.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -var unary = require( '@stdlib/ndarray-base-unary' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var dispatch = require( './../lib' ); - -var types = [ 'float64', 'float64' ]; - -var data = [ - abs -]; - -var absolute = dispatch( unary, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -absolute( x, y ); -console.log( ybuf ); -// => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index d0190a1..4a48e2d 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..9dc4d5a --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@v0.1.0-esm/index.mjs";function m(e,r,t,n,i,a,s,o,u){var d,m,l,f;for(d=a,l=0;l [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( 'invalid invocation. Insufficient arguments.' );\n\t\t\t}\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n"],"names":["indexOfTypes","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","i","j","dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","out","push","resolveEnum","types2enums","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","getDType","slice"],"mappings":";;09BA6EA,SAASA,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,KAAgBE,EAAGI,GADdE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,CACN,CACD,OAAQ,CACT,CCMA,SAASU,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,oGAAqGZ,IAEnI,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,+EAAgFX,IAE9G,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,sFAAuFV,IAErH,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,6EAA8ET,IAE5G,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,+EAAgFR,IAE9G,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,+EAAgFP,IAG9G,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAO,8IAElB,GAAKb,IAAUG,EACd,MAAM,IAAIU,MAAO,8FAElB,GAAKR,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAO,qJAIlB,GADAT,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAO,gJAGnB,GAAKd,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAO,qGAGlB,OADAf,EA5GD,SAAsBA,GACrB,IAAIkB,EACAtB,EAGJ,IADAsB,EAAM,GACAtB,EAAI,EAAGA,EAAII,EAAMgB,OAAQpB,IAC9BsB,EAAIC,KAAMC,EAAapB,EAAOJ,KAE/B,OAAOsB,CACR,CAmGSG,CAAarB,GAgBrB,WACC,IAAIsB,EACAC,EACAC,EACAC,EACAC,EACAC,EACA/B,EAGJ,IADA4B,EAAOI,UAAUZ,UACHd,EAAQ,CACrB,GAAKsB,EAAOtB,EACX,MAAM,IAAIa,MAAO,+CAElB,MAAM,IAAIA,MAAO,0CACjB,CAGD,IAFAO,EAAS,GACTC,EAAS,GACH3B,EAAI,EAAGA,EAAIM,EAAON,IAAM,CAE7B,IAAMiC,EADNH,EAAIE,UAAWhC,IAEd,MAAKA,EAAIO,EACF,IAAIO,UAAWC,EAAQ,6EAA8Ee,IAErG,IAAIhB,UAAWC,EAAQ,8EAA+Ee,IAG9GJ,EAAOH,KAAMO,GACbH,EAAOJ,KAAMC,EAAaU,EAAUJ,IACpC,CAKD,IAHAD,EAAMzC,EAAcsB,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGkB,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAIb,UAAW,+GAIrBiB,EADIpB,GAGAR,EAAM0B,GAGNxB,EACJ0B,EAAGL,EAAQrB,EAAMwB,IAEjBE,EAAGL,GAEJ,GAAc,IAATlB,EACJ,OAAOkB,EAAQjB,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOkB,EAAOS,MAAO5B,EACrB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 291641d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Create an ndarray function interface which performs multiple dispatch. -* -* @module @stdlib/ndarray-dispatch -* -* @example -* var dispatch = require( '@stdlib/ndarray-dispatch' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/index_of_types.js b/lib/index_of_types.js deleted file mode 100644 index fda2297..0000000 --- a/lib/index_of_types.js +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found). -* -* ## Notes -* -* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types). -* - The function assumes that `x` is stored in row-major order. -* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`. -* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value. -* -* @private -* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension) -* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension) -* @param {ArrayLikeObject} x - input two-dimensional reference array -* @param {integer} strideX1 - `x` stride length along first dimension -* @param {integer} strideX2 - `x` stride length along second dimension -* @param {NonNegativeInteger} offsetX - `x` starting index -* @param {ArrayLikeObject} y - search array -* @param {integer} strideY - `y` stride length -* @param {NonNegativeInteger} offsetY - `y` starting index -* @returns {integer} row index (if found) and `-1` otherwise -* -* @example -* // Define a reference array to search: -* var types = [ -* 'float64', 'float64', 'float64', -* 'float32', 'float32', 'float32', -* 'uint32', 'uint32', 'float64', -* 'int32', 'int32', 'float64', -* 'uint16', 'uint16', 'float64', -* 'int16', 'int16', 'float64', -* 'uint8', 'uint8', 'float64', -* 'int8', 'int8', 'float64' -* ]; -* -* // Define reference array dimensions: -* var N = 8; // rows -* var M = 3; // columns -* -* // Define a search array: -* y1 = [ -* 'float32', 'float32', 'float32', -* ]; -* -* // Find the list of types: -* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 ); -* // returns 1 -* -// Define a search array: -* y2 = [ -* 'float32', 'float32', 'float64', -* ]; -* -* // Find the list of types: -* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 ); -* // returns -1 -*/ -function indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len - var ix; - var iy; - var i; - var j; - - // Search for the first row which matches `y`... - ix = offsetX; - for ( i = 0; i < N; i++ ) { - iy = offsetY; - for ( j = 0; j < M; j++ ) { - if ( x[ ix+(j*strideX2) ] !== y[ iy ] ) { - break; - } - iy += strideY; - } - // If we successfully iterated over all columns, then that means we've found a match... - if ( j === M ) { - return i; - } - ix += strideX1; - } - return -1; -} - - -// EXPORTS // - -module.exports = indexOfTypes; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 5f4bb5d..0000000 --- a/lib/main.js +++ /dev/null @@ -1,231 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isFunctionArray = require( '@stdlib/assert-is-function-array' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/string-format' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var resolveEnum = require( '@stdlib/ndarray-base-dtype-resolve-enum' ); -var indexOfTypes = require( './index_of_types.js' ); - - -// FUNCTIONS // - -/** -* Returns a list of data type enumeration constants. -* -* @private -* @param {Collection} types - list of types -* @returns {IntegerArray} list of data type enumeration constants -*/ -function types2enums( types ) { - var out; - var i; - - out = []; - for ( i = 0; i < types.length; i++ ) { - out.push( resolveEnum( types[ i ] ) ); - } - return out; -} - - -// MAIN // - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param {(FunctionArray|Function)} fcns - list of ndarray functions -* @param {Collection} types - one-dimensional list of ndarray argument data types -* @param {(Collection|null)} data - ndarray function data (e.g., callbacks) -* @param {PositiveInteger} nargs - total number of ndarray function interface arguments -* @param {NonNegativeInteger} nin - number of input ndarrays -* @param {NonNegativeInteger} nout - number of output ndarrays -* @throws {TypeError} first argument must be either a function or an array of functions -* @throws {TypeError} second argument must be an array-like object -* @throws {TypeError} third argument must be an array-like object or `null` -* @throws {Error} third and first arguments must have the same number of elements -* @throws {TypeError} fourth argument must be a positive integer -* @throws {TypeError} fifth argument must be a nonnegative integer -* @throws {TypeError} sixth argument must be a nonnegative integer -* @throws {Error} fourth argument must equal the specified number of input and output arrays -* @throws {Error} number of types must match the number of functions times the total number of array arguments for each function -* @throws {Error} interface must accept at least one input and/or output ndarray -* @returns {Function} ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function dispatch( fcns, types, data, nargs, nin, nout ) { - var narrays; - var nfcns; - var fcn; - - if ( isFunction( fcns ) ) { - fcn = fcns; - } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) ); - } - if ( !isCollection( types ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) ); - } - if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); - } - if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) ); - } - if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) ); - } - if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) ); - } - narrays = nin + nout; - if ( narrays === 0 ) { - throw new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' ); - } - if ( nargs !== narrays ) { - throw new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' ); - } - if ( fcn ) { - nfcns = types.length / narrays; - if ( !isInteger( nfcns ) ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); - } - } else { - nfcns = fcns.length; - if ( types.length !== nfcns*narrays ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); - } - } - if ( data && data.length !== nfcns ) { - throw new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' ); - } - types = types2enums( types ); - return dispatcher; - - /** - * ndarray function interface which performs multiple dispatch. - * - * @private - * @param {ndarrayLike} x - ndarray - * @param {...ndarrayLike} args - ndarray arguments - * @throws {Error} insufficient arguments - * @throws {Error} too many arguments - * @throws {TypeError} input array arguments must be ndarray-like objects - * @throws {TypeError} output array arguments must be ndarray-like objects - * @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types - * @returns {(ndarrayLike|Array|void)} destination array(s) - */ - function dispatcher() { - var arrays; - var dtypes; - var argc; - var idx; - var v; - var f; - var i; - - argc = arguments.length; - if ( argc !== nargs ) { - if ( argc < nargs ) { - throw new Error( 'invalid invocation. Insufficient arguments.' ); - } - throw new Error( 'invalid invocation. Too many arguments.' ); - } - arrays = []; - dtypes = []; - for ( i = 0; i < nargs; i++ ) { - v = arguments[ i ]; - if ( !isndarrayLike( v ) ) { - if ( i < nin ) { - throw new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) ); - } else { - throw new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) ); - } - } - arrays.push( v ); - dtypes.push( resolveEnum( getDType( v ) ) ); - } - // Resolve the ndarray function satisfying the input array types: - idx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len - - // Check whether we were able to successfully resolve an ndarray function: - if ( idx < 0 ) { - throw new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' ); - } - // Retrieve the ndarray function: - if ( fcn ) { - f = fcn; - } else { - f = fcns[ idx ]; - } - // Evaluate the ndarray function: - if ( data ) { - f( arrays, data[ idx ] ); - } else { - f( arrays ); - } - if ( nout === 1 ) { - return arrays[ narrays-1 ]; - } - if ( nout === 0 ) { - return; - } - return arrays.slice( nin ); - } -} - - -// EXPORTS // - -module.exports = dispatch; diff --git a/package.json b/package.json index b0977fa..06365f4 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Create an ndarray function interface which performs multiple dispatch.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-collection": "^0.1.0", - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/assert-is-function-array": "^0.1.0", - "@stdlib/assert-is-integer": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/assert-is-nonnegative-integer": "^0.1.0", - "@stdlib/assert-is-positive-integer": "^0.1.0", - "@stdlib/ndarray-base-dtype-resolve-enum": "^0.1.0", - "@stdlib/ndarray-dtype": "github:stdlib-js/ndarray-dtype#main", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.1.1", - "@stdlib/array-float64": "^0.1.1", - "@stdlib/array-int32": "^0.1.1", - "@stdlib/array-int8": "^0.1.1", - "@stdlib/array-uint8": "^0.1.1", - "@stdlib/bench": "^0.1.0", - "@stdlib/math-base-assert-is-nan": "^0.1.1", - "@stdlib/math-base-special-abs": "^0.1.0", - "@stdlib/math-base-special-pow": "^0.1.0", - "@stdlib/math-base-special-sin": "^0.1.0", - "@stdlib/ndarray-base-buffer-dtype": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-unary": "^0.1.0", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-dtypes": "^0.1.0", - "@stdlib/ndarray-ind2sub": "^0.1.0", - "@stdlib/strided-dtypes": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "ndarray", @@ -99,7 +26,6 @@ "multimethod", "multimethods" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..14b934d --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index 41aa6ff..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,363 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var dispatch = require( './../../dist' ); - - -// FIXTURES // - -var fill = require( './../fixtures/fill.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either a function or an array of functions as a first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( value, types, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object as a second argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided either an array-like object or `null` as a third argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - dispatch( unary, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a positive integer for a fourth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 0, - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a fifth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, value, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a sixth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, 1, value ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function array)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var fcns = [ unary, unary, unary ]; - var data = [ abs, abs, abs ]; - dispatch( fcns, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function argument)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs, abs, abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the length of `data` argument does not match the number of ndarray functions', function test( t ) { - var values; - var i; - - values = [ - [], - [ abs, abs ], - [ abs, abs, abs ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var fcns = [ unary ]; - dispatch( fcns, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the fourth argument is incompatible with the number of input and output ndarrays', function test( t ) { - var values; - var i; - - values = [ - 0, - 1, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of specified input and output ndarrays is zero', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var types = [ 'float64' ]; - dispatch( fill( 3 ), types, null, 1, 0, 0 ); - } -}); - -tape( 'the function returns an ndarray function interface', function test( t ) { - var types; - var data; - var f; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - f = dispatch( unary, types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ unary ], types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( fill( 3 ), types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ fill( 3 ) ], types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - t.end(); -}); diff --git a/test/fixtures/binary.js b/test/fixtures/binary.js deleted file mode 100644 index a60dfa2..0000000 --- a/test/fixtures/binary.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Binary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @returns {number} sum -*/ -function binary( x, y ) { - return x + y; -} - - -// EXPORTS // - -module.exports = binary; diff --git a/test/fixtures/fill.js b/test/fixtures/fill.js deleted file mode 100644 index 41b2958..0000000 --- a/test/fixtures/fill.js +++ /dev/null @@ -1,76 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which fills one or more ndarrays. -* -* @private -* @param {*} value - fill value -* @returns {Function} ndarray function -*/ -function fill( value ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - */ - function ndarrayFcn( arrays ) { - var opts; - var sub; - var arr; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - opts = { - 'order': '' - }; - for ( j = 0; j < M; j++ ) { - arr = arrays[ j ]; - opts.order = arrays[ j ].order; - for ( i = 0; i < N; i++ ) { - sub = ind2sub( sh, i, opts ); - sub.push( value ); - arr.set.apply( arr, sub ); - } - } - } -} - - -// EXPORTS // - -module.exports = fill; diff --git a/test/fixtures/foreach.js b/test/fixtures/foreach.js deleted file mode 100644 index a426290..0000000 --- a/test/fixtures/foreach.js +++ /dev/null @@ -1,72 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function forEach( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - fcn.apply( null, args ); - } -} - - -// EXPORTS // - -module.exports = forEach; diff --git a/test/fixtures/map1n.js b/test/fixtures/map1n.js deleted file mode 100644 index 614196b..0000000 --- a/test/fixtures/map1n.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function which maps the return value of a callback to `N` arrays. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function map1N( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var v; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - v = fcn(); - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - sub.push( v ); - arrays[ j ].set.apply( arrays[ j ], sub ); - } - } -} - - -// EXPORTS // - -module.exports = map1N; diff --git a/test/fixtures/nullary.js b/test/fixtures/nullary.js deleted file mode 100644 index 4f22126..0000000 --- a/test/fixtures/nullary.js +++ /dev/null @@ -1,36 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Nullary callback. -* -* @private -* @returns {number} value -*/ -function nullary() { - return 3.0; -} - - -// EXPORTS // - -module.exports = nullary; diff --git a/test/fixtures/quaternary.js b/test/fixtures/quaternary.js deleted file mode 100644 index 548437b..0000000 --- a/test/fixtures/quaternary.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quaternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @returns {number} sum -*/ -function quaternary( x, y, z, w ) { - return x + y + z + w; -} - - -// EXPORTS // - -module.exports = quaternary; diff --git a/test/fixtures/quinary.js b/test/fixtures/quinary.js deleted file mode 100644 index 36068de..0000000 --- a/test/fixtures/quinary.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quinary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @param {number} u - input value -* @returns {number} sum -*/ -function quinary( x, y, z, w, u ) { - return x + y + z + w + u; -} - - -// EXPORTS // - -module.exports = quinary; diff --git a/test/fixtures/sum.js b/test/fixtures/sum.js deleted file mode 100644 index efdbb1b..0000000 --- a/test/fixtures/sum.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which computes the sum across one or more ndarrays. -* -* @private -* @param {Object} ctx - context -* @param {number} ctx.sum - initial sum -* @returns {Function} ndarray function -*/ -function wrapper( ctx ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - * @param {Function} [fcn] - callback - */ - function ndarrayFcn( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var f; - var i; - var j; - - if ( arguments.length > 1 ) { - f = fcn; - } - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - if ( f ) { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - ctx.sum += f.apply( null, args ); - } - } else { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - ctx.sum += arrays[ j ].get.apply( arrays[ j ], sub ); - } - } - } - } -} - - -// EXPORTS // - -module.exports = wrapper; diff --git a/test/fixtures/ternary.js b/test/fixtures/ternary.js deleted file mode 100644 index 0595d5f..0000000 --- a/test/fixtures/ternary.js +++ /dev/null @@ -1,39 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Ternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @returns {number} sum -*/ -function ternary( x, y, z ) { - return x + y + z; -} - - -// EXPORTS // - -module.exports = ternary; diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d6c2c8e..0000000 --- a/test/test.js +++ /dev/null @@ -1,363 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var fill = require( './fixtures/fill.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either a function or an array of functions as a first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( value, types, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object as a second argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided either an array-like object or `null` as a third argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - dispatch( unary, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a positive integer for a fourth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 0, - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a fifth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, value, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a sixth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, 1, value ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function array)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var fcns = [ unary, unary, unary ]; - var data = [ abs, abs, abs ]; - dispatch( fcns, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function argument)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs, abs, abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the length of `data` argument does not match the number of ndarray functions', function test( t ) { - var values; - var i; - - values = [ - [], - [ abs, abs ], - [ abs, abs, abs ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var fcns = [ unary ]; - dispatch( fcns, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the fourth argument is incompatible with the number of input and output ndarrays', function test( t ) { - var values; - var i; - - values = [ - 0, - 1, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of specified input and output ndarrays is zero', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var types = [ 'float64' ]; - dispatch( fill( 3 ), types, null, 1, 0, 0 ); - } -}); - -tape( 'the function returns an ndarray function interface', function test( t ) { - var types; - var data; - var f; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - f = dispatch( unary, types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ unary ], types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( fill( 3 ), types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ fill( 3 ) ], types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.two_arrays.js b/test/test.two_arrays.js deleted file mode 100644 index 16eb61b..0000000 --- a/test/test.two_arrays.js +++ /dev/null @@ -1,814 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var dtype = require( '@stdlib/ndarray-base-buffer-dtype' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var forEach = require( './fixtures/foreach.js' ); -var map1N = require( './fixtures/map1n.js' ); -var fill = require( './fixtures/fill.js' ); -var sum = require( './fixtures/sum.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the first argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var ybuf = new Float64Array( 10 ); - var y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( value, y ); - }; - } -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the second argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var xbuf = new Float64Array( 10 ); - var x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( x, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided insufficient arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var f; - var x; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [], - [ x ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided too many arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var ybuf; - var f; - var x; - var y; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [ x, y, y ], - [ x, y, y, y ], - [ x, y, y, y, y ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if unable to resolve a ndarray function supporting the provided array argument data types', function test( t ) { - var values; - var types; - var data; - var xbuf; - var fcn; - var x; - var i; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ abs, abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 4 ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - values = [ - new Uint8Array( 4 ), - new Int32Array( 4 ), - [ 0, 0, 0, 0 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided an array having data type: ' + dtype( values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var y = ndarray( dtype( value ), value, [ value.length ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - }; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only input arrays)', function test( t ) { - var types; - var xbuf; - var ybuf; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only output arrays)', function test( t ) { - var expected; - var types; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only input arrays)', function test( t ) { - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var ctx; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcns = [ - sum( ctx ), - sum( ctx ) - ]; - fcn = dispatch( fcns, types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only output arrays)', function test( t ) { - var expected; - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcns = [ - fill( 3.0 ), - fill( 4.0 ) - ]; - fcn = dispatch( fcns, types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - - fcn = dispatch( forEach, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - - fcn = dispatch( map1N, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - fcns = [ - forEach, - forEach - ]; - fcn = dispatch( fcns, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - fcns = [ - map1N, - map1N - ]; - fcn = dispatch( fcns, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - fcns = [ - unary, - unary - ]; - fcn = dispatch( fcns, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which returns one or more output arrays, if one or more output arrays is specified, and otherwise returns `undefined`', function test( t ) { - var types; - var data; - var xbuf; - var ybuf; - var out; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - // No output arrays... - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, void 0, 'returns expected value' ); - - // One output array... - data = [ - abs, - abs - ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - fcn = dispatch( fill( 3.0 ), types, null, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - // Two output arrays... - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.end(); -}); From 78a57ffb8b12f2cb83ebd87805b93c91586f3a9b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 28 Dec 2023 03:45:39 +0000 Subject: [PATCH 047/109] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9fbece1..5e6762c 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/assert-is-positive-integer": "^0.1.0", "@stdlib/ndarray-base-dtype-resolve-enum": "^0.1.0", "@stdlib/ndarray-dtype": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0" }, "devDependencies": { From e291ec9f2535c33dc438c133f7ce795130c7c97b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 28 Dec 2023 03:46:04 +0000 Subject: [PATCH 048/109] Remove files --- index.d.ts | 334 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6516 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 4a48e2d..0000000 --- a/index.d.ts +++ /dev/null @@ -1,334 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* ndarray function. -* -* @param arrays - array containing input and output ndarrays -* @param data - ndarray function data (e.g., a callback) -* -* @example -* var numel = require( `@stdlib/ndarray/base/numel` ); -* var ind2sub = require( `@stdlib/ndarray/ind2sub` ); -* -* function ndarrayFcn( arrays, fcn ) { -* var xord; -* var yord; -* var opts; -* var sub; -* var sh; -* var N; -* var x; -* var y; -* var v; -* var i; -* -* x = arrays[ 0 ]; -* y = arrays[ 1 ]; -* sh = x.shape; -* N = numel( sh ); -* if ( N <= 0 ) { -* return; -* } -* xord = x.order; -* yord = y.order; -* opts = {}; -* opts.order = xord; -* for ( i = 0; i < N; i++ ) { -* // Convert a linear index to subscripts: -* opts.order = xord; -* sub = ind2sub( sh, i, opts ); -* -* // Retrieve an element from `x`: -* v = x.get.apply( x, sub ); -* -* // Convert a linear index to subscripts: -* opts.order = yord; -* sub = ind2sub( sh, i, opts ); -* -* // Append the result of applying the callback: -* sub.push( fcn( v ) ); -* -* // Assign the result to an element in `y`: -* y.set.apply( y, sub ); -* } -* } -*/ -type ndarrayFcn = ( arrays: Array, data?: any ) => void; - -/** -* Interface describing an ndarray function dispatcher. -*/ -interface Dispatcher { - /** - * Invokes an ndarray function based on the provided array data type(s). - * - * @param x - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array - * - * @example - * var nullary = require( `@stdlib/ndarray/base/nullary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function value() { - * return 3.14; - * } - * - * var types = [ 'float64' ]; - * var data = [ value ]; - * - * var fcn = dispatch( nullary, types, data, 1, 0, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( 5 ); - * var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x ); - * // xbuf => [ 3.14, 3.14, 3.14, 3.14, 3.14 ] - */ - ( x: ndarray ): ndarray | void; - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var unary = require( `@stdlib/ndarray/base/unary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * var abs = require( `@stdlib/math/base/special/abs` ); - * - * var types = [ 'float64', 'float64' ]; - * var data = [ abs ]; - * - * var fcn = dispatch( unary, types, data, 2, 1, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - * var ybuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y ); - * // ybuf => [ 1.0, 2.0, 3.0 ] - */ - ( x: ndarray, y: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var ternary = require( `@stdlib/ndarray/base/ternary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add2( x, y ) { - * return x + y; - * } - * - * var types = [ 'float64', 'float64', 'float64' ]; - * var data = [ add2 ]; - * - * var fcn = dispatch( ternary, types, data, 3, 2, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z ); - * // zbuf => [ 2.0, 4.0, 6.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quaternary = require( `@stdlib/ndarray/base/quaternary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add3( x, y, z ) { - * return x + y + z; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add3 ]; - * - * var fcn = dispatch( quaternary, types, data, 4, 3, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w ); - * // wbuf => [ 3.0, 6.0, 9.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray ): ndarray | void; // tslint:disable-line:unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @param args - ndarray arguments - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quinary = require( `@stdlib/ndarray/base/quinary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add4( x, y, z, w ) { - * return x + y + z + w; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add4 ]; - * - * var fcn = dispatch( quinary, types, data, 5, 4, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ubuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var u = ndarray( 'float64', ubuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w, u ); - * // ubuf => [ 4.0, 8.0, 12.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray, ...args: Array ): ndarray | void; // tslint:disable-line:max-line-length unified-signatures -} - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param fcns - list of ndarray functions -* @param types - one-dimensional list of ndarray argument data types -* @param data - ndarray function data (e.g., callbacks) -* @param nargs - total number of ndarray function interface arguments -* @param nin - number of input ndarrays -* @param nout - number of output ndarrays -* @throws first argument must be either a function or an array of functions -* @throws second argument must be an array-like object -* @throws third argument must be an array-like object or `null` -* @throws third and first arguments must have the same number of elements -* @throws fourth argument must be a positive integer -* @throws fifth argument must be a nonnegative integer -* @throws sixth argument must be a nonnegative integer -* @throws fourth argument must equal the specified number of input and output arrays -* @throws number of types must match the number of functions times the total number of array arguments for each function -* @throws interface must accept at least one input and/or output ndarray -* @returns ndarray function interface -* -* @example -* var unary = require( `@stdlib/ndarray/base/unary` ); -* var abs = require( `@stdlib/math/base/special/abs` ); -* var Float64Array = require( `@stdlib/array/float64` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var fcn = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* fcn( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function dispatch( fcns: ndarrayFcn | ArrayLike, types: ArrayLike, data: ArrayLike | null, nargs: number, nin: number, nout: number ): Dispatcher; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = dispatch; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 9dc4d5a..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@v0.1.0-esm/index.mjs";function m(e,r,t,n,i,a,s,o,u){var d,m,l,f;for(d=a,l=0;l [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( 'invalid invocation. Insufficient arguments.' );\n\t\t\t}\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n"],"names":["indexOfTypes","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","i","j","dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","out","push","resolveEnum","types2enums","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","getDType","slice"],"mappings":";;09BA6EA,SAASA,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,KAAgBE,EAAGI,GADdE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,CACN,CACD,OAAQ,CACT,CCMA,SAASU,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,oGAAqGZ,IAEnI,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,+EAAgFX,IAE9G,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,sFAAuFV,IAErH,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,6EAA8ET,IAE5G,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,+EAAgFR,IAE9G,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,+EAAgFP,IAG9G,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAO,8IAElB,GAAKb,IAAUG,EACd,MAAM,IAAIU,MAAO,8FAElB,GAAKR,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAO,qJAIlB,GADAT,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAO,gJAGnB,GAAKd,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAO,qGAGlB,OADAf,EA5GD,SAAsBA,GACrB,IAAIkB,EACAtB,EAGJ,IADAsB,EAAM,GACAtB,EAAI,EAAGA,EAAII,EAAMgB,OAAQpB,IAC9BsB,EAAIC,KAAMC,EAAapB,EAAOJ,KAE/B,OAAOsB,CACR,CAmGSG,CAAarB,GAgBrB,WACC,IAAIsB,EACAC,EACAC,EACAC,EACAC,EACAC,EACA/B,EAGJ,IADA4B,EAAOI,UAAUZ,UACHd,EAAQ,CACrB,GAAKsB,EAAOtB,EACX,MAAM,IAAIa,MAAO,+CAElB,MAAM,IAAIA,MAAO,0CACjB,CAGD,IAFAO,EAAS,GACTC,EAAS,GACH3B,EAAI,EAAGA,EAAIM,EAAON,IAAM,CAE7B,IAAMiC,EADNH,EAAIE,UAAWhC,IAEd,MAAKA,EAAIO,EACF,IAAIO,UAAWC,EAAQ,6EAA8Ee,IAErG,IAAIhB,UAAWC,EAAQ,8EAA+Ee,IAG9GJ,EAAOH,KAAMO,GACbH,EAAOJ,KAAMC,EAAaU,EAAUJ,IACpC,CAKD,IAHAD,EAAMzC,EAAcsB,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGkB,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAIb,UAAW,+GAIrBiB,EADIpB,GAGAR,EAAM0B,GAGNxB,EACJ0B,EAAGL,EAAQrB,EAAMwB,IAEjBE,EAAGL,GAEJ,GAAc,IAATlB,EACJ,OAAOkB,EAAQjB,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOkB,EAAOS,MAAO5B,EACrB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 14b934d..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 987b779baa27acc96ebc1ec5926439a98413113c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 28 Dec 2023 03:46:58 +0000 Subject: [PATCH 049/109] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 59 +- SECURITY.md | 5 - benchmark/benchmark.dispatch_size.js | 156 - benchmark/benchmark.js | 81 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 87 - docs/types/test.ts | 641 --- examples/add.js | 121 - examples/sin.js | 142 - examples/unary.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/index_of_types.js | 106 - lib/main.js | 231 - package.json | 78 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/binary.js | 38 - test/fixtures/fill.js | 76 - test/fixtures/foreach.js | 72 - test/fixtures/map1n.js | 74 - test/fixtures/nullary.js | 36 - test/fixtures/quaternary.js | 40 - test/fixtures/quinary.js | 41 - test/fixtures/sum.js | 98 - test/fixtures/ternary.js | 39 - test/test.js | 363 -- test/test.two_arrays.js | 814 --- 56 files changed, 6211 insertions(+), 6742 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.dispatch_size.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/add.js delete mode 100644 examples/sin.js delete mode 100644 examples/unary.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/index_of_types.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/fixtures/binary.js delete mode 100644 test/fixtures/fill.js delete mode 100644 test/fixtures/foreach.js delete mode 100644 test/fixtures/map1n.js delete mode 100644 test/fixtures/nullary.js delete mode 100644 test/fixtures/quaternary.js delete mode 100644 test/fixtures/quinary.js delete mode 100644 test/fixtures/sum.js delete mode 100644 test/fixtures/ternary.js delete mode 100644 test/test.js delete mode 100644 test/test.two_arrays.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ac0b7cd..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 30656c4..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 5e92c3e..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c92f5c4..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index d53fd56..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '43 7 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index e1e3539..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -302,7 +295,7 @@ console.log( ybuf ); ## 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. +This package is part of [stdlib][stdlib], a standard library 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]. @@ -362,11 +355,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-dispatch/main/LICENSE -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.dispatch_size.js b/benchmark/benchmark.dispatch_size.js deleted file mode 100644 index 15805ba..0000000 --- a/benchmark/benchmark.dispatch_size.js +++ /dev/null @@ -1,156 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib/main.js' ); - - -// FUNCTIONS // - -/** -* Evaluates the identity function. -* -* @private -* @param {*} v - value -* @returns {*} input value -*/ -function identity( v ) { - return v; -} - -/** -* Dummy function which throws an error. -* -* @private -* @throws {Error} unexpected error -*/ -function throwError() { - throw new Error( 'unexpected error' ); -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} size - dispatch size -* @returns {Function} benchmark function -*/ -function createBenchmark( size ) { - var types; - var data; - var fcn; - var x; - var y; - var t; - var i; - - types = []; - - // Create dummy types... - for ( i = 0; i < (size-1)*2; i += 2 ) { - t = 'foo' + i; - types.push( t ); - types.push( t ); - } - // Append test types: - types.push( 'float64' ); - types.push( 'float64' ); - - // Define a list of callbacks: - data = []; - for ( i = 0; i < size-1; i++ ) { - data.push( throwError ); - } - // Append a test callback: - data.push( identity ); - - // Create the dispatcher: - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - // Create sample arrays: - x = new Float64Array( 1 ); - y = new Float64Array( x.length ); - - x = ndarray( 'float64', x, [ 1 ], [ 1 ], 0, 'row-major' ); - y = ndarray( 'float64', y, [ 1 ], [ 1 ], 0, 'row-major' ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var z; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x.data[ 0 ] = i; - z = fcn( x, y ); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var size; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - size = pow( 2, i ); - f = createBenchmark( size ); - bench( pkg+':size='+size, f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 3c6f450..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::fcns_array', function benchmark( b ) { - var types; - var fcns; - var data; - var out; - var i; - - fcns = [ unary ]; - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( fcns, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::fcn_arg', function benchmark( b ) { - var types; - var data; - var out; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( unary, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 6c1b20d..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch" -%% click B href "https://github.com/stdlib-js/ndarray-dispatch/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-dispatch/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-dispatch/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-dispatch/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-dispatch/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch -[production-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 1295a44..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import dispatch from '../docs/types/index'; -export = dispatch; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7fb29cb..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var y=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var b=y(function(D,w){ -function k(i,r,e,u,f,m,n,o,l){var h,t,s,a;for(h=m,s=0;s [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( 'invalid invocation. Insufficient arguments.' );\n\t\t\t}\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = dispatch;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an ndarray function interface which performs multiple dispatch.\n*\n* @module @stdlib/ndarray-dispatch\n*\n* @example\n* var dispatch = require( '@stdlib/ndarray-dispatch' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var unary = require( '@stdlib/ndarray-base-unary' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var types = [\n* 'float64', 'float64'\n* ];\n*\n* var data = [\n* abs\n* ];\n*\n* var absolute = dispatch( unary, types, data, 2, 1, 1 );\n*\n* // ...\n*\n* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] );\n* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] );\n*\n* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' );\n* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' );\n*\n* absolute( x, y );\n* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA6EA,SAASC,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,EAAU,CAClF,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,CAAU,IAAME,EAAGI,CAAG,EADjBE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,CACP,CACA,MAAO,EACR,CAKAL,EAAO,QAAUC,ICzGjB,IAAAc,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAoB,QAAS,oCAAqC,EAClEC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAkB,QAAS,kCAAmC,EAC9DC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAc,QAAS,yCAA0C,EACjEC,EAAe,IAYnB,SAASC,EAAaC,EAAQ,CAC7B,IAAIC,EACAC,EAGJ,IADAD,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIF,EAAM,OAAQE,IAC9BD,EAAI,KAAMJ,EAAaG,EAAOE,CAAE,CAAE,CAAE,EAErC,OAAOD,CACR,CAqDA,SAASE,EAAUC,EAAMJ,EAAOK,EAAMC,EAAOC,EAAKC,EAAO,CACxD,IAAIC,EACAC,EACAC,EAEJ,GAAKnB,EAAYY,CAAK,EACrBO,EAAMP,UACK,CAACb,EAAiBa,CAAK,EAClC,MAAM,IAAI,UAAWT,EAAQ,oGAAqGS,CAAK,CAAE,EAE1I,GAAK,CAACX,EAAcO,CAAM,EACzB,MAAM,IAAI,UAAWL,EAAQ,+EAAgFK,CAAM,CAAE,EAEtH,GAAK,CAACP,EAAcY,CAAK,GAAKA,IAAS,KACtC,MAAM,IAAI,UAAWV,EAAQ,sFAAuFU,CAAK,CAAE,EAE5H,GAAK,CAAChB,EAAmBiB,CAAM,EAC9B,MAAM,IAAI,UAAWX,EAAQ,6EAA8EW,CAAM,CAAE,EAEpH,GAAK,CAAClB,EAAsBmB,CAAI,EAC/B,MAAM,IAAI,UAAWZ,EAAQ,+EAAgFY,CAAI,CAAE,EAEpH,GAAK,CAACnB,EAAsBoB,CAAK,EAChC,MAAM,IAAI,UAAWb,EAAQ,+EAAgFa,CAAK,CAAE,EAGrH,GADAC,EAAUF,EAAMC,EACXC,IAAY,EAChB,MAAM,IAAI,MAAO,4IAA6I,EAE/J,GAAKH,IAAUG,EACd,MAAM,IAAI,MAAO,4FAA6F,EAE/G,GAAKE,GAEJ,GADAD,EAAQV,EAAM,OAASS,EAClB,CAACnB,EAAWoB,CAAM,EACtB,MAAM,IAAI,MAAO,8IAA+I,UAGjKA,EAAQN,EAAK,OACRJ,EAAM,SAAWU,EAAMD,EAC3B,MAAM,IAAI,MAAO,8IAA+I,EAGlK,GAAKJ,GAAQA,EAAK,SAAWK,EAC5B,MAAM,IAAI,MAAO,mGAAoG,EAEtH,OAAAV,EAAQD,EAAaC,CAAM,EACpBY,EAeP,SAASA,GAAa,CACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EAGJ,GADAa,EAAO,UAAU,OACZA,IAAST,EACb,MAAKS,EAAOT,EACL,IAAI,MAAO,6CAA8C,EAE1D,IAAI,MAAO,yCAA0C,EAI5D,IAFAO,EAAS,CAAC,EACVC,EAAS,CAAC,EACJZ,EAAI,EAAGA,EAAII,EAAOJ,IAAM,CAE7B,GADAe,EAAI,UAAWf,CAAE,EACZ,CAACR,EAAeuB,CAAE,EACtB,MAAKf,EAAIK,EACF,IAAI,UAAWZ,EAAQ,6EAA8EsB,CAAE,CAAE,EAEzG,IAAI,UAAWtB,EAAQ,8EAA+EsB,CAAE,CAAE,EAGlHJ,EAAO,KAAMI,CAAE,EACfH,EAAO,KAAMjB,EAAaD,EAAUqB,CAAE,CAAE,CAAE,CAC3C,CAKA,GAHAD,EAAMlB,EAAcY,EAAOD,EAAST,EAAOS,EAAS,EAAG,EAAGK,EAAQ,EAAG,CAAE,EAGlEE,EAAM,EACV,MAAM,IAAI,UAAW,6GAA8G,EAcpI,GAXKL,EACJO,EAAIP,EAEJO,EAAId,EAAMY,CAAI,EAGVX,EACJa,EAAGL,EAAQR,EAAMW,CAAI,CAAE,EAEvBE,EAAGL,CAAO,EAENL,IAAS,EACb,OAAOK,EAAQJ,EAAQ,CAAE,EAE1B,GAAKD,IAAS,EAGd,OAAOK,EAAO,MAAON,CAAI,CAC1B,CACD,CAKApB,EAAO,QAAUgB,IC9KjB,IAAIgB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_index_of_types", "__commonJSMin", "exports", "module", "indexOfTypes", "N", "M", "x", "strideX1", "strideX2", "offsetX", "y", "strideY", "offsetY", "ix", "iy", "i", "j", "require_main", "__commonJSMin", "exports", "module", "isNonNegativeInteger", "isPositiveInteger", "isInteger", "isFunctionArray", "isFunction", "isCollection", "isndarrayLike", "format", "getDType", "resolveEnum", "indexOfTypes", "types2enums", "types", "out", "i", "dispatch", "fcns", "data", "nargs", "nin", "nout", "narrays", "nfcns", "fcn", "dispatcher", "arrays", "dtypes", "argc", "idx", "v", "f", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 02fe150..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,87 +0,0 @@ - -{{alias}}( fcns, types, data, nargs, nin, nout ) - Returns an ndarray function interface which performs multiple dispatch. - - An ndarray function interface has the following signature: - - f( x, y, ... ) - - where - - - x: ndarray. - - y: ndarray. - - ...: additional ndarrays. - - The number of parameters is derived from `nargs`, the number of input - ndarrays is derived from `nin`, and the number of output ndarrays is derived - from `nout`. - - Parameters - ---------- - fcns: Function|ArrayLikeObject - List of ndarray functions. An ndarray function should have the following - signature: - - f( arrays, data ) - - where - - - arrays: array containing input and output ndarrays. - - data: ndarray function data (e.g., a callback). - - For convenience, a single ndarray function may be provided which will be - invoked whenever the ndarray argument data types match a sequence of - types in `types`. Providing a single ndarray function is particularly - convenient for the case where, regardless of array data types, - traversing arrays remains the same, but the ndarray function `data` - differs (e.g., callbacks which differ based on the array data types). - - types: ArrayLikeObject - One-dimensional list of ndarray argument data types. - - data: ArrayLikeObject|null - ndarray function data (e.g., callbacks). If `null`, a returned ndarray - function interface does **not** provide a `data` argument to an invoked - ndarray function. - - nargs: integer - Total number of ndarray function interface arguments. - - nin: integer - Number of input ndarrays. - - nout: integer - Number of output ndarrays. - - Returns - ------- - fcn: Function - ndarray function interface. - - Examples - -------- - // Define ndarray argument data types: - > var t = [ 'float64', 'float64', 'float32', 'float32' ]; - - // Define a list of ndarray function data (callbacks): - > var d = [ {{alias:@stdlib/math/base/special/abs}}, {{alias:@stdlib/math/base/special/absf}} ]; - - // Create an ndarray function interface for applying unary callbacks: - > var f = {{alias}}( {{alias:@stdlib/ndarray/base/unary}}, t, d, 2, 1, 1 ); - - // Create an input ndarray: - > var xbuf = new {{alias:@stdlib/array/float64}}( [ -1.0, -2.0, -3.0, -4.0 ] ); - > var x = {{alias:@stdlib/ndarray/ctor}}( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Create an output ndarray: - > var ybuf = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 0.0, 0.0 ] ); - > var y = {{alias:@stdlib/ndarray/ctor}}( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Compute the element-wise absolute value: - > f( x, y ); - > ybuf - [ 1.0, 2.0, 3.0, 4.0 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 3cba031..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,641 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable max-lines */ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import dispatch = require( './index' ); - - -// FUNCTIONS // - -/** -* Nullary callback. -* -* @return input value -*/ -function nullary(): any { - return 5.0; -} - -/** -* Unary callback. -* -* @param x - input value -* @return input value -*/ -function unary( x: any ): any { - return x; -} - -/** -* Binary callback. -* -* @param x - input value -* @param y - input value -* @return output value -*/ -function binary( x: number, y: number ): number { - return x + y; -} - -/** -* Ternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @return output value -*/ -function ternary( x: number, y: number, z: number ): number { - return x + y + z; -} - -/** -* Quaternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @param w - input value -* @return output value -*/ -function quaternary( x: number, y: number, z: number, w: number ): number { - return x + y + z + w; -} - -/** -* Mock `ind2sub` function. -* -* @param shape - dimensions -* @param idx - linear index -* @param opts - options -* @return subscripts -*/ -function ind2sub( shape: ArrayLike, idx: number, opts?: any ): Array { - let out; - let i; - - out = []; - if ( typeof opts === 'object' && opts !== null && opts.order === 'row-major' ) { no-unsafe-any - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } else { - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } - return out; -} - -/** -* Mock ndarray function. -* -* @param arrays - ndarrays -* @param fcn - callback -*/ -function ndarrayFcn( arrays: Array, fcn: ( x: any ) => any ): void { - let xord; - let yord; - let opts; - let sub; - let sh; - let N; - let x; - let y; - let v; - let i; - - x = arrays[ 0 ]; - y = arrays[ 1 ]; - sh = x.shape; - if ( sh.length === 0 ) { - return; - } - N = 1; - for ( i = 0; i < sh.length; i += 1 ) { - N *= sh[ i ]; - } - xord = x.order; - yord = y.order; - opts = { - 'order': '' - }; - opts.order = xord; - for ( i = 0; i < N; i += 1 ) { - // Convert a linear index to subscripts: - opts.order = xord; - sub = ind2sub( sh, i, opts ); - - // Retrieve an element from `x`: - v = x.get.apply( x, sub ); - - // Convert a linear index to subscripts: - opts.order = yord; - sub = ind2sub( sh, i, opts ); - - // Append the result of applying the callback: - sub[ sub.length ] = fcn( v ) as number; - - // Assign the result to an element in `y`: - y.set.apply( y, sub ); - } -} - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a dispatch function... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, 1 ); // $ExpectType Dispatcher - dispatch( [ ndarrayFcn ], types, data, 2, 1, 1 ); // $ExpectType Dispatcher -} - -// The compiler throws an error if the function is provided a first argument which is not either an ndarray function or an array-like object containing ndarray functions... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( '10', types, data, 2, 1, 1 ); // $ExpectError - dispatch( 10, types, data, 2, 1, 1 ); // $ExpectError - dispatch( true, types, data, 2, 1, 1 ); // $ExpectError - dispatch( false, types, data, 2, 1, 1 ); // $ExpectError - dispatch( null, types, data, 2, 1, 1 ); // $ExpectError - dispatch( undefined, types, data, 2, 1, 1 ); // $ExpectError - dispatch( [ '1' ], types, data, 2, 1, 1 ); // $ExpectError - dispatch( {}, types, data, 2, 1, 1 ); // $ExpectError - dispatch( ( x: number ): number => x, types, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object... -{ - const data = [ unary ]; - - dispatch( ndarrayFcn, 10, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, true, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, false, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, null, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, undefined, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, {}, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object or null... -{ - const types = [ 'float64', 'float64' ]; - - dispatch( ndarrayFcn, types, 10, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, true, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, false, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, undefined, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, {}, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, '10', 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, true, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, false, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, null, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, undefined, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, [ '1' ], 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, {}, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, ( x: number ): number => x, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, '10', 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, true, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, false, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, null, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, undefined, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, [ '1' ], 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, {}, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, ( x: number ): number => x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, '10' ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, true ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, false ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, null ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, undefined ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, [ '1' ] ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, {} ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch(); // $ExpectError - dispatch( ndarrayFcn ); // $ExpectError - dispatch( ndarrayFcn, types ); // $ExpectError - dispatch( ndarrayFcn, types, data ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, 1, 0 ); // $ExpectError -} - -// The function returns a dispatch function... -{ - const x = array(); - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const t1 = [ 'float64' ]; - const d1 = [ nullary ]; - const f1 = dispatch( ndarrayFcn, t1, d1, 1, 1, 0 ); - f1( x ); // $ExpectType void | ndarray - - const t2 = [ 'float64', 'float64' ]; - const d2 = [ unary ]; - const f2 = dispatch( ndarrayFcn, t2, d2, 2, 1, 1 ); - f2( x, y ); // $ExpectType void | ndarray - - const t3 = [ 'float64', 'float64', 'float64' ]; - const d3 = [ binary ]; - const f3 = dispatch( ndarrayFcn, t3, d3, 3, 2, 1 ); - f3( x, y, z ); // $ExpectType void | ndarray - - const t4 = [ 'float64', 'float64', 'float64', 'float64' ]; - const d4 = [ ternary ]; - const f4 = dispatch( ndarrayFcn, t4, d4, 4, 3, 1 ); - f4( x, y, z, w ); // $ExpectType void | ndarray - - const t5 = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const d5 = [ quaternary ]; - const f5 = dispatch( ndarrayFcn, t5, d5, 5, 4, 1 ); - f5( x, y, z, w, u ); // $ExpectType void | ndarray -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (1 ndarray)... -{ - const types = [ 'float64' ]; - const data = [ nullary ]; - - const f = dispatch( ndarrayFcn, types, data, 1, 0, 1 ); - f( '10' ); // $ExpectError - f( 10 ); // $ExpectError - f( true ); // $ExpectError - f( false ); // $ExpectError - f( null ); // $ExpectError - f( undefined ); // $ExpectError - f( [ '1' ] ); // $ExpectError - f( {} ); // $ExpectError - f( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( 10, y ); // $ExpectError - f( '10', y ); // $ExpectError - f( true, y ); // $ExpectError - f( false, y ); // $ExpectError - f( null, y ); // $ExpectError - f( undefined, y ); // $ExpectError - f( [ '1' ], y ); // $ExpectError - f( {}, y ); // $ExpectError - f( ( x: number ): number => x, y ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const x = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( x, 10 ); // $ExpectError - f( x, '10' ); // $ExpectError - f( x, true ); // $ExpectError - f( x, false ); // $ExpectError - f( x, null ); // $ExpectError - f( x, undefined ); // $ExpectError - f( x, [ '1' ] ); // $ExpectError - f( x, {} ); // $ExpectError - f( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( 10, y, z ); // $ExpectError - f( '10', y, z ); // $ExpectError - f( true, y, z ); // $ExpectError - f( false, y, z ); // $ExpectError - f( null, y, z ); // $ExpectError - f( undefined, y, z ); // $ExpectError - f( [ '1' ], y, z ); // $ExpectError - f( {}, y, z ); // $ExpectError - f( ( x: number ): number => x, y, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, 10, z ); // $ExpectError - f( x, '10', z ); // $ExpectError - f( x, true, z ); // $ExpectError - f( x, false, z ); // $ExpectError - f( x, null, z ); // $ExpectError - f( x, undefined, z ); // $ExpectError - f( x, [ '1' ], z ); // $ExpectError - f( x, {}, z ); // $ExpectError - f( x, ( x: number ): number => x, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, y, '10' ); // $ExpectError - f( x, y, true ); // $ExpectError - f( x, y, false ); // $ExpectError - f( x, y, null ); // $ExpectError - f( x, y, undefined ); // $ExpectError - f( x, y, [ '1' ] ); // $ExpectError - f( x, y, {} ); // $ExpectError - f( x, y, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( 10, y, z, w ); // $ExpectError - f( '10', y, z, w ); // $ExpectError - f( true, y, z, w ); // $ExpectError - f( false, y, z, w ); // $ExpectError - f( null, y, z, w ); // $ExpectError - f( undefined, y, z, w ); // $ExpectError - f( [ '1' ], y, z, w ); // $ExpectError - f( {}, y, z, w ); // $ExpectError - f( ( x: number ): number => x, y, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, 10, z, w ); // $ExpectError - f( x, '10', z, w ); // $ExpectError - f( x, true, z, w ); // $ExpectError - f( x, false, z, w ); // $ExpectError - f( x, null, z, w ); // $ExpectError - f( x, undefined, z, w ); // $ExpectError - f( x, [ '1' ], z, w ); // $ExpectError - f( x, {}, z, w ); // $ExpectError - f( x, ( x: number ): number => x, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, 10, w ); // $ExpectError - f( x, y, '10', w ); // $ExpectError - f( x, y, true, w ); // $ExpectError - f( x, y, false, w ); // $ExpectError - f( x, y, null, w ); // $ExpectError - f( x, y, undefined, w ); // $ExpectError - f( x, y, [ '1' ], w ); // $ExpectError - f( x, y, {}, w ); // $ExpectError - f( x, y, ( x: number ): number => x, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, z, 10 ); // $ExpectError - f( x, y, z, '10' ); // $ExpectError - f( x, y, z, true ); // $ExpectError - f( x, y, z, false ); // $ExpectError - f( x, y, z, null ); // $ExpectError - f( x, y, z, undefined ); // $ExpectError - f( x, y, z, [ '1' ] ); // $ExpectError - f( x, y, z, {} ); // $ExpectError - f( x, y, z, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( 10, y, z, w, u ); // $ExpectError - f( '10', y, z, w, u ); // $ExpectError - f( true, y, z, w, u ); // $ExpectError - f( false, y, z, w, u ); // $ExpectError - f( null, y, z, w, u ); // $ExpectError - f( undefined, y, z, w, u ); // $ExpectError - f( [ '1' ], y, z, w, u ); // $ExpectError - f( {}, y, z, w, u ); // $ExpectError - f( ( x: number ): number => x, y, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, 10, z, w, u ); // $ExpectError - f( x, '10', z, w, u ); // $ExpectError - f( x, true, z, w, u ); // $ExpectError - f( x, false, z, w, u ); // $ExpectError - f( x, null, z, w, u ); // $ExpectError - f( x, undefined, z, w, u ); // $ExpectError - f( x, [ '1' ], z, w, u ); // $ExpectError - f( x, {}, z, w, u ); // $ExpectError - f( x, ( x: number ): number => x, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, 10, w, u ); // $ExpectError - f( x, y, '10', w, u ); // $ExpectError - f( x, y, true, w, u ); // $ExpectError - f( x, y, false, w, u ); // $ExpectError - f( x, y, null, w, u ); // $ExpectError - f( x, y, undefined, w, u ); // $ExpectError - f( x, y, [ '1' ], w, u ); // $ExpectError - f( x, y, {}, w, u ); // $ExpectError - f( x, y, ( x: number ): number => x, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, 10, u ); // $ExpectError - f( x, y, z, '10', u ); // $ExpectError - f( x, y, z, true, u ); // $ExpectError - f( x, y, z, false, u ); // $ExpectError - f( x, y, z, null, u ); // $ExpectError - f( x, y, z, undefined, u ); // $ExpectError - f( x, y, z, [ '1' ], u ); // $ExpectError - f( x, y, z, {}, u ); // $ExpectError - f( x, y, z, ( x: number ): number => x, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fifth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, w, 10 ); // $ExpectError - f( x, y, z, w, '10' ); // $ExpectError - f( x, y, z, w, true ); // $ExpectError - f( x, y, z, w, false ); // $ExpectError - f( x, y, z, w, null ); // $ExpectError - f( x, y, z, w, undefined ); // $ExpectError - f( x, y, z, w, [ '1' ] ); // $ExpectError - f( x, y, z, w, {} ); // $ExpectError - f( x, y, z, w, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/add.js b/examples/add.js deleted file mode 100644 index 775b711..0000000 --- a/examples/add.js +++ /dev/null @@ -1,121 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var dispatch = require( './../lib' ); - -function add2( arrays ) { - var opts; - var xo; - var yo; - var zo; - var sx; - var sy; - var sz; - var sh; - var N; - var x; - var y; - var z; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - z = arrays[ 2 ]; - xo = x.order; - yo = y.order; - zo = z.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - opts.order = yo; - sy = ind2sub( sh, i, opts ); - v = x.get.apply( x, sx ) + y.get.apply( y, sy ); - - opts.order = zo; - sz = ind2sub( sh, i, opts ); - sz.push( v ); - z.set.apply( z, sz ); - } -} - -var fcns = [ - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2 -]; - -var types = [ - dtypes.float64, dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.int32, dtypes.int32, - dtypes.uint32, dtypes.uint32, dtypes.uint32, - dtypes.int16, dtypes.int16, dtypes.int16, - dtypes.uint16, dtypes.uint16, dtypes.uint16, - dtypes.int8, dtypes.int8, dtypes.int8, - dtypes.uint8, dtypes.uint8, dtypes.uint8, - dtypes.uint8c, dtypes.uint8c, dtypes.uint8c -]; - -var add = dispatch( fcns, types, null, 3, 2, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var zbuf = new Float64Array( xbuf.length ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var z = ndarray( 'float64', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); - -xbuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -ybuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -zbuf = new Int32Array( xbuf.length ); - -x = ndarray( 'int32', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'int32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -z = ndarray( 'int32', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); diff --git a/examples/sin.js b/examples/sin.js deleted file mode 100644 index 8cd4871..0000000 --- a/examples/sin.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int8Array = require( '@stdlib/array-int8' ); -var sin = require( '@stdlib/math-base-special-sin' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/strided-dtypes' ); -var dispatch = require( './../lib' ); - -function apply( arrays, fcn ) { - var opts; - var xo; - var yo; - var sx; - var sy; - var sh; - var N; - var x; - var y; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - xo = x.order; - yo = y.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - v = fcn( x.get.apply( x, sx ) ); - - opts.order = yo; - sy = ind2sub( sh, i, opts ); - sy.push( v ); - y.set.apply( y, sy ); - } -} - -var fcns = [ - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply -]; - -var types = [ - dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float64, - dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.float64, - dtypes.uint32, dtypes.float64, - dtypes.int16, dtypes.float64, - dtypes.int16, dtypes.float32, - dtypes.uint16, dtypes.float64, - dtypes.uint16, dtypes.float32, - dtypes.int8, dtypes.float64, - dtypes.int8, dtypes.float32, - dtypes.uint8, dtypes.float64, - dtypes.uint8, dtypes.float32, - dtypes.uint8c, dtypes.float64, - dtypes.uint8c, dtypes.float32 -]; - -var data = [ - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin -]; - -var sine = dispatch( fcns, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); - -xbuf = new Int8Array( [ 1, 2, 3, 4, 5 ] ); -ybuf = new Float32Array( xbuf.length ); - -x = ndarray( 'int8', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'float32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); diff --git a/examples/unary.js b/examples/unary.js deleted file mode 100644 index e9c3fb4..0000000 --- a/examples/unary.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -var unary = require( '@stdlib/ndarray-base-unary' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var dispatch = require( './../lib' ); - -var types = [ 'float64', 'float64' ]; - -var data = [ - abs -]; - -var absolute = dispatch( unary, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -absolute( x, y ); -console.log( ybuf ); -// => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index bf753e9..955072f 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..860839f --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@v0.1.0-esm/index.mjs";function m(e,r,t,n,i,a,s,o,u){var d,m,l,f;for(d=a,l=0;l [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( 'invalid invocation. Insufficient arguments.' );\n\t\t\t}\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n"],"names":["indexOfTypes","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","i","j","dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","out","push","resolveEnum","types2enums","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","getDType","slice"],"mappings":";;i+BA6EA,SAASA,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,KAAgBE,EAAGI,GADdE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,CACN,CACD,OAAQ,CACT,CCMA,SAASU,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,oGAAqGZ,IAEnI,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,+EAAgFX,IAE9G,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,sFAAuFV,IAErH,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,6EAA8ET,IAE5G,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,+EAAgFR,IAE9G,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,+EAAgFP,IAG9G,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAO,8IAElB,GAAKb,IAAUG,EACd,MAAM,IAAIU,MAAO,8FAElB,GAAKR,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAO,qJAIlB,GADAT,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAO,gJAGnB,GAAKd,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAO,qGAGlB,OADAf,EA5GD,SAAsBA,GACrB,IAAIkB,EACAtB,EAGJ,IADAsB,EAAM,GACAtB,EAAI,EAAGA,EAAII,EAAMgB,OAAQpB,IAC9BsB,EAAIC,KAAMC,EAAapB,EAAOJ,KAE/B,OAAOsB,CACR,CAmGSG,CAAarB,GAgBrB,WACC,IAAIsB,EACAC,EACAC,EACAC,EACAC,EACAC,EACA/B,EAGJ,IADA4B,EAAOI,UAAUZ,UACHd,EAAQ,CACrB,GAAKsB,EAAOtB,EACX,MAAM,IAAIa,MAAO,+CAElB,MAAM,IAAIA,MAAO,0CACjB,CAGD,IAFAO,EAAS,GACTC,EAAS,GACH3B,EAAI,EAAGA,EAAIM,EAAON,IAAM,CAE7B,IAAMiC,EADNH,EAAIE,UAAWhC,IAEd,MAAKA,EAAIO,EACF,IAAIO,UAAWC,EAAQ,6EAA8Ee,IAErG,IAAIhB,UAAWC,EAAQ,8EAA+Ee,IAG9GJ,EAAOH,KAAMO,GACbH,EAAOJ,KAAMC,EAAaU,EAAUJ,IACpC,CAKD,IAHAD,EAAMzC,EAAcsB,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGkB,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAIb,UAAW,+GAIrBiB,EADIpB,GAGAR,EAAM0B,GAGNxB,EACJ0B,EAAGL,EAAQrB,EAAMwB,IAEjBE,EAAGL,GAEJ,GAAc,IAATlB,EACJ,OAAOkB,EAAQjB,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOkB,EAAOS,MAAO5B,EACrB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 291641d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Create an ndarray function interface which performs multiple dispatch. -* -* @module @stdlib/ndarray-dispatch -* -* @example -* var dispatch = require( '@stdlib/ndarray-dispatch' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/index_of_types.js b/lib/index_of_types.js deleted file mode 100644 index fda2297..0000000 --- a/lib/index_of_types.js +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found). -* -* ## Notes -* -* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types). -* - The function assumes that `x` is stored in row-major order. -* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`. -* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value. -* -* @private -* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension) -* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension) -* @param {ArrayLikeObject} x - input two-dimensional reference array -* @param {integer} strideX1 - `x` stride length along first dimension -* @param {integer} strideX2 - `x` stride length along second dimension -* @param {NonNegativeInteger} offsetX - `x` starting index -* @param {ArrayLikeObject} y - search array -* @param {integer} strideY - `y` stride length -* @param {NonNegativeInteger} offsetY - `y` starting index -* @returns {integer} row index (if found) and `-1` otherwise -* -* @example -* // Define a reference array to search: -* var types = [ -* 'float64', 'float64', 'float64', -* 'float32', 'float32', 'float32', -* 'uint32', 'uint32', 'float64', -* 'int32', 'int32', 'float64', -* 'uint16', 'uint16', 'float64', -* 'int16', 'int16', 'float64', -* 'uint8', 'uint8', 'float64', -* 'int8', 'int8', 'float64' -* ]; -* -* // Define reference array dimensions: -* var N = 8; // rows -* var M = 3; // columns -* -* // Define a search array: -* y1 = [ -* 'float32', 'float32', 'float32', -* ]; -* -* // Find the list of types: -* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 ); -* // returns 1 -* -// Define a search array: -* y2 = [ -* 'float32', 'float32', 'float64', -* ]; -* -* // Find the list of types: -* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 ); -* // returns -1 -*/ -function indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len - var ix; - var iy; - var i; - var j; - - // Search for the first row which matches `y`... - ix = offsetX; - for ( i = 0; i < N; i++ ) { - iy = offsetY; - for ( j = 0; j < M; j++ ) { - if ( x[ ix+(j*strideX2) ] !== y[ iy ] ) { - break; - } - iy += strideY; - } - // If we successfully iterated over all columns, then that means we've found a match... - if ( j === M ) { - return i; - } - ix += strideX1; - } - return -1; -} - - -// EXPORTS // - -module.exports = indexOfTypes; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 5f4bb5d..0000000 --- a/lib/main.js +++ /dev/null @@ -1,231 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isFunctionArray = require( '@stdlib/assert-is-function-array' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/string-format' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var resolveEnum = require( '@stdlib/ndarray-base-dtype-resolve-enum' ); -var indexOfTypes = require( './index_of_types.js' ); - - -// FUNCTIONS // - -/** -* Returns a list of data type enumeration constants. -* -* @private -* @param {Collection} types - list of types -* @returns {IntegerArray} list of data type enumeration constants -*/ -function types2enums( types ) { - var out; - var i; - - out = []; - for ( i = 0; i < types.length; i++ ) { - out.push( resolveEnum( types[ i ] ) ); - } - return out; -} - - -// MAIN // - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param {(FunctionArray|Function)} fcns - list of ndarray functions -* @param {Collection} types - one-dimensional list of ndarray argument data types -* @param {(Collection|null)} data - ndarray function data (e.g., callbacks) -* @param {PositiveInteger} nargs - total number of ndarray function interface arguments -* @param {NonNegativeInteger} nin - number of input ndarrays -* @param {NonNegativeInteger} nout - number of output ndarrays -* @throws {TypeError} first argument must be either a function or an array of functions -* @throws {TypeError} second argument must be an array-like object -* @throws {TypeError} third argument must be an array-like object or `null` -* @throws {Error} third and first arguments must have the same number of elements -* @throws {TypeError} fourth argument must be a positive integer -* @throws {TypeError} fifth argument must be a nonnegative integer -* @throws {TypeError} sixth argument must be a nonnegative integer -* @throws {Error} fourth argument must equal the specified number of input and output arrays -* @throws {Error} number of types must match the number of functions times the total number of array arguments for each function -* @throws {Error} interface must accept at least one input and/or output ndarray -* @returns {Function} ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function dispatch( fcns, types, data, nargs, nin, nout ) { - var narrays; - var nfcns; - var fcn; - - if ( isFunction( fcns ) ) { - fcn = fcns; - } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) ); - } - if ( !isCollection( types ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) ); - } - if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); - } - if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) ); - } - if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) ); - } - if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) ); - } - narrays = nin + nout; - if ( narrays === 0 ) { - throw new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' ); - } - if ( nargs !== narrays ) { - throw new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' ); - } - if ( fcn ) { - nfcns = types.length / narrays; - if ( !isInteger( nfcns ) ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); - } - } else { - nfcns = fcns.length; - if ( types.length !== nfcns*narrays ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); - } - } - if ( data && data.length !== nfcns ) { - throw new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' ); - } - types = types2enums( types ); - return dispatcher; - - /** - * ndarray function interface which performs multiple dispatch. - * - * @private - * @param {ndarrayLike} x - ndarray - * @param {...ndarrayLike} args - ndarray arguments - * @throws {Error} insufficient arguments - * @throws {Error} too many arguments - * @throws {TypeError} input array arguments must be ndarray-like objects - * @throws {TypeError} output array arguments must be ndarray-like objects - * @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types - * @returns {(ndarrayLike|Array|void)} destination array(s) - */ - function dispatcher() { - var arrays; - var dtypes; - var argc; - var idx; - var v; - var f; - var i; - - argc = arguments.length; - if ( argc !== nargs ) { - if ( argc < nargs ) { - throw new Error( 'invalid invocation. Insufficient arguments.' ); - } - throw new Error( 'invalid invocation. Too many arguments.' ); - } - arrays = []; - dtypes = []; - for ( i = 0; i < nargs; i++ ) { - v = arguments[ i ]; - if ( !isndarrayLike( v ) ) { - if ( i < nin ) { - throw new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) ); - } else { - throw new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) ); - } - } - arrays.push( v ); - dtypes.push( resolveEnum( getDType( v ) ) ); - } - // Resolve the ndarray function satisfying the input array types: - idx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len - - // Check whether we were able to successfully resolve an ndarray function: - if ( idx < 0 ) { - throw new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' ); - } - // Retrieve the ndarray function: - if ( fcn ) { - f = fcn; - } else { - f = fcns[ idx ]; - } - // Evaluate the ndarray function: - if ( data ) { - f( arrays, data[ idx ] ); - } else { - f( arrays ); - } - if ( nout === 1 ) { - return arrays[ narrays-1 ]; - } - if ( nout === 0 ) { - return; - } - return arrays.slice( nin ); - } -} - - -// EXPORTS // - -module.exports = dispatch; diff --git a/package.json b/package.json index 5e6762c..06365f4 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Create an ndarray function interface which performs multiple dispatch.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-collection": "^0.1.0", - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/assert-is-function-array": "^0.1.0", - "@stdlib/assert-is-integer": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/assert-is-nonnegative-integer": "^0.1.0", - "@stdlib/assert-is-positive-integer": "^0.1.0", - "@stdlib/ndarray-base-dtype-resolve-enum": "^0.1.0", - "@stdlib/ndarray-dtype": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.1.1", - "@stdlib/array-float64": "^0.1.1", - "@stdlib/array-int32": "^0.1.1", - "@stdlib/array-int8": "^0.1.1", - "@stdlib/array-uint8": "^0.1.1", - "@stdlib/math-base-assert-is-nan": "^0.1.1", - "@stdlib/math-base-special-abs": "^0.1.1", - "@stdlib/math-base-special-pow": "^0.1.0", - "@stdlib/math-base-special-sin": "^0.1.0", - "@stdlib/ndarray-base-buffer-dtype": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-unary": "^0.1.0", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-dtypes": "^0.1.0", - "@stdlib/ndarray-ind2sub": "^0.1.1", - "@stdlib/strided-dtypes": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "ndarray", @@ -99,7 +26,6 @@ "multimethod", "multimethods" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..3385629 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/fixtures/binary.js b/test/fixtures/binary.js deleted file mode 100644 index a60dfa2..0000000 --- a/test/fixtures/binary.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Binary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @returns {number} sum -*/ -function binary( x, y ) { - return x + y; -} - - -// EXPORTS // - -module.exports = binary; diff --git a/test/fixtures/fill.js b/test/fixtures/fill.js deleted file mode 100644 index 41b2958..0000000 --- a/test/fixtures/fill.js +++ /dev/null @@ -1,76 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which fills one or more ndarrays. -* -* @private -* @param {*} value - fill value -* @returns {Function} ndarray function -*/ -function fill( value ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - */ - function ndarrayFcn( arrays ) { - var opts; - var sub; - var arr; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - opts = { - 'order': '' - }; - for ( j = 0; j < M; j++ ) { - arr = arrays[ j ]; - opts.order = arrays[ j ].order; - for ( i = 0; i < N; i++ ) { - sub = ind2sub( sh, i, opts ); - sub.push( value ); - arr.set.apply( arr, sub ); - } - } - } -} - - -// EXPORTS // - -module.exports = fill; diff --git a/test/fixtures/foreach.js b/test/fixtures/foreach.js deleted file mode 100644 index a426290..0000000 --- a/test/fixtures/foreach.js +++ /dev/null @@ -1,72 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function forEach( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - fcn.apply( null, args ); - } -} - - -// EXPORTS // - -module.exports = forEach; diff --git a/test/fixtures/map1n.js b/test/fixtures/map1n.js deleted file mode 100644 index 614196b..0000000 --- a/test/fixtures/map1n.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function which maps the return value of a callback to `N` arrays. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function map1N( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var v; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - v = fcn(); - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - sub.push( v ); - arrays[ j ].set.apply( arrays[ j ], sub ); - } - } -} - - -// EXPORTS // - -module.exports = map1N; diff --git a/test/fixtures/nullary.js b/test/fixtures/nullary.js deleted file mode 100644 index 4f22126..0000000 --- a/test/fixtures/nullary.js +++ /dev/null @@ -1,36 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Nullary callback. -* -* @private -* @returns {number} value -*/ -function nullary() { - return 3.0; -} - - -// EXPORTS // - -module.exports = nullary; diff --git a/test/fixtures/quaternary.js b/test/fixtures/quaternary.js deleted file mode 100644 index 548437b..0000000 --- a/test/fixtures/quaternary.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quaternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @returns {number} sum -*/ -function quaternary( x, y, z, w ) { - return x + y + z + w; -} - - -// EXPORTS // - -module.exports = quaternary; diff --git a/test/fixtures/quinary.js b/test/fixtures/quinary.js deleted file mode 100644 index 36068de..0000000 --- a/test/fixtures/quinary.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quinary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @param {number} u - input value -* @returns {number} sum -*/ -function quinary( x, y, z, w, u ) { - return x + y + z + w + u; -} - - -// EXPORTS // - -module.exports = quinary; diff --git a/test/fixtures/sum.js b/test/fixtures/sum.js deleted file mode 100644 index efdbb1b..0000000 --- a/test/fixtures/sum.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which computes the sum across one or more ndarrays. -* -* @private -* @param {Object} ctx - context -* @param {number} ctx.sum - initial sum -* @returns {Function} ndarray function -*/ -function wrapper( ctx ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - * @param {Function} [fcn] - callback - */ - function ndarrayFcn( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var f; - var i; - var j; - - if ( arguments.length > 1 ) { - f = fcn; - } - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - if ( f ) { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - ctx.sum += f.apply( null, args ); - } - } else { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - ctx.sum += arrays[ j ].get.apply( arrays[ j ], sub ); - } - } - } - } -} - - -// EXPORTS // - -module.exports = wrapper; diff --git a/test/fixtures/ternary.js b/test/fixtures/ternary.js deleted file mode 100644 index 0595d5f..0000000 --- a/test/fixtures/ternary.js +++ /dev/null @@ -1,39 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Ternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @returns {number} sum -*/ -function ternary( x, y, z ) { - return x + y + z; -} - - -// EXPORTS // - -module.exports = ternary; diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d6c2c8e..0000000 --- a/test/test.js +++ /dev/null @@ -1,363 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var fill = require( './fixtures/fill.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either a function or an array of functions as a first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( value, types, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object as a second argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided either an array-like object or `null` as a third argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - dispatch( unary, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a positive integer for a fourth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 0, - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a fifth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, value, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a sixth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, 1, value ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function array)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var fcns = [ unary, unary, unary ]; - var data = [ abs, abs, abs ]; - dispatch( fcns, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function argument)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs, abs, abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the length of `data` argument does not match the number of ndarray functions', function test( t ) { - var values; - var i; - - values = [ - [], - [ abs, abs ], - [ abs, abs, abs ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var fcns = [ unary ]; - dispatch( fcns, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the fourth argument is incompatible with the number of input and output ndarrays', function test( t ) { - var values; - var i; - - values = [ - 0, - 1, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of specified input and output ndarrays is zero', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var types = [ 'float64' ]; - dispatch( fill( 3 ), types, null, 1, 0, 0 ); - } -}); - -tape( 'the function returns an ndarray function interface', function test( t ) { - var types; - var data; - var f; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - f = dispatch( unary, types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ unary ], types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( fill( 3 ), types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ fill( 3 ) ], types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.two_arrays.js b/test/test.two_arrays.js deleted file mode 100644 index 16eb61b..0000000 --- a/test/test.two_arrays.js +++ /dev/null @@ -1,814 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var dtype = require( '@stdlib/ndarray-base-buffer-dtype' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var forEach = require( './fixtures/foreach.js' ); -var map1N = require( './fixtures/map1n.js' ); -var fill = require( './fixtures/fill.js' ); -var sum = require( './fixtures/sum.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the first argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var ybuf = new Float64Array( 10 ); - var y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( value, y ); - }; - } -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the second argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var xbuf = new Float64Array( 10 ); - var x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( x, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided insufficient arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var f; - var x; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [], - [ x ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided too many arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var ybuf; - var f; - var x; - var y; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [ x, y, y ], - [ x, y, y, y ], - [ x, y, y, y, y ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if unable to resolve a ndarray function supporting the provided array argument data types', function test( t ) { - var values; - var types; - var data; - var xbuf; - var fcn; - var x; - var i; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ abs, abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 4 ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - values = [ - new Uint8Array( 4 ), - new Int32Array( 4 ), - [ 0, 0, 0, 0 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided an array having data type: ' + dtype( values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var y = ndarray( dtype( value ), value, [ value.length ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - }; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only input arrays)', function test( t ) { - var types; - var xbuf; - var ybuf; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only output arrays)', function test( t ) { - var expected; - var types; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only input arrays)', function test( t ) { - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var ctx; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcns = [ - sum( ctx ), - sum( ctx ) - ]; - fcn = dispatch( fcns, types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only output arrays)', function test( t ) { - var expected; - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcns = [ - fill( 3.0 ), - fill( 4.0 ) - ]; - fcn = dispatch( fcns, types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - - fcn = dispatch( forEach, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - - fcn = dispatch( map1N, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - fcns = [ - forEach, - forEach - ]; - fcn = dispatch( fcns, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - fcns = [ - map1N, - map1N - ]; - fcn = dispatch( fcns, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - fcns = [ - unary, - unary - ]; - fcn = dispatch( fcns, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which returns one or more output arrays, if one or more output arrays is specified, and otherwise returns `undefined`', function test( t ) { - var types; - var data; - var xbuf; - var ybuf; - var out; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - // No output arrays... - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, void 0, 'returns expected value' ); - - // One output array... - data = [ - abs, - abs - ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - fcn = dispatch( fill( 3.0 ), types, null, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - // Two output arrays... - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.end(); -}); From 74b3bfae7a2f73961e30b3c72673499e5727f5cd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 08:28:19 +0000 Subject: [PATCH 050/109] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9fbece1..5e6762c 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/assert-is-positive-integer": "^0.1.0", "@stdlib/ndarray-base-dtype-resolve-enum": "^0.1.0", "@stdlib/ndarray-dtype": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0" }, "devDependencies": { From 1340d8d152fa580b1a9f44fa87682747db25bb1a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 15:07:27 +0000 Subject: [PATCH 051/109] Remove files --- index.d.ts | 334 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6516 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 955072f..0000000 --- a/index.d.ts +++ /dev/null @@ -1,334 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* ndarray function. -* -* @param arrays - array containing input and output ndarrays -* @param data - ndarray function data (e.g., a callback) -* -* @example -* var numel = require( `@stdlib/ndarray/base/numel` ); -* var ind2sub = require( `@stdlib/ndarray/ind2sub` ); -* -* function ndarrayFcn( arrays, fcn ) { -* var xord; -* var yord; -* var opts; -* var sub; -* var sh; -* var N; -* var x; -* var y; -* var v; -* var i; -* -* x = arrays[ 0 ]; -* y = arrays[ 1 ]; -* sh = x.shape; -* N = numel( sh ); -* if ( N <= 0 ) { -* return; -* } -* xord = x.order; -* yord = y.order; -* opts = {}; -* opts.order = xord; -* for ( i = 0; i < N; i++ ) { -* // Convert a linear index to subscripts: -* opts.order = xord; -* sub = ind2sub( sh, i, opts ); -* -* // Retrieve an element from `x`: -* v = x.get.apply( x, sub ); -* -* // Convert a linear index to subscripts: -* opts.order = yord; -* sub = ind2sub( sh, i, opts ); -* -* // Append the result of applying the callback: -* sub.push( fcn( v ) ); -* -* // Assign the result to an element in `y`: -* y.set.apply( y, sub ); -* } -* } -*/ -type ndarrayFcn = ( arrays: Array, data?: any ) => void; - -/** -* Interface describing an ndarray function dispatcher. -*/ -interface Dispatcher { - /** - * Invokes an ndarray function based on the provided array data type(s). - * - * @param x - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array - * - * @example - * var nullary = require( `@stdlib/ndarray/base/nullary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function value() { - * return 3.14; - * } - * - * var types = [ 'float64' ]; - * var data = [ value ]; - * - * var fcn = dispatch( nullary, types, data, 1, 0, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( 5 ); - * var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x ); - * // xbuf => [ 3.14, 3.14, 3.14, 3.14, 3.14 ] - */ - ( x: ndarray ): ndarray | void; - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var unary = require( `@stdlib/ndarray/base/unary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * var abs = require( `@stdlib/math/base/special/abs` ); - * - * var types = [ 'float64', 'float64' ]; - * var data = [ abs ]; - * - * var fcn = dispatch( unary, types, data, 2, 1, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - * var ybuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y ); - * // ybuf => [ 1.0, 2.0, 3.0 ] - */ - ( x: ndarray, y: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var ternary = require( `@stdlib/ndarray/base/ternary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add2( x, y ) { - * return x + y; - * } - * - * var types = [ 'float64', 'float64', 'float64' ]; - * var data = [ add2 ]; - * - * var fcn = dispatch( ternary, types, data, 3, 2, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z ); - * // zbuf => [ 2.0, 4.0, 6.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quaternary = require( `@stdlib/ndarray/base/quaternary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add3( x, y, z ) { - * return x + y + z; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add3 ]; - * - * var fcn = dispatch( quaternary, types, data, 4, 3, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w ); - * // wbuf => [ 3.0, 6.0, 9.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @param args - ndarray arguments - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quinary = require( `@stdlib/ndarray/base/quinary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add4( x, y, z, w ) { - * return x + y + z + w; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add4 ]; - * - * var fcn = dispatch( quinary, types, data, 5, 4, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ubuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var u = ndarray( 'float64', ubuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w, u ); - * // ubuf => [ 4.0, 8.0, 12.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray, ...args: Array ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures -} - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param fcns - list of ndarray functions -* @param types - one-dimensional list of ndarray argument data types -* @param data - ndarray function data (e.g., callbacks) -* @param nargs - total number of ndarray function interface arguments -* @param nin - number of input ndarrays -* @param nout - number of output ndarrays -* @throws first argument must be either a function or an array of functions -* @throws second argument must be an array-like object -* @throws third argument must be an array-like object or `null` -* @throws third and first arguments must have the same number of elements -* @throws fourth argument must be a positive integer -* @throws fifth argument must be a nonnegative integer -* @throws sixth argument must be a nonnegative integer -* @throws fourth argument must equal the specified number of input and output arrays -* @throws number of types must match the number of functions times the total number of array arguments for each function -* @throws interface must accept at least one input and/or output ndarray -* @returns ndarray function interface -* -* @example -* var unary = require( `@stdlib/ndarray/base/unary` ); -* var abs = require( `@stdlib/math/base/special/abs` ); -* var Float64Array = require( `@stdlib/array/float64` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var fcn = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* fcn( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function dispatch( fcns: ndarrayFcn | ArrayLike, types: ArrayLike, data: ArrayLike | null, nargs: number, nin: number, nout: number ): Dispatcher; - - -// EXPORTS // - -export = dispatch; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 860839f..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@v0.1.0-esm/index.mjs";function m(e,r,t,n,i,a,s,o,u){var d,m,l,f;for(d=a,l=0;l [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( 'invalid invocation. Insufficient arguments.' );\n\t\t\t}\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n"],"names":["indexOfTypes","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","i","j","dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","out","push","resolveEnum","types2enums","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","getDType","slice"],"mappings":";;i+BA6EA,SAASA,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,KAAgBE,EAAGI,GADdE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,CACN,CACD,OAAQ,CACT,CCMA,SAASU,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,oGAAqGZ,IAEnI,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,+EAAgFX,IAE9G,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,sFAAuFV,IAErH,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,6EAA8ET,IAE5G,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,+EAAgFR,IAE9G,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,+EAAgFP,IAG9G,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAO,8IAElB,GAAKb,IAAUG,EACd,MAAM,IAAIU,MAAO,8FAElB,GAAKR,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAO,qJAIlB,GADAT,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAO,gJAGnB,GAAKd,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAO,qGAGlB,OADAf,EA5GD,SAAsBA,GACrB,IAAIkB,EACAtB,EAGJ,IADAsB,EAAM,GACAtB,EAAI,EAAGA,EAAII,EAAMgB,OAAQpB,IAC9BsB,EAAIC,KAAMC,EAAapB,EAAOJ,KAE/B,OAAOsB,CACR,CAmGSG,CAAarB,GAgBrB,WACC,IAAIsB,EACAC,EACAC,EACAC,EACAC,EACAC,EACA/B,EAGJ,IADA4B,EAAOI,UAAUZ,UACHd,EAAQ,CACrB,GAAKsB,EAAOtB,EACX,MAAM,IAAIa,MAAO,+CAElB,MAAM,IAAIA,MAAO,0CACjB,CAGD,IAFAO,EAAS,GACTC,EAAS,GACH3B,EAAI,EAAGA,EAAIM,EAAON,IAAM,CAE7B,IAAMiC,EADNH,EAAIE,UAAWhC,IAEd,MAAKA,EAAIO,EACF,IAAIO,UAAWC,EAAQ,6EAA8Ee,IAErG,IAAIhB,UAAWC,EAAQ,8EAA+Ee,IAG9GJ,EAAOH,KAAMO,GACbH,EAAOJ,KAAMC,EAAaU,EAAUJ,IACpC,CAKD,IAHAD,EAAMzC,EAAcsB,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGkB,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAIb,UAAW,+GAIrBiB,EADIpB,GAGAR,EAAM0B,GAGNxB,EACJ0B,EAAGL,EAAQrB,EAAMwB,IAEjBE,EAAGL,GAEJ,GAAc,IAATlB,EACJ,OAAOkB,EAAQjB,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOkB,EAAOS,MAAO5B,EACrB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 3385629..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 4dee952174125a69a79ee472c681831b6df6e4b4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 15:07:59 +0000 Subject: [PATCH 052/109] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 59 +- SECURITY.md | 5 - benchmark/benchmark.dispatch_size.js | 156 - benchmark/benchmark.js | 81 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 87 - docs/types/test.ts | 641 --- examples/add.js | 121 - examples/sin.js | 142 - examples/unary.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/index_of_types.js | 106 - lib/main.js | 231 - package.json | 78 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/binary.js | 38 - test/fixtures/fill.js | 76 - test/fixtures/foreach.js | 72 - test/fixtures/map1n.js | 74 - test/fixtures/nullary.js | 36 - test/fixtures/quaternary.js | 40 - test/fixtures/quinary.js | 41 - test/fixtures/sum.js | 98 - test/fixtures/ternary.js | 39 - test/test.js | 363 -- test/test.two_arrays.js | 814 --- 57 files changed, 6211 insertions(+), 6743 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.dispatch_size.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/add.js delete mode 100644 examples/sin.js delete mode 100644 examples/unary.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/index_of_types.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/fixtures/binary.js delete mode 100644 test/fixtures/fill.js delete mode 100644 test/fixtures/foreach.js delete mode 100644 test/fixtures/map1n.js delete mode 100644 test/fixtures/nullary.js delete mode 100644 test/fixtures/quaternary.js delete mode 100644 test/fixtures/quinary.js delete mode 100644 test/fixtures/sum.js delete mode 100644 test/fixtures/ternary.js delete mode 100644 test/test.js delete mode 100644 test/test.two_arrays.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 5d2de00..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-01-01T05:27:55.341Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ac0b7cd..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 30656c4..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 5e92c3e..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c92f5c4..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index d53fd56..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '43 7 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index e1e3539..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -302,7 +295,7 @@ console.log( ybuf ); ## 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. +This package is part of [stdlib][stdlib], a standard library 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]. @@ -362,11 +355,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-dispatch/main/LICENSE -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.dispatch_size.js b/benchmark/benchmark.dispatch_size.js deleted file mode 100644 index 15805ba..0000000 --- a/benchmark/benchmark.dispatch_size.js +++ /dev/null @@ -1,156 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib/main.js' ); - - -// FUNCTIONS // - -/** -* Evaluates the identity function. -* -* @private -* @param {*} v - value -* @returns {*} input value -*/ -function identity( v ) { - return v; -} - -/** -* Dummy function which throws an error. -* -* @private -* @throws {Error} unexpected error -*/ -function throwError() { - throw new Error( 'unexpected error' ); -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} size - dispatch size -* @returns {Function} benchmark function -*/ -function createBenchmark( size ) { - var types; - var data; - var fcn; - var x; - var y; - var t; - var i; - - types = []; - - // Create dummy types... - for ( i = 0; i < (size-1)*2; i += 2 ) { - t = 'foo' + i; - types.push( t ); - types.push( t ); - } - // Append test types: - types.push( 'float64' ); - types.push( 'float64' ); - - // Define a list of callbacks: - data = []; - for ( i = 0; i < size-1; i++ ) { - data.push( throwError ); - } - // Append a test callback: - data.push( identity ); - - // Create the dispatcher: - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - // Create sample arrays: - x = new Float64Array( 1 ); - y = new Float64Array( x.length ); - - x = ndarray( 'float64', x, [ 1 ], [ 1 ], 0, 'row-major' ); - y = ndarray( 'float64', y, [ 1 ], [ 1 ], 0, 'row-major' ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var z; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x.data[ 0 ] = i; - z = fcn( x, y ); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var size; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - size = pow( 2, i ); - f = createBenchmark( size ); - bench( pkg+':size='+size, f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 3c6f450..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::fcns_array', function benchmark( b ) { - var types; - var fcns; - var data; - var out; - var i; - - fcns = [ unary ]; - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( fcns, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::fcn_arg', function benchmark( b ) { - var types; - var data; - var out; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( unary, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 6c1b20d..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch" -%% click B href "https://github.com/stdlib-js/ndarray-dispatch/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-dispatch/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-dispatch/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-dispatch/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-dispatch/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch -[production-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 1295a44..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import dispatch from '../docs/types/index'; -export = dispatch; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7fb29cb..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var y=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var b=y(function(D,w){ -function k(i,r,e,u,f,m,n,o,l){var h,t,s,a;for(h=m,s=0;s [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( 'invalid invocation. Insufficient arguments.' );\n\t\t\t}\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = dispatch;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an ndarray function interface which performs multiple dispatch.\n*\n* @module @stdlib/ndarray-dispatch\n*\n* @example\n* var dispatch = require( '@stdlib/ndarray-dispatch' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var unary = require( '@stdlib/ndarray-base-unary' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var types = [\n* 'float64', 'float64'\n* ];\n*\n* var data = [\n* abs\n* ];\n*\n* var absolute = dispatch( unary, types, data, 2, 1, 1 );\n*\n* // ...\n*\n* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] );\n* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] );\n*\n* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' );\n* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' );\n*\n* absolute( x, y );\n* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA6EA,SAASC,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,EAAU,CAClF,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,CAAU,IAAME,EAAGI,CAAG,EADjBE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,CACP,CACA,MAAO,EACR,CAKAL,EAAO,QAAUC,ICzGjB,IAAAc,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAoB,QAAS,oCAAqC,EAClEC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAkB,QAAS,kCAAmC,EAC9DC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAc,QAAS,yCAA0C,EACjEC,EAAe,IAYnB,SAASC,EAAaC,EAAQ,CAC7B,IAAIC,EACAC,EAGJ,IADAD,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIF,EAAM,OAAQE,IAC9BD,EAAI,KAAMJ,EAAaG,EAAOE,CAAE,CAAE,CAAE,EAErC,OAAOD,CACR,CAqDA,SAASE,EAAUC,EAAMJ,EAAOK,EAAMC,EAAOC,EAAKC,EAAO,CACxD,IAAIC,EACAC,EACAC,EAEJ,GAAKnB,EAAYY,CAAK,EACrBO,EAAMP,UACK,CAACb,EAAiBa,CAAK,EAClC,MAAM,IAAI,UAAWT,EAAQ,oGAAqGS,CAAK,CAAE,EAE1I,GAAK,CAACX,EAAcO,CAAM,EACzB,MAAM,IAAI,UAAWL,EAAQ,+EAAgFK,CAAM,CAAE,EAEtH,GAAK,CAACP,EAAcY,CAAK,GAAKA,IAAS,KACtC,MAAM,IAAI,UAAWV,EAAQ,sFAAuFU,CAAK,CAAE,EAE5H,GAAK,CAAChB,EAAmBiB,CAAM,EAC9B,MAAM,IAAI,UAAWX,EAAQ,6EAA8EW,CAAM,CAAE,EAEpH,GAAK,CAAClB,EAAsBmB,CAAI,EAC/B,MAAM,IAAI,UAAWZ,EAAQ,+EAAgFY,CAAI,CAAE,EAEpH,GAAK,CAACnB,EAAsBoB,CAAK,EAChC,MAAM,IAAI,UAAWb,EAAQ,+EAAgFa,CAAK,CAAE,EAGrH,GADAC,EAAUF,EAAMC,EACXC,IAAY,EAChB,MAAM,IAAI,MAAO,4IAA6I,EAE/J,GAAKH,IAAUG,EACd,MAAM,IAAI,MAAO,4FAA6F,EAE/G,GAAKE,GAEJ,GADAD,EAAQV,EAAM,OAASS,EAClB,CAACnB,EAAWoB,CAAM,EACtB,MAAM,IAAI,MAAO,8IAA+I,UAGjKA,EAAQN,EAAK,OACRJ,EAAM,SAAWU,EAAMD,EAC3B,MAAM,IAAI,MAAO,8IAA+I,EAGlK,GAAKJ,GAAQA,EAAK,SAAWK,EAC5B,MAAM,IAAI,MAAO,mGAAoG,EAEtH,OAAAV,EAAQD,EAAaC,CAAM,EACpBY,EAeP,SAASA,GAAa,CACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EAGJ,GADAa,EAAO,UAAU,OACZA,IAAST,EACb,MAAKS,EAAOT,EACL,IAAI,MAAO,6CAA8C,EAE1D,IAAI,MAAO,yCAA0C,EAI5D,IAFAO,EAAS,CAAC,EACVC,EAAS,CAAC,EACJZ,EAAI,EAAGA,EAAII,EAAOJ,IAAM,CAE7B,GADAe,EAAI,UAAWf,CAAE,EACZ,CAACR,EAAeuB,CAAE,EACtB,MAAKf,EAAIK,EACF,IAAI,UAAWZ,EAAQ,6EAA8EsB,CAAE,CAAE,EAEzG,IAAI,UAAWtB,EAAQ,8EAA+EsB,CAAE,CAAE,EAGlHJ,EAAO,KAAMI,CAAE,EACfH,EAAO,KAAMjB,EAAaD,EAAUqB,CAAE,CAAE,CAAE,CAC3C,CAKA,GAHAD,EAAMlB,EAAcY,EAAOD,EAAST,EAAOS,EAAS,EAAG,EAAGK,EAAQ,EAAG,CAAE,EAGlEE,EAAM,EACV,MAAM,IAAI,UAAW,6GAA8G,EAcpI,GAXKL,EACJO,EAAIP,EAEJO,EAAId,EAAMY,CAAI,EAGVX,EACJa,EAAGL,EAAQR,EAAMW,CAAI,CAAE,EAEvBE,EAAGL,CAAO,EAENL,IAAS,EACb,OAAOK,EAAQJ,EAAQ,CAAE,EAE1B,GAAKD,IAAS,EAGd,OAAOK,EAAO,MAAON,CAAI,CAC1B,CACD,CAKApB,EAAO,QAAUgB,IC9KjB,IAAIgB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_index_of_types", "__commonJSMin", "exports", "module", "indexOfTypes", "N", "M", "x", "strideX1", "strideX2", "offsetX", "y", "strideY", "offsetY", "ix", "iy", "i", "j", "require_main", "__commonJSMin", "exports", "module", "isNonNegativeInteger", "isPositiveInteger", "isInteger", "isFunctionArray", "isFunction", "isCollection", "isndarrayLike", "format", "getDType", "resolveEnum", "indexOfTypes", "types2enums", "types", "out", "i", "dispatch", "fcns", "data", "nargs", "nin", "nout", "narrays", "nfcns", "fcn", "dispatcher", "arrays", "dtypes", "argc", "idx", "v", "f", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 02fe150..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,87 +0,0 @@ - -{{alias}}( fcns, types, data, nargs, nin, nout ) - Returns an ndarray function interface which performs multiple dispatch. - - An ndarray function interface has the following signature: - - f( x, y, ... ) - - where - - - x: ndarray. - - y: ndarray. - - ...: additional ndarrays. - - The number of parameters is derived from `nargs`, the number of input - ndarrays is derived from `nin`, and the number of output ndarrays is derived - from `nout`. - - Parameters - ---------- - fcns: Function|ArrayLikeObject - List of ndarray functions. An ndarray function should have the following - signature: - - f( arrays, data ) - - where - - - arrays: array containing input and output ndarrays. - - data: ndarray function data (e.g., a callback). - - For convenience, a single ndarray function may be provided which will be - invoked whenever the ndarray argument data types match a sequence of - types in `types`. Providing a single ndarray function is particularly - convenient for the case where, regardless of array data types, - traversing arrays remains the same, but the ndarray function `data` - differs (e.g., callbacks which differ based on the array data types). - - types: ArrayLikeObject - One-dimensional list of ndarray argument data types. - - data: ArrayLikeObject|null - ndarray function data (e.g., callbacks). If `null`, a returned ndarray - function interface does **not** provide a `data` argument to an invoked - ndarray function. - - nargs: integer - Total number of ndarray function interface arguments. - - nin: integer - Number of input ndarrays. - - nout: integer - Number of output ndarrays. - - Returns - ------- - fcn: Function - ndarray function interface. - - Examples - -------- - // Define ndarray argument data types: - > var t = [ 'float64', 'float64', 'float32', 'float32' ]; - - // Define a list of ndarray function data (callbacks): - > var d = [ {{alias:@stdlib/math/base/special/abs}}, {{alias:@stdlib/math/base/special/absf}} ]; - - // Create an ndarray function interface for applying unary callbacks: - > var f = {{alias}}( {{alias:@stdlib/ndarray/base/unary}}, t, d, 2, 1, 1 ); - - // Create an input ndarray: - > var xbuf = new {{alias:@stdlib/array/float64}}( [ -1.0, -2.0, -3.0, -4.0 ] ); - > var x = {{alias:@stdlib/ndarray/ctor}}( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Create an output ndarray: - > var ybuf = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 0.0, 0.0 ] ); - > var y = {{alias:@stdlib/ndarray/ctor}}( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Compute the element-wise absolute value: - > f( x, y ); - > ybuf - [ 1.0, 2.0, 3.0, 4.0 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 3cba031..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,641 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable max-lines */ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import dispatch = require( './index' ); - - -// FUNCTIONS // - -/** -* Nullary callback. -* -* @return input value -*/ -function nullary(): any { - return 5.0; -} - -/** -* Unary callback. -* -* @param x - input value -* @return input value -*/ -function unary( x: any ): any { - return x; -} - -/** -* Binary callback. -* -* @param x - input value -* @param y - input value -* @return output value -*/ -function binary( x: number, y: number ): number { - return x + y; -} - -/** -* Ternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @return output value -*/ -function ternary( x: number, y: number, z: number ): number { - return x + y + z; -} - -/** -* Quaternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @param w - input value -* @return output value -*/ -function quaternary( x: number, y: number, z: number, w: number ): number { - return x + y + z + w; -} - -/** -* Mock `ind2sub` function. -* -* @param shape - dimensions -* @param idx - linear index -* @param opts - options -* @return subscripts -*/ -function ind2sub( shape: ArrayLike, idx: number, opts?: any ): Array { - let out; - let i; - - out = []; - if ( typeof opts === 'object' && opts !== null && opts.order === 'row-major' ) { no-unsafe-any - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } else { - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } - return out; -} - -/** -* Mock ndarray function. -* -* @param arrays - ndarrays -* @param fcn - callback -*/ -function ndarrayFcn( arrays: Array, fcn: ( x: any ) => any ): void { - let xord; - let yord; - let opts; - let sub; - let sh; - let N; - let x; - let y; - let v; - let i; - - x = arrays[ 0 ]; - y = arrays[ 1 ]; - sh = x.shape; - if ( sh.length === 0 ) { - return; - } - N = 1; - for ( i = 0; i < sh.length; i += 1 ) { - N *= sh[ i ]; - } - xord = x.order; - yord = y.order; - opts = { - 'order': '' - }; - opts.order = xord; - for ( i = 0; i < N; i += 1 ) { - // Convert a linear index to subscripts: - opts.order = xord; - sub = ind2sub( sh, i, opts ); - - // Retrieve an element from `x`: - v = x.get.apply( x, sub ); - - // Convert a linear index to subscripts: - opts.order = yord; - sub = ind2sub( sh, i, opts ); - - // Append the result of applying the callback: - sub[ sub.length ] = fcn( v ) as number; - - // Assign the result to an element in `y`: - y.set.apply( y, sub ); - } -} - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a dispatch function... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, 1 ); // $ExpectType Dispatcher - dispatch( [ ndarrayFcn ], types, data, 2, 1, 1 ); // $ExpectType Dispatcher -} - -// The compiler throws an error if the function is provided a first argument which is not either an ndarray function or an array-like object containing ndarray functions... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( '10', types, data, 2, 1, 1 ); // $ExpectError - dispatch( 10, types, data, 2, 1, 1 ); // $ExpectError - dispatch( true, types, data, 2, 1, 1 ); // $ExpectError - dispatch( false, types, data, 2, 1, 1 ); // $ExpectError - dispatch( null, types, data, 2, 1, 1 ); // $ExpectError - dispatch( undefined, types, data, 2, 1, 1 ); // $ExpectError - dispatch( [ '1' ], types, data, 2, 1, 1 ); // $ExpectError - dispatch( {}, types, data, 2, 1, 1 ); // $ExpectError - dispatch( ( x: number ): number => x, types, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object... -{ - const data = [ unary ]; - - dispatch( ndarrayFcn, 10, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, true, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, false, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, null, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, undefined, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, {}, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object or null... -{ - const types = [ 'float64', 'float64' ]; - - dispatch( ndarrayFcn, types, 10, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, true, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, false, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, undefined, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, {}, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, '10', 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, true, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, false, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, null, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, undefined, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, [ '1' ], 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, {}, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, ( x: number ): number => x, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, '10', 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, true, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, false, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, null, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, undefined, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, [ '1' ], 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, {}, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, ( x: number ): number => x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, '10' ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, true ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, false ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, null ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, undefined ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, [ '1' ] ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, {} ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch(); // $ExpectError - dispatch( ndarrayFcn ); // $ExpectError - dispatch( ndarrayFcn, types ); // $ExpectError - dispatch( ndarrayFcn, types, data ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, 1, 0 ); // $ExpectError -} - -// The function returns a dispatch function... -{ - const x = array(); - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const t1 = [ 'float64' ]; - const d1 = [ nullary ]; - const f1 = dispatch( ndarrayFcn, t1, d1, 1, 1, 0 ); - f1( x ); // $ExpectType void | ndarray - - const t2 = [ 'float64', 'float64' ]; - const d2 = [ unary ]; - const f2 = dispatch( ndarrayFcn, t2, d2, 2, 1, 1 ); - f2( x, y ); // $ExpectType void | ndarray - - const t3 = [ 'float64', 'float64', 'float64' ]; - const d3 = [ binary ]; - const f3 = dispatch( ndarrayFcn, t3, d3, 3, 2, 1 ); - f3( x, y, z ); // $ExpectType void | ndarray - - const t4 = [ 'float64', 'float64', 'float64', 'float64' ]; - const d4 = [ ternary ]; - const f4 = dispatch( ndarrayFcn, t4, d4, 4, 3, 1 ); - f4( x, y, z, w ); // $ExpectType void | ndarray - - const t5 = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const d5 = [ quaternary ]; - const f5 = dispatch( ndarrayFcn, t5, d5, 5, 4, 1 ); - f5( x, y, z, w, u ); // $ExpectType void | ndarray -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (1 ndarray)... -{ - const types = [ 'float64' ]; - const data = [ nullary ]; - - const f = dispatch( ndarrayFcn, types, data, 1, 0, 1 ); - f( '10' ); // $ExpectError - f( 10 ); // $ExpectError - f( true ); // $ExpectError - f( false ); // $ExpectError - f( null ); // $ExpectError - f( undefined ); // $ExpectError - f( [ '1' ] ); // $ExpectError - f( {} ); // $ExpectError - f( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( 10, y ); // $ExpectError - f( '10', y ); // $ExpectError - f( true, y ); // $ExpectError - f( false, y ); // $ExpectError - f( null, y ); // $ExpectError - f( undefined, y ); // $ExpectError - f( [ '1' ], y ); // $ExpectError - f( {}, y ); // $ExpectError - f( ( x: number ): number => x, y ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const x = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( x, 10 ); // $ExpectError - f( x, '10' ); // $ExpectError - f( x, true ); // $ExpectError - f( x, false ); // $ExpectError - f( x, null ); // $ExpectError - f( x, undefined ); // $ExpectError - f( x, [ '1' ] ); // $ExpectError - f( x, {} ); // $ExpectError - f( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( 10, y, z ); // $ExpectError - f( '10', y, z ); // $ExpectError - f( true, y, z ); // $ExpectError - f( false, y, z ); // $ExpectError - f( null, y, z ); // $ExpectError - f( undefined, y, z ); // $ExpectError - f( [ '1' ], y, z ); // $ExpectError - f( {}, y, z ); // $ExpectError - f( ( x: number ): number => x, y, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, 10, z ); // $ExpectError - f( x, '10', z ); // $ExpectError - f( x, true, z ); // $ExpectError - f( x, false, z ); // $ExpectError - f( x, null, z ); // $ExpectError - f( x, undefined, z ); // $ExpectError - f( x, [ '1' ], z ); // $ExpectError - f( x, {}, z ); // $ExpectError - f( x, ( x: number ): number => x, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, y, '10' ); // $ExpectError - f( x, y, true ); // $ExpectError - f( x, y, false ); // $ExpectError - f( x, y, null ); // $ExpectError - f( x, y, undefined ); // $ExpectError - f( x, y, [ '1' ] ); // $ExpectError - f( x, y, {} ); // $ExpectError - f( x, y, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( 10, y, z, w ); // $ExpectError - f( '10', y, z, w ); // $ExpectError - f( true, y, z, w ); // $ExpectError - f( false, y, z, w ); // $ExpectError - f( null, y, z, w ); // $ExpectError - f( undefined, y, z, w ); // $ExpectError - f( [ '1' ], y, z, w ); // $ExpectError - f( {}, y, z, w ); // $ExpectError - f( ( x: number ): number => x, y, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, 10, z, w ); // $ExpectError - f( x, '10', z, w ); // $ExpectError - f( x, true, z, w ); // $ExpectError - f( x, false, z, w ); // $ExpectError - f( x, null, z, w ); // $ExpectError - f( x, undefined, z, w ); // $ExpectError - f( x, [ '1' ], z, w ); // $ExpectError - f( x, {}, z, w ); // $ExpectError - f( x, ( x: number ): number => x, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, 10, w ); // $ExpectError - f( x, y, '10', w ); // $ExpectError - f( x, y, true, w ); // $ExpectError - f( x, y, false, w ); // $ExpectError - f( x, y, null, w ); // $ExpectError - f( x, y, undefined, w ); // $ExpectError - f( x, y, [ '1' ], w ); // $ExpectError - f( x, y, {}, w ); // $ExpectError - f( x, y, ( x: number ): number => x, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, z, 10 ); // $ExpectError - f( x, y, z, '10' ); // $ExpectError - f( x, y, z, true ); // $ExpectError - f( x, y, z, false ); // $ExpectError - f( x, y, z, null ); // $ExpectError - f( x, y, z, undefined ); // $ExpectError - f( x, y, z, [ '1' ] ); // $ExpectError - f( x, y, z, {} ); // $ExpectError - f( x, y, z, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( 10, y, z, w, u ); // $ExpectError - f( '10', y, z, w, u ); // $ExpectError - f( true, y, z, w, u ); // $ExpectError - f( false, y, z, w, u ); // $ExpectError - f( null, y, z, w, u ); // $ExpectError - f( undefined, y, z, w, u ); // $ExpectError - f( [ '1' ], y, z, w, u ); // $ExpectError - f( {}, y, z, w, u ); // $ExpectError - f( ( x: number ): number => x, y, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, 10, z, w, u ); // $ExpectError - f( x, '10', z, w, u ); // $ExpectError - f( x, true, z, w, u ); // $ExpectError - f( x, false, z, w, u ); // $ExpectError - f( x, null, z, w, u ); // $ExpectError - f( x, undefined, z, w, u ); // $ExpectError - f( x, [ '1' ], z, w, u ); // $ExpectError - f( x, {}, z, w, u ); // $ExpectError - f( x, ( x: number ): number => x, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, 10, w, u ); // $ExpectError - f( x, y, '10', w, u ); // $ExpectError - f( x, y, true, w, u ); // $ExpectError - f( x, y, false, w, u ); // $ExpectError - f( x, y, null, w, u ); // $ExpectError - f( x, y, undefined, w, u ); // $ExpectError - f( x, y, [ '1' ], w, u ); // $ExpectError - f( x, y, {}, w, u ); // $ExpectError - f( x, y, ( x: number ): number => x, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, 10, u ); // $ExpectError - f( x, y, z, '10', u ); // $ExpectError - f( x, y, z, true, u ); // $ExpectError - f( x, y, z, false, u ); // $ExpectError - f( x, y, z, null, u ); // $ExpectError - f( x, y, z, undefined, u ); // $ExpectError - f( x, y, z, [ '1' ], u ); // $ExpectError - f( x, y, z, {}, u ); // $ExpectError - f( x, y, z, ( x: number ): number => x, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fifth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, w, 10 ); // $ExpectError - f( x, y, z, w, '10' ); // $ExpectError - f( x, y, z, w, true ); // $ExpectError - f( x, y, z, w, false ); // $ExpectError - f( x, y, z, w, null ); // $ExpectError - f( x, y, z, w, undefined ); // $ExpectError - f( x, y, z, w, [ '1' ] ); // $ExpectError - f( x, y, z, w, {} ); // $ExpectError - f( x, y, z, w, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/add.js b/examples/add.js deleted file mode 100644 index 775b711..0000000 --- a/examples/add.js +++ /dev/null @@ -1,121 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var dispatch = require( './../lib' ); - -function add2( arrays ) { - var opts; - var xo; - var yo; - var zo; - var sx; - var sy; - var sz; - var sh; - var N; - var x; - var y; - var z; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - z = arrays[ 2 ]; - xo = x.order; - yo = y.order; - zo = z.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - opts.order = yo; - sy = ind2sub( sh, i, opts ); - v = x.get.apply( x, sx ) + y.get.apply( y, sy ); - - opts.order = zo; - sz = ind2sub( sh, i, opts ); - sz.push( v ); - z.set.apply( z, sz ); - } -} - -var fcns = [ - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2 -]; - -var types = [ - dtypes.float64, dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.int32, dtypes.int32, - dtypes.uint32, dtypes.uint32, dtypes.uint32, - dtypes.int16, dtypes.int16, dtypes.int16, - dtypes.uint16, dtypes.uint16, dtypes.uint16, - dtypes.int8, dtypes.int8, dtypes.int8, - dtypes.uint8, dtypes.uint8, dtypes.uint8, - dtypes.uint8c, dtypes.uint8c, dtypes.uint8c -]; - -var add = dispatch( fcns, types, null, 3, 2, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var zbuf = new Float64Array( xbuf.length ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var z = ndarray( 'float64', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); - -xbuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -ybuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -zbuf = new Int32Array( xbuf.length ); - -x = ndarray( 'int32', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'int32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -z = ndarray( 'int32', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); diff --git a/examples/sin.js b/examples/sin.js deleted file mode 100644 index 8cd4871..0000000 --- a/examples/sin.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int8Array = require( '@stdlib/array-int8' ); -var sin = require( '@stdlib/math-base-special-sin' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/strided-dtypes' ); -var dispatch = require( './../lib' ); - -function apply( arrays, fcn ) { - var opts; - var xo; - var yo; - var sx; - var sy; - var sh; - var N; - var x; - var y; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - xo = x.order; - yo = y.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - v = fcn( x.get.apply( x, sx ) ); - - opts.order = yo; - sy = ind2sub( sh, i, opts ); - sy.push( v ); - y.set.apply( y, sy ); - } -} - -var fcns = [ - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply -]; - -var types = [ - dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float64, - dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.float64, - dtypes.uint32, dtypes.float64, - dtypes.int16, dtypes.float64, - dtypes.int16, dtypes.float32, - dtypes.uint16, dtypes.float64, - dtypes.uint16, dtypes.float32, - dtypes.int8, dtypes.float64, - dtypes.int8, dtypes.float32, - dtypes.uint8, dtypes.float64, - dtypes.uint8, dtypes.float32, - dtypes.uint8c, dtypes.float64, - dtypes.uint8c, dtypes.float32 -]; - -var data = [ - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin -]; - -var sine = dispatch( fcns, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); - -xbuf = new Int8Array( [ 1, 2, 3, 4, 5 ] ); -ybuf = new Float32Array( xbuf.length ); - -x = ndarray( 'int8', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'float32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); diff --git a/examples/unary.js b/examples/unary.js deleted file mode 100644 index e9c3fb4..0000000 --- a/examples/unary.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -var unary = require( '@stdlib/ndarray-base-unary' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var dispatch = require( './../lib' ); - -var types = [ 'float64', 'float64' ]; - -var data = [ - abs -]; - -var absolute = dispatch( unary, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -absolute( x, y ); -console.log( ybuf ); -// => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index bf753e9..955072f 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..61e1ca6 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@v0.1.0-esm/index.mjs";function m(e,r,t,n,i,a,s,o,u){var d,m,l,f;for(d=a,l=0;l [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( 'invalid invocation. Insufficient arguments.' );\n\t\t\t}\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n"],"names":["indexOfTypes","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","i","j","dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","out","push","resolveEnum","types2enums","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","getDType","slice"],"mappings":";;i+BA6EA,SAASA,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,KAAgBE,EAAGI,GADdE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,CACN,CACD,OAAQ,CACT,CCMA,SAASU,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,oGAAqGZ,IAEnI,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,+EAAgFX,IAE9G,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,sFAAuFV,IAErH,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,6EAA8ET,IAE5G,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,+EAAgFR,IAE9G,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,+EAAgFP,IAG9G,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAO,8IAElB,GAAKb,IAAUG,EACd,MAAM,IAAIU,MAAO,8FAElB,GAAKR,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAO,qJAIlB,GADAT,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAO,gJAGnB,GAAKd,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAO,qGAGlB,OADAf,EA5GD,SAAsBA,GACrB,IAAIkB,EACAtB,EAGJ,IADAsB,EAAM,GACAtB,EAAI,EAAGA,EAAII,EAAMgB,OAAQpB,IAC9BsB,EAAIC,KAAMC,EAAapB,EAAOJ,KAE/B,OAAOsB,CACR,CAmGSG,CAAarB,GAgBrB,WACC,IAAIsB,EACAC,EACAC,EACAC,EACAC,EACAC,EACA/B,EAGJ,IADA4B,EAAOI,UAAUZ,UACHd,EAAQ,CACrB,GAAKsB,EAAOtB,EACX,MAAM,IAAIa,MAAO,+CAElB,MAAM,IAAIA,MAAO,0CACjB,CAGD,IAFAO,EAAS,GACTC,EAAS,GACH3B,EAAI,EAAGA,EAAIM,EAAON,IAAM,CAE7B,IAAMiC,EADNH,EAAIE,UAAWhC,IAEd,MAAKA,EAAIO,EACF,IAAIO,UAAWC,EAAQ,6EAA8Ee,IAErG,IAAIhB,UAAWC,EAAQ,8EAA+Ee,IAG9GJ,EAAOH,KAAMO,GACbH,EAAOJ,KAAMC,EAAaU,EAAUJ,IACpC,CAKD,IAHAD,EAAMzC,EAAcsB,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGkB,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAIb,UAAW,+GAIrBiB,EADIpB,GAGAR,EAAM0B,GAGNxB,EACJ0B,EAAGL,EAAQrB,EAAMwB,IAEjBE,EAAGL,GAEJ,GAAc,IAATlB,EACJ,OAAOkB,EAAQjB,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOkB,EAAOS,MAAO5B,EACrB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 291641d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Create an ndarray function interface which performs multiple dispatch. -* -* @module @stdlib/ndarray-dispatch -* -* @example -* var dispatch = require( '@stdlib/ndarray-dispatch' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/index_of_types.js b/lib/index_of_types.js deleted file mode 100644 index fda2297..0000000 --- a/lib/index_of_types.js +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found). -* -* ## Notes -* -* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types). -* - The function assumes that `x` is stored in row-major order. -* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`. -* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value. -* -* @private -* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension) -* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension) -* @param {ArrayLikeObject} x - input two-dimensional reference array -* @param {integer} strideX1 - `x` stride length along first dimension -* @param {integer} strideX2 - `x` stride length along second dimension -* @param {NonNegativeInteger} offsetX - `x` starting index -* @param {ArrayLikeObject} y - search array -* @param {integer} strideY - `y` stride length -* @param {NonNegativeInteger} offsetY - `y` starting index -* @returns {integer} row index (if found) and `-1` otherwise -* -* @example -* // Define a reference array to search: -* var types = [ -* 'float64', 'float64', 'float64', -* 'float32', 'float32', 'float32', -* 'uint32', 'uint32', 'float64', -* 'int32', 'int32', 'float64', -* 'uint16', 'uint16', 'float64', -* 'int16', 'int16', 'float64', -* 'uint8', 'uint8', 'float64', -* 'int8', 'int8', 'float64' -* ]; -* -* // Define reference array dimensions: -* var N = 8; // rows -* var M = 3; // columns -* -* // Define a search array: -* y1 = [ -* 'float32', 'float32', 'float32', -* ]; -* -* // Find the list of types: -* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 ); -* // returns 1 -* -// Define a search array: -* y2 = [ -* 'float32', 'float32', 'float64', -* ]; -* -* // Find the list of types: -* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 ); -* // returns -1 -*/ -function indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len - var ix; - var iy; - var i; - var j; - - // Search for the first row which matches `y`... - ix = offsetX; - for ( i = 0; i < N; i++ ) { - iy = offsetY; - for ( j = 0; j < M; j++ ) { - if ( x[ ix+(j*strideX2) ] !== y[ iy ] ) { - break; - } - iy += strideY; - } - // If we successfully iterated over all columns, then that means we've found a match... - if ( j === M ) { - return i; - } - ix += strideX1; - } - return -1; -} - - -// EXPORTS // - -module.exports = indexOfTypes; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 5f4bb5d..0000000 --- a/lib/main.js +++ /dev/null @@ -1,231 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isFunctionArray = require( '@stdlib/assert-is-function-array' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/string-format' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var resolveEnum = require( '@stdlib/ndarray-base-dtype-resolve-enum' ); -var indexOfTypes = require( './index_of_types.js' ); - - -// FUNCTIONS // - -/** -* Returns a list of data type enumeration constants. -* -* @private -* @param {Collection} types - list of types -* @returns {IntegerArray} list of data type enumeration constants -*/ -function types2enums( types ) { - var out; - var i; - - out = []; - for ( i = 0; i < types.length; i++ ) { - out.push( resolveEnum( types[ i ] ) ); - } - return out; -} - - -// MAIN // - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param {(FunctionArray|Function)} fcns - list of ndarray functions -* @param {Collection} types - one-dimensional list of ndarray argument data types -* @param {(Collection|null)} data - ndarray function data (e.g., callbacks) -* @param {PositiveInteger} nargs - total number of ndarray function interface arguments -* @param {NonNegativeInteger} nin - number of input ndarrays -* @param {NonNegativeInteger} nout - number of output ndarrays -* @throws {TypeError} first argument must be either a function or an array of functions -* @throws {TypeError} second argument must be an array-like object -* @throws {TypeError} third argument must be an array-like object or `null` -* @throws {Error} third and first arguments must have the same number of elements -* @throws {TypeError} fourth argument must be a positive integer -* @throws {TypeError} fifth argument must be a nonnegative integer -* @throws {TypeError} sixth argument must be a nonnegative integer -* @throws {Error} fourth argument must equal the specified number of input and output arrays -* @throws {Error} number of types must match the number of functions times the total number of array arguments for each function -* @throws {Error} interface must accept at least one input and/or output ndarray -* @returns {Function} ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function dispatch( fcns, types, data, nargs, nin, nout ) { - var narrays; - var nfcns; - var fcn; - - if ( isFunction( fcns ) ) { - fcn = fcns; - } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) ); - } - if ( !isCollection( types ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) ); - } - if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); - } - if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) ); - } - if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) ); - } - if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) ); - } - narrays = nin + nout; - if ( narrays === 0 ) { - throw new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' ); - } - if ( nargs !== narrays ) { - throw new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' ); - } - if ( fcn ) { - nfcns = types.length / narrays; - if ( !isInteger( nfcns ) ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); - } - } else { - nfcns = fcns.length; - if ( types.length !== nfcns*narrays ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); - } - } - if ( data && data.length !== nfcns ) { - throw new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' ); - } - types = types2enums( types ); - return dispatcher; - - /** - * ndarray function interface which performs multiple dispatch. - * - * @private - * @param {ndarrayLike} x - ndarray - * @param {...ndarrayLike} args - ndarray arguments - * @throws {Error} insufficient arguments - * @throws {Error} too many arguments - * @throws {TypeError} input array arguments must be ndarray-like objects - * @throws {TypeError} output array arguments must be ndarray-like objects - * @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types - * @returns {(ndarrayLike|Array|void)} destination array(s) - */ - function dispatcher() { - var arrays; - var dtypes; - var argc; - var idx; - var v; - var f; - var i; - - argc = arguments.length; - if ( argc !== nargs ) { - if ( argc < nargs ) { - throw new Error( 'invalid invocation. Insufficient arguments.' ); - } - throw new Error( 'invalid invocation. Too many arguments.' ); - } - arrays = []; - dtypes = []; - for ( i = 0; i < nargs; i++ ) { - v = arguments[ i ]; - if ( !isndarrayLike( v ) ) { - if ( i < nin ) { - throw new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) ); - } else { - throw new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) ); - } - } - arrays.push( v ); - dtypes.push( resolveEnum( getDType( v ) ) ); - } - // Resolve the ndarray function satisfying the input array types: - idx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len - - // Check whether we were able to successfully resolve an ndarray function: - if ( idx < 0 ) { - throw new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' ); - } - // Retrieve the ndarray function: - if ( fcn ) { - f = fcn; - } else { - f = fcns[ idx ]; - } - // Evaluate the ndarray function: - if ( data ) { - f( arrays, data[ idx ] ); - } else { - f( arrays ); - } - if ( nout === 1 ) { - return arrays[ narrays-1 ]; - } - if ( nout === 0 ) { - return; - } - return arrays.slice( nin ); - } -} - - -// EXPORTS // - -module.exports = dispatch; diff --git a/package.json b/package.json index 5e6762c..06365f4 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Create an ndarray function interface which performs multiple dispatch.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-collection": "^0.1.0", - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/assert-is-function-array": "^0.1.0", - "@stdlib/assert-is-integer": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/assert-is-nonnegative-integer": "^0.1.0", - "@stdlib/assert-is-positive-integer": "^0.1.0", - "@stdlib/ndarray-base-dtype-resolve-enum": "^0.1.0", - "@stdlib/ndarray-dtype": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.1.1", - "@stdlib/array-float64": "^0.1.1", - "@stdlib/array-int32": "^0.1.1", - "@stdlib/array-int8": "^0.1.1", - "@stdlib/array-uint8": "^0.1.1", - "@stdlib/math-base-assert-is-nan": "^0.1.1", - "@stdlib/math-base-special-abs": "^0.1.1", - "@stdlib/math-base-special-pow": "^0.1.0", - "@stdlib/math-base-special-sin": "^0.1.0", - "@stdlib/ndarray-base-buffer-dtype": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-unary": "^0.1.0", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-dtypes": "^0.1.0", - "@stdlib/ndarray-ind2sub": "^0.1.1", - "@stdlib/strided-dtypes": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "ndarray", @@ -99,7 +26,6 @@ "multimethod", "multimethods" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..b88d04a --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/fixtures/binary.js b/test/fixtures/binary.js deleted file mode 100644 index a60dfa2..0000000 --- a/test/fixtures/binary.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Binary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @returns {number} sum -*/ -function binary( x, y ) { - return x + y; -} - - -// EXPORTS // - -module.exports = binary; diff --git a/test/fixtures/fill.js b/test/fixtures/fill.js deleted file mode 100644 index 41b2958..0000000 --- a/test/fixtures/fill.js +++ /dev/null @@ -1,76 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which fills one or more ndarrays. -* -* @private -* @param {*} value - fill value -* @returns {Function} ndarray function -*/ -function fill( value ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - */ - function ndarrayFcn( arrays ) { - var opts; - var sub; - var arr; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - opts = { - 'order': '' - }; - for ( j = 0; j < M; j++ ) { - arr = arrays[ j ]; - opts.order = arrays[ j ].order; - for ( i = 0; i < N; i++ ) { - sub = ind2sub( sh, i, opts ); - sub.push( value ); - arr.set.apply( arr, sub ); - } - } - } -} - - -// EXPORTS // - -module.exports = fill; diff --git a/test/fixtures/foreach.js b/test/fixtures/foreach.js deleted file mode 100644 index a426290..0000000 --- a/test/fixtures/foreach.js +++ /dev/null @@ -1,72 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function forEach( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - fcn.apply( null, args ); - } -} - - -// EXPORTS // - -module.exports = forEach; diff --git a/test/fixtures/map1n.js b/test/fixtures/map1n.js deleted file mode 100644 index 614196b..0000000 --- a/test/fixtures/map1n.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function which maps the return value of a callback to `N` arrays. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function map1N( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var v; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - v = fcn(); - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - sub.push( v ); - arrays[ j ].set.apply( arrays[ j ], sub ); - } - } -} - - -// EXPORTS // - -module.exports = map1N; diff --git a/test/fixtures/nullary.js b/test/fixtures/nullary.js deleted file mode 100644 index 4f22126..0000000 --- a/test/fixtures/nullary.js +++ /dev/null @@ -1,36 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Nullary callback. -* -* @private -* @returns {number} value -*/ -function nullary() { - return 3.0; -} - - -// EXPORTS // - -module.exports = nullary; diff --git a/test/fixtures/quaternary.js b/test/fixtures/quaternary.js deleted file mode 100644 index 548437b..0000000 --- a/test/fixtures/quaternary.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quaternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @returns {number} sum -*/ -function quaternary( x, y, z, w ) { - return x + y + z + w; -} - - -// EXPORTS // - -module.exports = quaternary; diff --git a/test/fixtures/quinary.js b/test/fixtures/quinary.js deleted file mode 100644 index 36068de..0000000 --- a/test/fixtures/quinary.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quinary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @param {number} u - input value -* @returns {number} sum -*/ -function quinary( x, y, z, w, u ) { - return x + y + z + w + u; -} - - -// EXPORTS // - -module.exports = quinary; diff --git a/test/fixtures/sum.js b/test/fixtures/sum.js deleted file mode 100644 index efdbb1b..0000000 --- a/test/fixtures/sum.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which computes the sum across one or more ndarrays. -* -* @private -* @param {Object} ctx - context -* @param {number} ctx.sum - initial sum -* @returns {Function} ndarray function -*/ -function wrapper( ctx ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - * @param {Function} [fcn] - callback - */ - function ndarrayFcn( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var f; - var i; - var j; - - if ( arguments.length > 1 ) { - f = fcn; - } - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - if ( f ) { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - ctx.sum += f.apply( null, args ); - } - } else { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - ctx.sum += arrays[ j ].get.apply( arrays[ j ], sub ); - } - } - } - } -} - - -// EXPORTS // - -module.exports = wrapper; diff --git a/test/fixtures/ternary.js b/test/fixtures/ternary.js deleted file mode 100644 index 0595d5f..0000000 --- a/test/fixtures/ternary.js +++ /dev/null @@ -1,39 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Ternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @returns {number} sum -*/ -function ternary( x, y, z ) { - return x + y + z; -} - - -// EXPORTS // - -module.exports = ternary; diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d6c2c8e..0000000 --- a/test/test.js +++ /dev/null @@ -1,363 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var fill = require( './fixtures/fill.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either a function or an array of functions as a first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( value, types, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object as a second argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided either an array-like object or `null` as a third argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - dispatch( unary, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a positive integer for a fourth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 0, - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a fifth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, value, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a sixth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, 1, value ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function array)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var fcns = [ unary, unary, unary ]; - var data = [ abs, abs, abs ]; - dispatch( fcns, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function argument)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs, abs, abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the length of `data` argument does not match the number of ndarray functions', function test( t ) { - var values; - var i; - - values = [ - [], - [ abs, abs ], - [ abs, abs, abs ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var fcns = [ unary ]; - dispatch( fcns, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the fourth argument is incompatible with the number of input and output ndarrays', function test( t ) { - var values; - var i; - - values = [ - 0, - 1, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of specified input and output ndarrays is zero', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var types = [ 'float64' ]; - dispatch( fill( 3 ), types, null, 1, 0, 0 ); - } -}); - -tape( 'the function returns an ndarray function interface', function test( t ) { - var types; - var data; - var f; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - f = dispatch( unary, types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ unary ], types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( fill( 3 ), types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ fill( 3 ) ], types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.two_arrays.js b/test/test.two_arrays.js deleted file mode 100644 index 16eb61b..0000000 --- a/test/test.two_arrays.js +++ /dev/null @@ -1,814 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var dtype = require( '@stdlib/ndarray-base-buffer-dtype' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var forEach = require( './fixtures/foreach.js' ); -var map1N = require( './fixtures/map1n.js' ); -var fill = require( './fixtures/fill.js' ); -var sum = require( './fixtures/sum.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the first argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var ybuf = new Float64Array( 10 ); - var y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( value, y ); - }; - } -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the second argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var xbuf = new Float64Array( 10 ); - var x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( x, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided insufficient arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var f; - var x; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [], - [ x ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided too many arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var ybuf; - var f; - var x; - var y; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [ x, y, y ], - [ x, y, y, y ], - [ x, y, y, y, y ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if unable to resolve a ndarray function supporting the provided array argument data types', function test( t ) { - var values; - var types; - var data; - var xbuf; - var fcn; - var x; - var i; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ abs, abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 4 ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - values = [ - new Uint8Array( 4 ), - new Int32Array( 4 ), - [ 0, 0, 0, 0 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided an array having data type: ' + dtype( values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var y = ndarray( dtype( value ), value, [ value.length ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - }; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only input arrays)', function test( t ) { - var types; - var xbuf; - var ybuf; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only output arrays)', function test( t ) { - var expected; - var types; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only input arrays)', function test( t ) { - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var ctx; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcns = [ - sum( ctx ), - sum( ctx ) - ]; - fcn = dispatch( fcns, types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only output arrays)', function test( t ) { - var expected; - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcns = [ - fill( 3.0 ), - fill( 4.0 ) - ]; - fcn = dispatch( fcns, types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - - fcn = dispatch( forEach, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - - fcn = dispatch( map1N, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - fcns = [ - forEach, - forEach - ]; - fcn = dispatch( fcns, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - fcns = [ - map1N, - map1N - ]; - fcn = dispatch( fcns, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - fcns = [ - unary, - unary - ]; - fcn = dispatch( fcns, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which returns one or more output arrays, if one or more output arrays is specified, and otherwise returns `undefined`', function test( t ) { - var types; - var data; - var xbuf; - var ybuf; - var out; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - // No output arrays... - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, void 0, 'returns expected value' ); - - // One output array... - data = [ - abs, - abs - ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - fcn = dispatch( fill( 3.0 ), types, null, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - // Two output arrays... - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.end(); -}); From 5bde238c3ad43e0db2c6aa3f6e21f2b3f3ceb7f5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 21 Jan 2024 05:49:16 +0000 Subject: [PATCH 053/109] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9fbece1..5e6762c 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/assert-is-positive-integer": "^0.1.0", "@stdlib/ndarray-base-dtype-resolve-enum": "^0.1.0", "@stdlib/ndarray-dtype": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0" }, "devDependencies": { From 399a780f6982d1263b92e1ba320cb91618060b28 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 21 Jan 2024 05:49:45 +0000 Subject: [PATCH 054/109] Remove files --- index.d.ts | 334 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6516 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 955072f..0000000 --- a/index.d.ts +++ /dev/null @@ -1,334 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* ndarray function. -* -* @param arrays - array containing input and output ndarrays -* @param data - ndarray function data (e.g., a callback) -* -* @example -* var numel = require( `@stdlib/ndarray/base/numel` ); -* var ind2sub = require( `@stdlib/ndarray/ind2sub` ); -* -* function ndarrayFcn( arrays, fcn ) { -* var xord; -* var yord; -* var opts; -* var sub; -* var sh; -* var N; -* var x; -* var y; -* var v; -* var i; -* -* x = arrays[ 0 ]; -* y = arrays[ 1 ]; -* sh = x.shape; -* N = numel( sh ); -* if ( N <= 0 ) { -* return; -* } -* xord = x.order; -* yord = y.order; -* opts = {}; -* opts.order = xord; -* for ( i = 0; i < N; i++ ) { -* // Convert a linear index to subscripts: -* opts.order = xord; -* sub = ind2sub( sh, i, opts ); -* -* // Retrieve an element from `x`: -* v = x.get.apply( x, sub ); -* -* // Convert a linear index to subscripts: -* opts.order = yord; -* sub = ind2sub( sh, i, opts ); -* -* // Append the result of applying the callback: -* sub.push( fcn( v ) ); -* -* // Assign the result to an element in `y`: -* y.set.apply( y, sub ); -* } -* } -*/ -type ndarrayFcn = ( arrays: Array, data?: any ) => void; - -/** -* Interface describing an ndarray function dispatcher. -*/ -interface Dispatcher { - /** - * Invokes an ndarray function based on the provided array data type(s). - * - * @param x - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array - * - * @example - * var nullary = require( `@stdlib/ndarray/base/nullary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function value() { - * return 3.14; - * } - * - * var types = [ 'float64' ]; - * var data = [ value ]; - * - * var fcn = dispatch( nullary, types, data, 1, 0, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( 5 ); - * var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x ); - * // xbuf => [ 3.14, 3.14, 3.14, 3.14, 3.14 ] - */ - ( x: ndarray ): ndarray | void; - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var unary = require( `@stdlib/ndarray/base/unary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * var abs = require( `@stdlib/math/base/special/abs` ); - * - * var types = [ 'float64', 'float64' ]; - * var data = [ abs ]; - * - * var fcn = dispatch( unary, types, data, 2, 1, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - * var ybuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y ); - * // ybuf => [ 1.0, 2.0, 3.0 ] - */ - ( x: ndarray, y: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var ternary = require( `@stdlib/ndarray/base/ternary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add2( x, y ) { - * return x + y; - * } - * - * var types = [ 'float64', 'float64', 'float64' ]; - * var data = [ add2 ]; - * - * var fcn = dispatch( ternary, types, data, 3, 2, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z ); - * // zbuf => [ 2.0, 4.0, 6.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quaternary = require( `@stdlib/ndarray/base/quaternary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add3( x, y, z ) { - * return x + y + z; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add3 ]; - * - * var fcn = dispatch( quaternary, types, data, 4, 3, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w ); - * // wbuf => [ 3.0, 6.0, 9.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @param args - ndarray arguments - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quinary = require( `@stdlib/ndarray/base/quinary` ); - * var Float64Array = require( `@stdlib/array/float64` ); - * var ndarray = require( `@stdlib/ndarray/ctor` ); - * - * function add4( x, y, z, w ) { - * return x + y + z + w; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add4 ]; - * - * var fcn = dispatch( quinary, types, data, 5, 4, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ubuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var u = ndarray( 'float64', ubuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w, u ); - * // ubuf => [ 4.0, 8.0, 12.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray, ...args: Array ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures -} - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param fcns - list of ndarray functions -* @param types - one-dimensional list of ndarray argument data types -* @param data - ndarray function data (e.g., callbacks) -* @param nargs - total number of ndarray function interface arguments -* @param nin - number of input ndarrays -* @param nout - number of output ndarrays -* @throws first argument must be either a function or an array of functions -* @throws second argument must be an array-like object -* @throws third argument must be an array-like object or `null` -* @throws third and first arguments must have the same number of elements -* @throws fourth argument must be a positive integer -* @throws fifth argument must be a nonnegative integer -* @throws sixth argument must be a nonnegative integer -* @throws fourth argument must equal the specified number of input and output arrays -* @throws number of types must match the number of functions times the total number of array arguments for each function -* @throws interface must accept at least one input and/or output ndarray -* @returns ndarray function interface -* -* @example -* var unary = require( `@stdlib/ndarray/base/unary` ); -* var abs = require( `@stdlib/math/base/special/abs` ); -* var Float64Array = require( `@stdlib/array/float64` ); -* var ndarray = require( `@stdlib/ndarray/ctor` ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var fcn = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* fcn( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function dispatch( fcns: ndarrayFcn | ArrayLike, types: ArrayLike, data: ArrayLike | null, nargs: number, nin: number, nout: number ): Dispatcher; - - -// EXPORTS // - -export = dispatch; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 61e1ca6..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@v0.1.0-esm/index.mjs";function m(e,r,t,n,i,a,s,o,u){var d,m,l,f;for(d=a,l=0;l [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( 'invalid invocation. Insufficient arguments.' );\n\t\t\t}\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n"],"names":["indexOfTypes","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","i","j","dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","out","push","resolveEnum","types2enums","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","getDType","slice"],"mappings":";;i+BA6EA,SAASA,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,KAAgBE,EAAGI,GADdE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,CACN,CACD,OAAQ,CACT,CCMA,SAASU,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,oGAAqGZ,IAEnI,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,+EAAgFX,IAE9G,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,sFAAuFV,IAErH,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,6EAA8ET,IAE5G,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,+EAAgFR,IAE9G,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,+EAAgFP,IAG9G,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAO,8IAElB,GAAKb,IAAUG,EACd,MAAM,IAAIU,MAAO,8FAElB,GAAKR,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAO,qJAIlB,GADAT,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAO,gJAGnB,GAAKd,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAO,qGAGlB,OADAf,EA5GD,SAAsBA,GACrB,IAAIkB,EACAtB,EAGJ,IADAsB,EAAM,GACAtB,EAAI,EAAGA,EAAII,EAAMgB,OAAQpB,IAC9BsB,EAAIC,KAAMC,EAAapB,EAAOJ,KAE/B,OAAOsB,CACR,CAmGSG,CAAarB,GAgBrB,WACC,IAAIsB,EACAC,EACAC,EACAC,EACAC,EACAC,EACA/B,EAGJ,IADA4B,EAAOI,UAAUZ,UACHd,EAAQ,CACrB,GAAKsB,EAAOtB,EACX,MAAM,IAAIa,MAAO,+CAElB,MAAM,IAAIA,MAAO,0CACjB,CAGD,IAFAO,EAAS,GACTC,EAAS,GACH3B,EAAI,EAAGA,EAAIM,EAAON,IAAM,CAE7B,IAAMiC,EADNH,EAAIE,UAAWhC,IAEd,MAAKA,EAAIO,EACF,IAAIO,UAAWC,EAAQ,6EAA8Ee,IAErG,IAAIhB,UAAWC,EAAQ,8EAA+Ee,IAG9GJ,EAAOH,KAAMO,GACbH,EAAOJ,KAAMC,EAAaU,EAAUJ,IACpC,CAKD,IAHAD,EAAMzC,EAAcsB,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGkB,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAIb,UAAW,+GAIrBiB,EADIpB,GAGAR,EAAM0B,GAGNxB,EACJ0B,EAAGL,EAAQrB,EAAMwB,IAEjBE,EAAGL,GAEJ,GAAc,IAATlB,EACJ,OAAOkB,EAAQjB,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOkB,EAAOS,MAAO5B,EACrB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index b88d04a..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 9f80259e3508db025c8db185f3d3f9e773d65eb3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 21 Jan 2024 05:50:17 +0000 Subject: [PATCH 055/109] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 59 +- SECURITY.md | 5 - benchmark/benchmark.dispatch_size.js | 156 - benchmark/benchmark.js | 81 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 87 - docs/types/test.ts | 641 --- examples/add.js | 121 - examples/sin.js | 142 - examples/unary.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/index_of_types.js | 106 - lib/main.js | 231 - package.json | 78 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/binary.js | 38 - test/fixtures/fill.js | 76 - test/fixtures/foreach.js | 72 - test/fixtures/map1n.js | 74 - test/fixtures/nullary.js | 36 - test/fixtures/quaternary.js | 40 - test/fixtures/quinary.js | 41 - test/fixtures/sum.js | 98 - test/fixtures/ternary.js | 39 - test/test.js | 363 -- test/test.two_arrays.js | 814 --- 56 files changed, 6211 insertions(+), 6742 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.dispatch_size.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/add.js delete mode 100644 examples/sin.js delete mode 100644 examples/unary.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/index_of_types.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/fixtures/binary.js delete mode 100644 test/fixtures/fill.js delete mode 100644 test/fixtures/foreach.js delete mode 100644 test/fixtures/map1n.js delete mode 100644 test/fixtures/nullary.js delete mode 100644 test/fixtures/quaternary.js delete mode 100644 test/fixtures/quinary.js delete mode 100644 test/fixtures/sum.js delete mode 100644 test/fixtures/ternary.js delete mode 100644 test/test.js delete mode 100644 test/test.two_arrays.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ac0b7cd..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 30656c4..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 5e92c3e..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c92f5c4..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index d53fd56..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '43 7 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index e1e3539..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -302,7 +295,7 @@ console.log( ybuf ); ## 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. +This package is part of [stdlib][stdlib], a standard library 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]. @@ -362,11 +355,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-dispatch/main/LICENSE -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.dispatch_size.js b/benchmark/benchmark.dispatch_size.js deleted file mode 100644 index 15805ba..0000000 --- a/benchmark/benchmark.dispatch_size.js +++ /dev/null @@ -1,156 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib/main.js' ); - - -// FUNCTIONS // - -/** -* Evaluates the identity function. -* -* @private -* @param {*} v - value -* @returns {*} input value -*/ -function identity( v ) { - return v; -} - -/** -* Dummy function which throws an error. -* -* @private -* @throws {Error} unexpected error -*/ -function throwError() { - throw new Error( 'unexpected error' ); -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} size - dispatch size -* @returns {Function} benchmark function -*/ -function createBenchmark( size ) { - var types; - var data; - var fcn; - var x; - var y; - var t; - var i; - - types = []; - - // Create dummy types... - for ( i = 0; i < (size-1)*2; i += 2 ) { - t = 'foo' + i; - types.push( t ); - types.push( t ); - } - // Append test types: - types.push( 'float64' ); - types.push( 'float64' ); - - // Define a list of callbacks: - data = []; - for ( i = 0; i < size-1; i++ ) { - data.push( throwError ); - } - // Append a test callback: - data.push( identity ); - - // Create the dispatcher: - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - // Create sample arrays: - x = new Float64Array( 1 ); - y = new Float64Array( x.length ); - - x = ndarray( 'float64', x, [ 1 ], [ 1 ], 0, 'row-major' ); - y = ndarray( 'float64', y, [ 1 ], [ 1 ], 0, 'row-major' ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var z; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x.data[ 0 ] = i; - z = fcn( x, y ); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var size; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - size = pow( 2, i ); - f = createBenchmark( size ); - bench( pkg+':size='+size, f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 3c6f450..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::fcns_array', function benchmark( b ) { - var types; - var fcns; - var data; - var out; - var i; - - fcns = [ unary ]; - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( fcns, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::fcn_arg', function benchmark( b ) { - var types; - var data; - var out; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( unary, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 6c1b20d..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch" -%% click B href "https://github.com/stdlib-js/ndarray-dispatch/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-dispatch/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-dispatch/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-dispatch/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-dispatch/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch -[production-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 1295a44..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import dispatch from '../docs/types/index'; -export = dispatch; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7fb29cb..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var y=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var b=y(function(D,w){ -function k(i,r,e,u,f,m,n,o,l){var h,t,s,a;for(h=m,s=0;s [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( 'invalid invocation. Insufficient arguments.' );\n\t\t\t}\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = dispatch;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an ndarray function interface which performs multiple dispatch.\n*\n* @module @stdlib/ndarray-dispatch\n*\n* @example\n* var dispatch = require( '@stdlib/ndarray-dispatch' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var unary = require( '@stdlib/ndarray-base-unary' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var types = [\n* 'float64', 'float64'\n* ];\n*\n* var data = [\n* abs\n* ];\n*\n* var absolute = dispatch( unary, types, data, 2, 1, 1 );\n*\n* // ...\n*\n* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] );\n* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] );\n*\n* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' );\n* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' );\n*\n* absolute( x, y );\n* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA6EA,SAASC,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,EAAU,CAClF,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,CAAU,IAAME,EAAGI,CAAG,EADjBE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,CACP,CACA,MAAO,EACR,CAKAL,EAAO,QAAUC,ICzGjB,IAAAc,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAoB,QAAS,oCAAqC,EAClEC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAkB,QAAS,kCAAmC,EAC9DC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAc,QAAS,yCAA0C,EACjEC,EAAe,IAYnB,SAASC,EAAaC,EAAQ,CAC7B,IAAIC,EACAC,EAGJ,IADAD,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIF,EAAM,OAAQE,IAC9BD,EAAI,KAAMJ,EAAaG,EAAOE,CAAE,CAAE,CAAE,EAErC,OAAOD,CACR,CAqDA,SAASE,EAAUC,EAAMJ,EAAOK,EAAMC,EAAOC,EAAKC,EAAO,CACxD,IAAIC,EACAC,EACAC,EAEJ,GAAKnB,EAAYY,CAAK,EACrBO,EAAMP,UACK,CAACb,EAAiBa,CAAK,EAClC,MAAM,IAAI,UAAWT,EAAQ,oGAAqGS,CAAK,CAAE,EAE1I,GAAK,CAACX,EAAcO,CAAM,EACzB,MAAM,IAAI,UAAWL,EAAQ,+EAAgFK,CAAM,CAAE,EAEtH,GAAK,CAACP,EAAcY,CAAK,GAAKA,IAAS,KACtC,MAAM,IAAI,UAAWV,EAAQ,sFAAuFU,CAAK,CAAE,EAE5H,GAAK,CAAChB,EAAmBiB,CAAM,EAC9B,MAAM,IAAI,UAAWX,EAAQ,6EAA8EW,CAAM,CAAE,EAEpH,GAAK,CAAClB,EAAsBmB,CAAI,EAC/B,MAAM,IAAI,UAAWZ,EAAQ,+EAAgFY,CAAI,CAAE,EAEpH,GAAK,CAACnB,EAAsBoB,CAAK,EAChC,MAAM,IAAI,UAAWb,EAAQ,+EAAgFa,CAAK,CAAE,EAGrH,GADAC,EAAUF,EAAMC,EACXC,IAAY,EAChB,MAAM,IAAI,MAAO,4IAA6I,EAE/J,GAAKH,IAAUG,EACd,MAAM,IAAI,MAAO,4FAA6F,EAE/G,GAAKE,GAEJ,GADAD,EAAQV,EAAM,OAASS,EAClB,CAACnB,EAAWoB,CAAM,EACtB,MAAM,IAAI,MAAO,8IAA+I,UAGjKA,EAAQN,EAAK,OACRJ,EAAM,SAAWU,EAAMD,EAC3B,MAAM,IAAI,MAAO,8IAA+I,EAGlK,GAAKJ,GAAQA,EAAK,SAAWK,EAC5B,MAAM,IAAI,MAAO,mGAAoG,EAEtH,OAAAV,EAAQD,EAAaC,CAAM,EACpBY,EAeP,SAASA,GAAa,CACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EAGJ,GADAa,EAAO,UAAU,OACZA,IAAST,EACb,MAAKS,EAAOT,EACL,IAAI,MAAO,6CAA8C,EAE1D,IAAI,MAAO,yCAA0C,EAI5D,IAFAO,EAAS,CAAC,EACVC,EAAS,CAAC,EACJZ,EAAI,EAAGA,EAAII,EAAOJ,IAAM,CAE7B,GADAe,EAAI,UAAWf,CAAE,EACZ,CAACR,EAAeuB,CAAE,EACtB,MAAKf,EAAIK,EACF,IAAI,UAAWZ,EAAQ,6EAA8EsB,CAAE,CAAE,EAEzG,IAAI,UAAWtB,EAAQ,8EAA+EsB,CAAE,CAAE,EAGlHJ,EAAO,KAAMI,CAAE,EACfH,EAAO,KAAMjB,EAAaD,EAAUqB,CAAE,CAAE,CAAE,CAC3C,CAKA,GAHAD,EAAMlB,EAAcY,EAAOD,EAAST,EAAOS,EAAS,EAAG,EAAGK,EAAQ,EAAG,CAAE,EAGlEE,EAAM,EACV,MAAM,IAAI,UAAW,6GAA8G,EAcpI,GAXKL,EACJO,EAAIP,EAEJO,EAAId,EAAMY,CAAI,EAGVX,EACJa,EAAGL,EAAQR,EAAMW,CAAI,CAAE,EAEvBE,EAAGL,CAAO,EAENL,IAAS,EACb,OAAOK,EAAQJ,EAAQ,CAAE,EAE1B,GAAKD,IAAS,EAGd,OAAOK,EAAO,MAAON,CAAI,CAC1B,CACD,CAKApB,EAAO,QAAUgB,IC9KjB,IAAIgB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_index_of_types", "__commonJSMin", "exports", "module", "indexOfTypes", "N", "M", "x", "strideX1", "strideX2", "offsetX", "y", "strideY", "offsetY", "ix", "iy", "i", "j", "require_main", "__commonJSMin", "exports", "module", "isNonNegativeInteger", "isPositiveInteger", "isInteger", "isFunctionArray", "isFunction", "isCollection", "isndarrayLike", "format", "getDType", "resolveEnum", "indexOfTypes", "types2enums", "types", "out", "i", "dispatch", "fcns", "data", "nargs", "nin", "nout", "narrays", "nfcns", "fcn", "dispatcher", "arrays", "dtypes", "argc", "idx", "v", "f", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 02fe150..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,87 +0,0 @@ - -{{alias}}( fcns, types, data, nargs, nin, nout ) - Returns an ndarray function interface which performs multiple dispatch. - - An ndarray function interface has the following signature: - - f( x, y, ... ) - - where - - - x: ndarray. - - y: ndarray. - - ...: additional ndarrays. - - The number of parameters is derived from `nargs`, the number of input - ndarrays is derived from `nin`, and the number of output ndarrays is derived - from `nout`. - - Parameters - ---------- - fcns: Function|ArrayLikeObject - List of ndarray functions. An ndarray function should have the following - signature: - - f( arrays, data ) - - where - - - arrays: array containing input and output ndarrays. - - data: ndarray function data (e.g., a callback). - - For convenience, a single ndarray function may be provided which will be - invoked whenever the ndarray argument data types match a sequence of - types in `types`. Providing a single ndarray function is particularly - convenient for the case where, regardless of array data types, - traversing arrays remains the same, but the ndarray function `data` - differs (e.g., callbacks which differ based on the array data types). - - types: ArrayLikeObject - One-dimensional list of ndarray argument data types. - - data: ArrayLikeObject|null - ndarray function data (e.g., callbacks). If `null`, a returned ndarray - function interface does **not** provide a `data` argument to an invoked - ndarray function. - - nargs: integer - Total number of ndarray function interface arguments. - - nin: integer - Number of input ndarrays. - - nout: integer - Number of output ndarrays. - - Returns - ------- - fcn: Function - ndarray function interface. - - Examples - -------- - // Define ndarray argument data types: - > var t = [ 'float64', 'float64', 'float32', 'float32' ]; - - // Define a list of ndarray function data (callbacks): - > var d = [ {{alias:@stdlib/math/base/special/abs}}, {{alias:@stdlib/math/base/special/absf}} ]; - - // Create an ndarray function interface for applying unary callbacks: - > var f = {{alias}}( {{alias:@stdlib/ndarray/base/unary}}, t, d, 2, 1, 1 ); - - // Create an input ndarray: - > var xbuf = new {{alias:@stdlib/array/float64}}( [ -1.0, -2.0, -3.0, -4.0 ] ); - > var x = {{alias:@stdlib/ndarray/ctor}}( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Create an output ndarray: - > var ybuf = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 0.0, 0.0 ] ); - > var y = {{alias:@stdlib/ndarray/ctor}}( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Compute the element-wise absolute value: - > f( x, y ); - > ybuf - [ 1.0, 2.0, 3.0, 4.0 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 3cba031..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,641 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable max-lines */ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import dispatch = require( './index' ); - - -// FUNCTIONS // - -/** -* Nullary callback. -* -* @return input value -*/ -function nullary(): any { - return 5.0; -} - -/** -* Unary callback. -* -* @param x - input value -* @return input value -*/ -function unary( x: any ): any { - return x; -} - -/** -* Binary callback. -* -* @param x - input value -* @param y - input value -* @return output value -*/ -function binary( x: number, y: number ): number { - return x + y; -} - -/** -* Ternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @return output value -*/ -function ternary( x: number, y: number, z: number ): number { - return x + y + z; -} - -/** -* Quaternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @param w - input value -* @return output value -*/ -function quaternary( x: number, y: number, z: number, w: number ): number { - return x + y + z + w; -} - -/** -* Mock `ind2sub` function. -* -* @param shape - dimensions -* @param idx - linear index -* @param opts - options -* @return subscripts -*/ -function ind2sub( shape: ArrayLike, idx: number, opts?: any ): Array { - let out; - let i; - - out = []; - if ( typeof opts === 'object' && opts !== null && opts.order === 'row-major' ) { no-unsafe-any - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } else { - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } - return out; -} - -/** -* Mock ndarray function. -* -* @param arrays - ndarrays -* @param fcn - callback -*/ -function ndarrayFcn( arrays: Array, fcn: ( x: any ) => any ): void { - let xord; - let yord; - let opts; - let sub; - let sh; - let N; - let x; - let y; - let v; - let i; - - x = arrays[ 0 ]; - y = arrays[ 1 ]; - sh = x.shape; - if ( sh.length === 0 ) { - return; - } - N = 1; - for ( i = 0; i < sh.length; i += 1 ) { - N *= sh[ i ]; - } - xord = x.order; - yord = y.order; - opts = { - 'order': '' - }; - opts.order = xord; - for ( i = 0; i < N; i += 1 ) { - // Convert a linear index to subscripts: - opts.order = xord; - sub = ind2sub( sh, i, opts ); - - // Retrieve an element from `x`: - v = x.get.apply( x, sub ); - - // Convert a linear index to subscripts: - opts.order = yord; - sub = ind2sub( sh, i, opts ); - - // Append the result of applying the callback: - sub[ sub.length ] = fcn( v ) as number; - - // Assign the result to an element in `y`: - y.set.apply( y, sub ); - } -} - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a dispatch function... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, 1 ); // $ExpectType Dispatcher - dispatch( [ ndarrayFcn ], types, data, 2, 1, 1 ); // $ExpectType Dispatcher -} - -// The compiler throws an error if the function is provided a first argument which is not either an ndarray function or an array-like object containing ndarray functions... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( '10', types, data, 2, 1, 1 ); // $ExpectError - dispatch( 10, types, data, 2, 1, 1 ); // $ExpectError - dispatch( true, types, data, 2, 1, 1 ); // $ExpectError - dispatch( false, types, data, 2, 1, 1 ); // $ExpectError - dispatch( null, types, data, 2, 1, 1 ); // $ExpectError - dispatch( undefined, types, data, 2, 1, 1 ); // $ExpectError - dispatch( [ '1' ], types, data, 2, 1, 1 ); // $ExpectError - dispatch( {}, types, data, 2, 1, 1 ); // $ExpectError - dispatch( ( x: number ): number => x, types, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object... -{ - const data = [ unary ]; - - dispatch( ndarrayFcn, 10, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, true, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, false, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, null, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, undefined, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, {}, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object or null... -{ - const types = [ 'float64', 'float64' ]; - - dispatch( ndarrayFcn, types, 10, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, true, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, false, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, undefined, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, {}, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, '10', 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, true, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, false, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, null, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, undefined, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, [ '1' ], 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, {}, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, ( x: number ): number => x, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, '10', 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, true, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, false, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, null, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, undefined, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, [ '1' ], 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, {}, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, ( x: number ): number => x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, '10' ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, true ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, false ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, null ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, undefined ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, [ '1' ] ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, {} ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch(); // $ExpectError - dispatch( ndarrayFcn ); // $ExpectError - dispatch( ndarrayFcn, types ); // $ExpectError - dispatch( ndarrayFcn, types, data ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, 1, 0 ); // $ExpectError -} - -// The function returns a dispatch function... -{ - const x = array(); - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const t1 = [ 'float64' ]; - const d1 = [ nullary ]; - const f1 = dispatch( ndarrayFcn, t1, d1, 1, 1, 0 ); - f1( x ); // $ExpectType void | ndarray - - const t2 = [ 'float64', 'float64' ]; - const d2 = [ unary ]; - const f2 = dispatch( ndarrayFcn, t2, d2, 2, 1, 1 ); - f2( x, y ); // $ExpectType void | ndarray - - const t3 = [ 'float64', 'float64', 'float64' ]; - const d3 = [ binary ]; - const f3 = dispatch( ndarrayFcn, t3, d3, 3, 2, 1 ); - f3( x, y, z ); // $ExpectType void | ndarray - - const t4 = [ 'float64', 'float64', 'float64', 'float64' ]; - const d4 = [ ternary ]; - const f4 = dispatch( ndarrayFcn, t4, d4, 4, 3, 1 ); - f4( x, y, z, w ); // $ExpectType void | ndarray - - const t5 = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const d5 = [ quaternary ]; - const f5 = dispatch( ndarrayFcn, t5, d5, 5, 4, 1 ); - f5( x, y, z, w, u ); // $ExpectType void | ndarray -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (1 ndarray)... -{ - const types = [ 'float64' ]; - const data = [ nullary ]; - - const f = dispatch( ndarrayFcn, types, data, 1, 0, 1 ); - f( '10' ); // $ExpectError - f( 10 ); // $ExpectError - f( true ); // $ExpectError - f( false ); // $ExpectError - f( null ); // $ExpectError - f( undefined ); // $ExpectError - f( [ '1' ] ); // $ExpectError - f( {} ); // $ExpectError - f( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( 10, y ); // $ExpectError - f( '10', y ); // $ExpectError - f( true, y ); // $ExpectError - f( false, y ); // $ExpectError - f( null, y ); // $ExpectError - f( undefined, y ); // $ExpectError - f( [ '1' ], y ); // $ExpectError - f( {}, y ); // $ExpectError - f( ( x: number ): number => x, y ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const x = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( x, 10 ); // $ExpectError - f( x, '10' ); // $ExpectError - f( x, true ); // $ExpectError - f( x, false ); // $ExpectError - f( x, null ); // $ExpectError - f( x, undefined ); // $ExpectError - f( x, [ '1' ] ); // $ExpectError - f( x, {} ); // $ExpectError - f( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( 10, y, z ); // $ExpectError - f( '10', y, z ); // $ExpectError - f( true, y, z ); // $ExpectError - f( false, y, z ); // $ExpectError - f( null, y, z ); // $ExpectError - f( undefined, y, z ); // $ExpectError - f( [ '1' ], y, z ); // $ExpectError - f( {}, y, z ); // $ExpectError - f( ( x: number ): number => x, y, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, 10, z ); // $ExpectError - f( x, '10', z ); // $ExpectError - f( x, true, z ); // $ExpectError - f( x, false, z ); // $ExpectError - f( x, null, z ); // $ExpectError - f( x, undefined, z ); // $ExpectError - f( x, [ '1' ], z ); // $ExpectError - f( x, {}, z ); // $ExpectError - f( x, ( x: number ): number => x, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, y, '10' ); // $ExpectError - f( x, y, true ); // $ExpectError - f( x, y, false ); // $ExpectError - f( x, y, null ); // $ExpectError - f( x, y, undefined ); // $ExpectError - f( x, y, [ '1' ] ); // $ExpectError - f( x, y, {} ); // $ExpectError - f( x, y, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( 10, y, z, w ); // $ExpectError - f( '10', y, z, w ); // $ExpectError - f( true, y, z, w ); // $ExpectError - f( false, y, z, w ); // $ExpectError - f( null, y, z, w ); // $ExpectError - f( undefined, y, z, w ); // $ExpectError - f( [ '1' ], y, z, w ); // $ExpectError - f( {}, y, z, w ); // $ExpectError - f( ( x: number ): number => x, y, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, 10, z, w ); // $ExpectError - f( x, '10', z, w ); // $ExpectError - f( x, true, z, w ); // $ExpectError - f( x, false, z, w ); // $ExpectError - f( x, null, z, w ); // $ExpectError - f( x, undefined, z, w ); // $ExpectError - f( x, [ '1' ], z, w ); // $ExpectError - f( x, {}, z, w ); // $ExpectError - f( x, ( x: number ): number => x, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, 10, w ); // $ExpectError - f( x, y, '10', w ); // $ExpectError - f( x, y, true, w ); // $ExpectError - f( x, y, false, w ); // $ExpectError - f( x, y, null, w ); // $ExpectError - f( x, y, undefined, w ); // $ExpectError - f( x, y, [ '1' ], w ); // $ExpectError - f( x, y, {}, w ); // $ExpectError - f( x, y, ( x: number ): number => x, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, z, 10 ); // $ExpectError - f( x, y, z, '10' ); // $ExpectError - f( x, y, z, true ); // $ExpectError - f( x, y, z, false ); // $ExpectError - f( x, y, z, null ); // $ExpectError - f( x, y, z, undefined ); // $ExpectError - f( x, y, z, [ '1' ] ); // $ExpectError - f( x, y, z, {} ); // $ExpectError - f( x, y, z, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( 10, y, z, w, u ); // $ExpectError - f( '10', y, z, w, u ); // $ExpectError - f( true, y, z, w, u ); // $ExpectError - f( false, y, z, w, u ); // $ExpectError - f( null, y, z, w, u ); // $ExpectError - f( undefined, y, z, w, u ); // $ExpectError - f( [ '1' ], y, z, w, u ); // $ExpectError - f( {}, y, z, w, u ); // $ExpectError - f( ( x: number ): number => x, y, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, 10, z, w, u ); // $ExpectError - f( x, '10', z, w, u ); // $ExpectError - f( x, true, z, w, u ); // $ExpectError - f( x, false, z, w, u ); // $ExpectError - f( x, null, z, w, u ); // $ExpectError - f( x, undefined, z, w, u ); // $ExpectError - f( x, [ '1' ], z, w, u ); // $ExpectError - f( x, {}, z, w, u ); // $ExpectError - f( x, ( x: number ): number => x, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, 10, w, u ); // $ExpectError - f( x, y, '10', w, u ); // $ExpectError - f( x, y, true, w, u ); // $ExpectError - f( x, y, false, w, u ); // $ExpectError - f( x, y, null, w, u ); // $ExpectError - f( x, y, undefined, w, u ); // $ExpectError - f( x, y, [ '1' ], w, u ); // $ExpectError - f( x, y, {}, w, u ); // $ExpectError - f( x, y, ( x: number ): number => x, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, 10, u ); // $ExpectError - f( x, y, z, '10', u ); // $ExpectError - f( x, y, z, true, u ); // $ExpectError - f( x, y, z, false, u ); // $ExpectError - f( x, y, z, null, u ); // $ExpectError - f( x, y, z, undefined, u ); // $ExpectError - f( x, y, z, [ '1' ], u ); // $ExpectError - f( x, y, z, {}, u ); // $ExpectError - f( x, y, z, ( x: number ): number => x, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fifth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, w, 10 ); // $ExpectError - f( x, y, z, w, '10' ); // $ExpectError - f( x, y, z, w, true ); // $ExpectError - f( x, y, z, w, false ); // $ExpectError - f( x, y, z, w, null ); // $ExpectError - f( x, y, z, w, undefined ); // $ExpectError - f( x, y, z, w, [ '1' ] ); // $ExpectError - f( x, y, z, w, {} ); // $ExpectError - f( x, y, z, w, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/add.js b/examples/add.js deleted file mode 100644 index 775b711..0000000 --- a/examples/add.js +++ /dev/null @@ -1,121 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var dispatch = require( './../lib' ); - -function add2( arrays ) { - var opts; - var xo; - var yo; - var zo; - var sx; - var sy; - var sz; - var sh; - var N; - var x; - var y; - var z; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - z = arrays[ 2 ]; - xo = x.order; - yo = y.order; - zo = z.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - opts.order = yo; - sy = ind2sub( sh, i, opts ); - v = x.get.apply( x, sx ) + y.get.apply( y, sy ); - - opts.order = zo; - sz = ind2sub( sh, i, opts ); - sz.push( v ); - z.set.apply( z, sz ); - } -} - -var fcns = [ - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2 -]; - -var types = [ - dtypes.float64, dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.int32, dtypes.int32, - dtypes.uint32, dtypes.uint32, dtypes.uint32, - dtypes.int16, dtypes.int16, dtypes.int16, - dtypes.uint16, dtypes.uint16, dtypes.uint16, - dtypes.int8, dtypes.int8, dtypes.int8, - dtypes.uint8, dtypes.uint8, dtypes.uint8, - dtypes.uint8c, dtypes.uint8c, dtypes.uint8c -]; - -var add = dispatch( fcns, types, null, 3, 2, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var zbuf = new Float64Array( xbuf.length ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var z = ndarray( 'float64', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); - -xbuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -ybuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -zbuf = new Int32Array( xbuf.length ); - -x = ndarray( 'int32', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'int32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -z = ndarray( 'int32', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); diff --git a/examples/sin.js b/examples/sin.js deleted file mode 100644 index 8cd4871..0000000 --- a/examples/sin.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int8Array = require( '@stdlib/array-int8' ); -var sin = require( '@stdlib/math-base-special-sin' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/strided-dtypes' ); -var dispatch = require( './../lib' ); - -function apply( arrays, fcn ) { - var opts; - var xo; - var yo; - var sx; - var sy; - var sh; - var N; - var x; - var y; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - xo = x.order; - yo = y.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - v = fcn( x.get.apply( x, sx ) ); - - opts.order = yo; - sy = ind2sub( sh, i, opts ); - sy.push( v ); - y.set.apply( y, sy ); - } -} - -var fcns = [ - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply -]; - -var types = [ - dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float64, - dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.float64, - dtypes.uint32, dtypes.float64, - dtypes.int16, dtypes.float64, - dtypes.int16, dtypes.float32, - dtypes.uint16, dtypes.float64, - dtypes.uint16, dtypes.float32, - dtypes.int8, dtypes.float64, - dtypes.int8, dtypes.float32, - dtypes.uint8, dtypes.float64, - dtypes.uint8, dtypes.float32, - dtypes.uint8c, dtypes.float64, - dtypes.uint8c, dtypes.float32 -]; - -var data = [ - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin -]; - -var sine = dispatch( fcns, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); - -xbuf = new Int8Array( [ 1, 2, 3, 4, 5 ] ); -ybuf = new Float32Array( xbuf.length ); - -x = ndarray( 'int8', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'float32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); diff --git a/examples/unary.js b/examples/unary.js deleted file mode 100644 index e9c3fb4..0000000 --- a/examples/unary.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -var unary = require( '@stdlib/ndarray-base-unary' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var dispatch = require( './../lib' ); - -var types = [ 'float64', 'float64' ]; - -var data = [ - abs -]; - -var absolute = dispatch( unary, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -absolute( x, y ); -console.log( ybuf ); -// => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 5f280a1..c49a4e4 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..61e1ca6 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@v0.1.0-esm/index.mjs";function m(e,r,t,n,i,a,s,o,u){var d,m,l,f;for(d=a,l=0;l [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( 'invalid invocation. Insufficient arguments.' );\n\t\t\t}\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n"],"names":["indexOfTypes","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","i","j","dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","out","push","resolveEnum","types2enums","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","getDType","slice"],"mappings":";;i+BA6EA,SAASA,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,KAAgBE,EAAGI,GADdE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,CACN,CACD,OAAQ,CACT,CCMA,SAASU,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,oGAAqGZ,IAEnI,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,+EAAgFX,IAE9G,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,sFAAuFV,IAErH,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,6EAA8ET,IAE5G,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,+EAAgFR,IAE9G,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,+EAAgFP,IAG9G,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAO,8IAElB,GAAKb,IAAUG,EACd,MAAM,IAAIU,MAAO,8FAElB,GAAKR,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAO,qJAIlB,GADAT,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAO,gJAGnB,GAAKd,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAO,qGAGlB,OADAf,EA5GD,SAAsBA,GACrB,IAAIkB,EACAtB,EAGJ,IADAsB,EAAM,GACAtB,EAAI,EAAGA,EAAII,EAAMgB,OAAQpB,IAC9BsB,EAAIC,KAAMC,EAAapB,EAAOJ,KAE/B,OAAOsB,CACR,CAmGSG,CAAarB,GAgBrB,WACC,IAAIsB,EACAC,EACAC,EACAC,EACAC,EACAC,EACA/B,EAGJ,IADA4B,EAAOI,UAAUZ,UACHd,EAAQ,CACrB,GAAKsB,EAAOtB,EACX,MAAM,IAAIa,MAAO,+CAElB,MAAM,IAAIA,MAAO,0CACjB,CAGD,IAFAO,EAAS,GACTC,EAAS,GACH3B,EAAI,EAAGA,EAAIM,EAAON,IAAM,CAE7B,IAAMiC,EADNH,EAAIE,UAAWhC,IAEd,MAAKA,EAAIO,EACF,IAAIO,UAAWC,EAAQ,6EAA8Ee,IAErG,IAAIhB,UAAWC,EAAQ,8EAA+Ee,IAG9GJ,EAAOH,KAAMO,GACbH,EAAOJ,KAAMC,EAAaU,EAAUJ,IACpC,CAKD,IAHAD,EAAMzC,EAAcsB,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGkB,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAIb,UAAW,+GAIrBiB,EADIpB,GAGAR,EAAM0B,GAGNxB,EACJ0B,EAAGL,EAAQrB,EAAMwB,IAEjBE,EAAGL,GAEJ,GAAc,IAATlB,EACJ,OAAOkB,EAAQjB,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOkB,EAAOS,MAAO5B,EACrB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 291641d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Create an ndarray function interface which performs multiple dispatch. -* -* @module @stdlib/ndarray-dispatch -* -* @example -* var dispatch = require( '@stdlib/ndarray-dispatch' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/index_of_types.js b/lib/index_of_types.js deleted file mode 100644 index fda2297..0000000 --- a/lib/index_of_types.js +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found). -* -* ## Notes -* -* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types). -* - The function assumes that `x` is stored in row-major order. -* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`. -* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value. -* -* @private -* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension) -* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension) -* @param {ArrayLikeObject} x - input two-dimensional reference array -* @param {integer} strideX1 - `x` stride length along first dimension -* @param {integer} strideX2 - `x` stride length along second dimension -* @param {NonNegativeInteger} offsetX - `x` starting index -* @param {ArrayLikeObject} y - search array -* @param {integer} strideY - `y` stride length -* @param {NonNegativeInteger} offsetY - `y` starting index -* @returns {integer} row index (if found) and `-1` otherwise -* -* @example -* // Define a reference array to search: -* var types = [ -* 'float64', 'float64', 'float64', -* 'float32', 'float32', 'float32', -* 'uint32', 'uint32', 'float64', -* 'int32', 'int32', 'float64', -* 'uint16', 'uint16', 'float64', -* 'int16', 'int16', 'float64', -* 'uint8', 'uint8', 'float64', -* 'int8', 'int8', 'float64' -* ]; -* -* // Define reference array dimensions: -* var N = 8; // rows -* var M = 3; // columns -* -* // Define a search array: -* y1 = [ -* 'float32', 'float32', 'float32', -* ]; -* -* // Find the list of types: -* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 ); -* // returns 1 -* -// Define a search array: -* y2 = [ -* 'float32', 'float32', 'float64', -* ]; -* -* // Find the list of types: -* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 ); -* // returns -1 -*/ -function indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len - var ix; - var iy; - var i; - var j; - - // Search for the first row which matches `y`... - ix = offsetX; - for ( i = 0; i < N; i++ ) { - iy = offsetY; - for ( j = 0; j < M; j++ ) { - if ( x[ ix+(j*strideX2) ] !== y[ iy ] ) { - break; - } - iy += strideY; - } - // If we successfully iterated over all columns, then that means we've found a match... - if ( j === M ) { - return i; - } - ix += strideX1; - } - return -1; -} - - -// EXPORTS // - -module.exports = indexOfTypes; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 5f4bb5d..0000000 --- a/lib/main.js +++ /dev/null @@ -1,231 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isFunctionArray = require( '@stdlib/assert-is-function-array' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/string-format' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var resolveEnum = require( '@stdlib/ndarray-base-dtype-resolve-enum' ); -var indexOfTypes = require( './index_of_types.js' ); - - -// FUNCTIONS // - -/** -* Returns a list of data type enumeration constants. -* -* @private -* @param {Collection} types - list of types -* @returns {IntegerArray} list of data type enumeration constants -*/ -function types2enums( types ) { - var out; - var i; - - out = []; - for ( i = 0; i < types.length; i++ ) { - out.push( resolveEnum( types[ i ] ) ); - } - return out; -} - - -// MAIN // - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param {(FunctionArray|Function)} fcns - list of ndarray functions -* @param {Collection} types - one-dimensional list of ndarray argument data types -* @param {(Collection|null)} data - ndarray function data (e.g., callbacks) -* @param {PositiveInteger} nargs - total number of ndarray function interface arguments -* @param {NonNegativeInteger} nin - number of input ndarrays -* @param {NonNegativeInteger} nout - number of output ndarrays -* @throws {TypeError} first argument must be either a function or an array of functions -* @throws {TypeError} second argument must be an array-like object -* @throws {TypeError} third argument must be an array-like object or `null` -* @throws {Error} third and first arguments must have the same number of elements -* @throws {TypeError} fourth argument must be a positive integer -* @throws {TypeError} fifth argument must be a nonnegative integer -* @throws {TypeError} sixth argument must be a nonnegative integer -* @throws {Error} fourth argument must equal the specified number of input and output arrays -* @throws {Error} number of types must match the number of functions times the total number of array arguments for each function -* @throws {Error} interface must accept at least one input and/or output ndarray -* @returns {Function} ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function dispatch( fcns, types, data, nargs, nin, nout ) { - var narrays; - var nfcns; - var fcn; - - if ( isFunction( fcns ) ) { - fcn = fcns; - } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) ); - } - if ( !isCollection( types ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) ); - } - if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); - } - if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) ); - } - if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) ); - } - if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) ); - } - narrays = nin + nout; - if ( narrays === 0 ) { - throw new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' ); - } - if ( nargs !== narrays ) { - throw new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' ); - } - if ( fcn ) { - nfcns = types.length / narrays; - if ( !isInteger( nfcns ) ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); - } - } else { - nfcns = fcns.length; - if ( types.length !== nfcns*narrays ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); - } - } - if ( data && data.length !== nfcns ) { - throw new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' ); - } - types = types2enums( types ); - return dispatcher; - - /** - * ndarray function interface which performs multiple dispatch. - * - * @private - * @param {ndarrayLike} x - ndarray - * @param {...ndarrayLike} args - ndarray arguments - * @throws {Error} insufficient arguments - * @throws {Error} too many arguments - * @throws {TypeError} input array arguments must be ndarray-like objects - * @throws {TypeError} output array arguments must be ndarray-like objects - * @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types - * @returns {(ndarrayLike|Array|void)} destination array(s) - */ - function dispatcher() { - var arrays; - var dtypes; - var argc; - var idx; - var v; - var f; - var i; - - argc = arguments.length; - if ( argc !== nargs ) { - if ( argc < nargs ) { - throw new Error( 'invalid invocation. Insufficient arguments.' ); - } - throw new Error( 'invalid invocation. Too many arguments.' ); - } - arrays = []; - dtypes = []; - for ( i = 0; i < nargs; i++ ) { - v = arguments[ i ]; - if ( !isndarrayLike( v ) ) { - if ( i < nin ) { - throw new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) ); - } else { - throw new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) ); - } - } - arrays.push( v ); - dtypes.push( resolveEnum( getDType( v ) ) ); - } - // Resolve the ndarray function satisfying the input array types: - idx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len - - // Check whether we were able to successfully resolve an ndarray function: - if ( idx < 0 ) { - throw new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' ); - } - // Retrieve the ndarray function: - if ( fcn ) { - f = fcn; - } else { - f = fcns[ idx ]; - } - // Evaluate the ndarray function: - if ( data ) { - f( arrays, data[ idx ] ); - } else { - f( arrays ); - } - if ( nout === 1 ) { - return arrays[ narrays-1 ]; - } - if ( nout === 0 ) { - return; - } - return arrays.slice( nin ); - } -} - - -// EXPORTS // - -module.exports = dispatch; diff --git a/package.json b/package.json index 5e6762c..06365f4 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Create an ndarray function interface which performs multiple dispatch.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-collection": "^0.1.0", - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/assert-is-function-array": "^0.1.0", - "@stdlib/assert-is-integer": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/assert-is-nonnegative-integer": "^0.1.0", - "@stdlib/assert-is-positive-integer": "^0.1.0", - "@stdlib/ndarray-base-dtype-resolve-enum": "^0.1.0", - "@stdlib/ndarray-dtype": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.1.1", - "@stdlib/array-float64": "^0.1.1", - "@stdlib/array-int32": "^0.1.1", - "@stdlib/array-int8": "^0.1.1", - "@stdlib/array-uint8": "^0.1.1", - "@stdlib/math-base-assert-is-nan": "^0.1.1", - "@stdlib/math-base-special-abs": "^0.1.1", - "@stdlib/math-base-special-pow": "^0.1.0", - "@stdlib/math-base-special-sin": "^0.1.0", - "@stdlib/ndarray-base-buffer-dtype": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-unary": "^0.1.0", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-dtypes": "^0.1.0", - "@stdlib/ndarray-ind2sub": "^0.1.1", - "@stdlib/strided-dtypes": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "ndarray", @@ -99,7 +26,6 @@ "multimethod", "multimethods" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..078ff81 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/fixtures/binary.js b/test/fixtures/binary.js deleted file mode 100644 index a60dfa2..0000000 --- a/test/fixtures/binary.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Binary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @returns {number} sum -*/ -function binary( x, y ) { - return x + y; -} - - -// EXPORTS // - -module.exports = binary; diff --git a/test/fixtures/fill.js b/test/fixtures/fill.js deleted file mode 100644 index 41b2958..0000000 --- a/test/fixtures/fill.js +++ /dev/null @@ -1,76 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which fills one or more ndarrays. -* -* @private -* @param {*} value - fill value -* @returns {Function} ndarray function -*/ -function fill( value ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - */ - function ndarrayFcn( arrays ) { - var opts; - var sub; - var arr; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - opts = { - 'order': '' - }; - for ( j = 0; j < M; j++ ) { - arr = arrays[ j ]; - opts.order = arrays[ j ].order; - for ( i = 0; i < N; i++ ) { - sub = ind2sub( sh, i, opts ); - sub.push( value ); - arr.set.apply( arr, sub ); - } - } - } -} - - -// EXPORTS // - -module.exports = fill; diff --git a/test/fixtures/foreach.js b/test/fixtures/foreach.js deleted file mode 100644 index a426290..0000000 --- a/test/fixtures/foreach.js +++ /dev/null @@ -1,72 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function forEach( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - fcn.apply( null, args ); - } -} - - -// EXPORTS // - -module.exports = forEach; diff --git a/test/fixtures/map1n.js b/test/fixtures/map1n.js deleted file mode 100644 index 614196b..0000000 --- a/test/fixtures/map1n.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function which maps the return value of a callback to `N` arrays. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function map1N( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var v; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - v = fcn(); - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - sub.push( v ); - arrays[ j ].set.apply( arrays[ j ], sub ); - } - } -} - - -// EXPORTS // - -module.exports = map1N; diff --git a/test/fixtures/nullary.js b/test/fixtures/nullary.js deleted file mode 100644 index 4f22126..0000000 --- a/test/fixtures/nullary.js +++ /dev/null @@ -1,36 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Nullary callback. -* -* @private -* @returns {number} value -*/ -function nullary() { - return 3.0; -} - - -// EXPORTS // - -module.exports = nullary; diff --git a/test/fixtures/quaternary.js b/test/fixtures/quaternary.js deleted file mode 100644 index 548437b..0000000 --- a/test/fixtures/quaternary.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quaternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @returns {number} sum -*/ -function quaternary( x, y, z, w ) { - return x + y + z + w; -} - - -// EXPORTS // - -module.exports = quaternary; diff --git a/test/fixtures/quinary.js b/test/fixtures/quinary.js deleted file mode 100644 index 36068de..0000000 --- a/test/fixtures/quinary.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quinary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @param {number} u - input value -* @returns {number} sum -*/ -function quinary( x, y, z, w, u ) { - return x + y + z + w + u; -} - - -// EXPORTS // - -module.exports = quinary; diff --git a/test/fixtures/sum.js b/test/fixtures/sum.js deleted file mode 100644 index efdbb1b..0000000 --- a/test/fixtures/sum.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which computes the sum across one or more ndarrays. -* -* @private -* @param {Object} ctx - context -* @param {number} ctx.sum - initial sum -* @returns {Function} ndarray function -*/ -function wrapper( ctx ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - * @param {Function} [fcn] - callback - */ - function ndarrayFcn( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var f; - var i; - var j; - - if ( arguments.length > 1 ) { - f = fcn; - } - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - if ( f ) { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - ctx.sum += f.apply( null, args ); - } - } else { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - ctx.sum += arrays[ j ].get.apply( arrays[ j ], sub ); - } - } - } - } -} - - -// EXPORTS // - -module.exports = wrapper; diff --git a/test/fixtures/ternary.js b/test/fixtures/ternary.js deleted file mode 100644 index 0595d5f..0000000 --- a/test/fixtures/ternary.js +++ /dev/null @@ -1,39 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Ternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @returns {number} sum -*/ -function ternary( x, y, z ) { - return x + y + z; -} - - -// EXPORTS // - -module.exports = ternary; diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d6c2c8e..0000000 --- a/test/test.js +++ /dev/null @@ -1,363 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var fill = require( './fixtures/fill.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either a function or an array of functions as a first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( value, types, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object as a second argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided either an array-like object or `null` as a third argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - dispatch( unary, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a positive integer for a fourth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 0, - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a fifth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, value, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a sixth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, 1, value ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function array)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var fcns = [ unary, unary, unary ]; - var data = [ abs, abs, abs ]; - dispatch( fcns, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function argument)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs, abs, abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the length of `data` argument does not match the number of ndarray functions', function test( t ) { - var values; - var i; - - values = [ - [], - [ abs, abs ], - [ abs, abs, abs ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var fcns = [ unary ]; - dispatch( fcns, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the fourth argument is incompatible with the number of input and output ndarrays', function test( t ) { - var values; - var i; - - values = [ - 0, - 1, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of specified input and output ndarrays is zero', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var types = [ 'float64' ]; - dispatch( fill( 3 ), types, null, 1, 0, 0 ); - } -}); - -tape( 'the function returns an ndarray function interface', function test( t ) { - var types; - var data; - var f; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - f = dispatch( unary, types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ unary ], types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( fill( 3 ), types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ fill( 3 ) ], types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.two_arrays.js b/test/test.two_arrays.js deleted file mode 100644 index 16eb61b..0000000 --- a/test/test.two_arrays.js +++ /dev/null @@ -1,814 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var dtype = require( '@stdlib/ndarray-base-buffer-dtype' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var forEach = require( './fixtures/foreach.js' ); -var map1N = require( './fixtures/map1n.js' ); -var fill = require( './fixtures/fill.js' ); -var sum = require( './fixtures/sum.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the first argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var ybuf = new Float64Array( 10 ); - var y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( value, y ); - }; - } -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the second argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var xbuf = new Float64Array( 10 ); - var x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( x, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided insufficient arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var f; - var x; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [], - [ x ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided too many arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var ybuf; - var f; - var x; - var y; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [ x, y, y ], - [ x, y, y, y ], - [ x, y, y, y, y ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if unable to resolve a ndarray function supporting the provided array argument data types', function test( t ) { - var values; - var types; - var data; - var xbuf; - var fcn; - var x; - var i; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ abs, abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 4 ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - values = [ - new Uint8Array( 4 ), - new Int32Array( 4 ), - [ 0, 0, 0, 0 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided an array having data type: ' + dtype( values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var y = ndarray( dtype( value ), value, [ value.length ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - }; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only input arrays)', function test( t ) { - var types; - var xbuf; - var ybuf; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only output arrays)', function test( t ) { - var expected; - var types; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only input arrays)', function test( t ) { - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var ctx; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcns = [ - sum( ctx ), - sum( ctx ) - ]; - fcn = dispatch( fcns, types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only output arrays)', function test( t ) { - var expected; - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcns = [ - fill( 3.0 ), - fill( 4.0 ) - ]; - fcn = dispatch( fcns, types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - - fcn = dispatch( forEach, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - - fcn = dispatch( map1N, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - fcns = [ - forEach, - forEach - ]; - fcn = dispatch( fcns, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - fcns = [ - map1N, - map1N - ]; - fcn = dispatch( fcns, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - fcns = [ - unary, - unary - ]; - fcn = dispatch( fcns, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which returns one or more output arrays, if one or more output arrays is specified, and otherwise returns `undefined`', function test( t ) { - var types; - var data; - var xbuf; - var ybuf; - var out; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - // No output arrays... - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, void 0, 'returns expected value' ); - - // One output array... - data = [ - abs, - abs - ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - fcn = dispatch( fill( 3.0 ), types, null, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - // Two output arrays... - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.end(); -}); From 764772b9a995b515e20fd96bb88cc9751312f3e9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 09:05:49 +0000 Subject: [PATCH 056/109] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9fbece1..5e6762c 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/assert-is-positive-integer": "^0.1.0", "@stdlib/ndarray-base-dtype-resolve-enum": "^0.1.0", "@stdlib/ndarray-dtype": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0" }, "devDependencies": { From aec0422bd8807cabed9d78ec679962bce6d92406 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 14:26:25 +0000 Subject: [PATCH 057/109] Remove files --- index.d.ts | 334 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6516 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index c49a4e4..0000000 --- a/index.d.ts +++ /dev/null @@ -1,334 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* ndarray function. -* -* @param arrays - array containing input and output ndarrays -* @param data - ndarray function data (e.g., a callback) -* -* @example -* var numel = require( '@stdlib/ndarray-base-numel' ); -* var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -* -* function ndarrayFcn( arrays, fcn ) { -* var xord; -* var yord; -* var opts; -* var sub; -* var sh; -* var N; -* var x; -* var y; -* var v; -* var i; -* -* x = arrays[ 0 ]; -* y = arrays[ 1 ]; -* sh = x.shape; -* N = numel( sh ); -* if ( N <= 0 ) { -* return; -* } -* xord = x.order; -* yord = y.order; -* opts = {}; -* opts.order = xord; -* for ( i = 0; i < N; i++ ) { -* // Convert a linear index to subscripts: -* opts.order = xord; -* sub = ind2sub( sh, i, opts ); -* -* // Retrieve an element from `x`: -* v = x.get.apply( x, sub ); -* -* // Convert a linear index to subscripts: -* opts.order = yord; -* sub = ind2sub( sh, i, opts ); -* -* // Append the result of applying the callback: -* sub.push( fcn( v ) ); -* -* // Assign the result to an element in `y`: -* y.set.apply( y, sub ); -* } -* } -*/ -type ndarrayFcn = ( arrays: Array, data?: any ) => void; - -/** -* Interface describing an ndarray function dispatcher. -*/ -interface Dispatcher { - /** - * Invokes an ndarray function based on the provided array data type(s). - * - * @param x - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array - * - * @example - * var nullary = require( '@stdlib/ndarray-base-nullary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function value() { - * return 3.14; - * } - * - * var types = [ 'float64' ]; - * var data = [ value ]; - * - * var fcn = dispatch( nullary, types, data, 1, 0, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( 5 ); - * var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x ); - * // xbuf => [ 3.14, 3.14, 3.14, 3.14, 3.14 ] - */ - ( x: ndarray ): ndarray | void; - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var unary = require( '@stdlib/ndarray-base-unary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * var abs = require( '@stdlib/math-base-special-abs' ); - * - * var types = [ 'float64', 'float64' ]; - * var data = [ abs ]; - * - * var fcn = dispatch( unary, types, data, 2, 1, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - * var ybuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y ); - * // ybuf => [ 1.0, 2.0, 3.0 ] - */ - ( x: ndarray, y: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var ternary = require( '@stdlib/ndarray-base-ternary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function add2( x, y ) { - * return x + y; - * } - * - * var types = [ 'float64', 'float64', 'float64' ]; - * var data = [ add2 ]; - * - * var fcn = dispatch( ternary, types, data, 3, 2, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z ); - * // zbuf => [ 2.0, 4.0, 6.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quaternary = require( '@stdlib/ndarray-base-quaternary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function add3( x, y, z ) { - * return x + y + z; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add3 ]; - * - * var fcn = dispatch( quaternary, types, data, 4, 3, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w ); - * // wbuf => [ 3.0, 6.0, 9.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @param args - ndarray arguments - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quinary = require( '@stdlib/ndarray-base-quinary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function add4( x, y, z, w ) { - * return x + y + z + w; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add4 ]; - * - * var fcn = dispatch( quinary, types, data, 5, 4, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ubuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var u = ndarray( 'float64', ubuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w, u ); - * // ubuf => [ 4.0, 8.0, 12.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray, ...args: Array ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures -} - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param fcns - list of ndarray functions -* @param types - one-dimensional list of ndarray argument data types -* @param data - ndarray function data (e.g., callbacks) -* @param nargs - total number of ndarray function interface arguments -* @param nin - number of input ndarrays -* @param nout - number of output ndarrays -* @throws first argument must be either a function or an array of functions -* @throws second argument must be an array-like object -* @throws third argument must be an array-like object or `null` -* @throws third and first arguments must have the same number of elements -* @throws fourth argument must be a positive integer -* @throws fifth argument must be a nonnegative integer -* @throws sixth argument must be a nonnegative integer -* @throws fourth argument must equal the specified number of input and output arrays -* @throws number of types must match the number of functions times the total number of array arguments for each function -* @throws interface must accept at least one input and/or output ndarray -* @returns ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var fcn = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* fcn( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function dispatch( fcns: ndarrayFcn | ArrayLike, types: ArrayLike, data: ArrayLike | null, nargs: number, nin: number, nout: number ): Dispatcher; - - -// EXPORTS // - -export = dispatch; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 61e1ca6..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@v0.1.0-esm/index.mjs";function m(e,r,t,n,i,a,s,o,u){var d,m,l,f;for(d=a,l=0;l [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( 'invalid invocation. Insufficient arguments.' );\n\t\t\t}\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n"],"names":["indexOfTypes","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","i","j","dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","out","push","resolveEnum","types2enums","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","getDType","slice"],"mappings":";;i+BA6EA,SAASA,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,KAAgBE,EAAGI,GADdE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,CACN,CACD,OAAQ,CACT,CCMA,SAASU,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,oGAAqGZ,IAEnI,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,+EAAgFX,IAE9G,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,sFAAuFV,IAErH,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,6EAA8ET,IAE5G,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,+EAAgFR,IAE9G,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,+EAAgFP,IAG9G,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAO,8IAElB,GAAKb,IAAUG,EACd,MAAM,IAAIU,MAAO,8FAElB,GAAKR,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAO,qJAIlB,GADAT,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAO,gJAGnB,GAAKd,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAO,qGAGlB,OADAf,EA5GD,SAAsBA,GACrB,IAAIkB,EACAtB,EAGJ,IADAsB,EAAM,GACAtB,EAAI,EAAGA,EAAII,EAAMgB,OAAQpB,IAC9BsB,EAAIC,KAAMC,EAAapB,EAAOJ,KAE/B,OAAOsB,CACR,CAmGSG,CAAarB,GAgBrB,WACC,IAAIsB,EACAC,EACAC,EACAC,EACAC,EACAC,EACA/B,EAGJ,IADA4B,EAAOI,UAAUZ,UACHd,EAAQ,CACrB,GAAKsB,EAAOtB,EACX,MAAM,IAAIa,MAAO,+CAElB,MAAM,IAAIA,MAAO,0CACjB,CAGD,IAFAO,EAAS,GACTC,EAAS,GACH3B,EAAI,EAAGA,EAAIM,EAAON,IAAM,CAE7B,IAAMiC,EADNH,EAAIE,UAAWhC,IAEd,MAAKA,EAAIO,EACF,IAAIO,UAAWC,EAAQ,6EAA8Ee,IAErG,IAAIhB,UAAWC,EAAQ,8EAA+Ee,IAG9GJ,EAAOH,KAAMO,GACbH,EAAOJ,KAAMC,EAAaU,EAAUJ,IACpC,CAKD,IAHAD,EAAMzC,EAAcsB,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGkB,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAIb,UAAW,+GAIrBiB,EADIpB,GAGAR,EAAM0B,GAGNxB,EACJ0B,EAAGL,EAAQrB,EAAMwB,IAEjBE,EAAGL,GAEJ,GAAc,IAATlB,EACJ,OAAOkB,EAAQjB,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOkB,EAAOS,MAAO5B,EACrB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 078ff81..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 89bbf95682066b8253f6bd0aa5b1814a96975478 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Feb 2024 14:26:51 +0000 Subject: [PATCH 058/109] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 61 +- SECURITY.md | 5 - benchmark/benchmark.dispatch_size.js | 156 - benchmark/benchmark.js | 81 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 87 - docs/types/test.ts | 641 --- examples/add.js | 121 - examples/sin.js | 142 - examples/unary.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/index_of_types.js | 106 - lib/main.js | 231 - package.json | 78 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/binary.js | 38 - test/fixtures/fill.js | 76 - test/fixtures/foreach.js | 72 - test/fixtures/map1n.js | 74 - test/fixtures/nullary.js | 36 - test/fixtures/quaternary.js | 40 - test/fixtures/quinary.js | 41 - test/fixtures/sum.js | 98 - test/fixtures/ternary.js | 39 - test/test.js | 363 -- test/test.two_arrays.js | 814 --- 57 files changed, 6211 insertions(+), 6748 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.dispatch_size.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/add.js delete mode 100644 examples/sin.js delete mode 100644 examples/unary.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/index_of_types.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/fixtures/binary.js delete mode 100644 test/fixtures/fill.js delete mode 100644 test/fixtures/foreach.js delete mode 100644 test/fixtures/map1n.js delete mode 100644 test/fixtures/nullary.js delete mode 100644 test/fixtures/quaternary.js delete mode 100644 test/fixtures/quinary.js delete mode 100644 test/fixtures/sum.js delete mode 100644 test/fixtures/ternary.js delete mode 100644 test/test.js delete mode 100644 test/test.two_arrays.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 5d2e826..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-02-01T06:22:27.093Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ac0b7cd..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 30656c4..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 5e92c3e..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c92f5c4..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index d53fd56..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '43 7 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index e1e3539..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -304,7 +295,7 @@ console.log( ybuf ); ## 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. +This package is part of [stdlib][stdlib], a standard library 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]. @@ -367,11 +358,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-dispatch/main/LICENSE -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.dispatch_size.js b/benchmark/benchmark.dispatch_size.js deleted file mode 100644 index 15805ba..0000000 --- a/benchmark/benchmark.dispatch_size.js +++ /dev/null @@ -1,156 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib/main.js' ); - - -// FUNCTIONS // - -/** -* Evaluates the identity function. -* -* @private -* @param {*} v - value -* @returns {*} input value -*/ -function identity( v ) { - return v; -} - -/** -* Dummy function which throws an error. -* -* @private -* @throws {Error} unexpected error -*/ -function throwError() { - throw new Error( 'unexpected error' ); -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} size - dispatch size -* @returns {Function} benchmark function -*/ -function createBenchmark( size ) { - var types; - var data; - var fcn; - var x; - var y; - var t; - var i; - - types = []; - - // Create dummy types... - for ( i = 0; i < (size-1)*2; i += 2 ) { - t = 'foo' + i; - types.push( t ); - types.push( t ); - } - // Append test types: - types.push( 'float64' ); - types.push( 'float64' ); - - // Define a list of callbacks: - data = []; - for ( i = 0; i < size-1; i++ ) { - data.push( throwError ); - } - // Append a test callback: - data.push( identity ); - - // Create the dispatcher: - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - // Create sample arrays: - x = new Float64Array( 1 ); - y = new Float64Array( x.length ); - - x = ndarray( 'float64', x, [ 1 ], [ 1 ], 0, 'row-major' ); - y = ndarray( 'float64', y, [ 1 ], [ 1 ], 0, 'row-major' ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var z; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x.data[ 0 ] = i; - z = fcn( x, y ); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var size; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - size = pow( 2, i ); - f = createBenchmark( size ); - bench( pkg+':size='+size, f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 3c6f450..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::fcns_array', function benchmark( b ) { - var types; - var fcns; - var data; - var out; - var i; - - fcns = [ unary ]; - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( fcns, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::fcn_arg', function benchmark( b ) { - var types; - var data; - var out; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( unary, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0aae4af..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch" -%% click B href "https://github.com/stdlib-js/ndarray-dispatch/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-dispatch/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-dispatch/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-dispatch/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-dispatch/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch -[production-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 1295a44..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import dispatch from '../docs/types/index'; -export = dispatch; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7fb29cb..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var y=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var b=y(function(D,w){ -function k(i,r,e,u,f,m,n,o,l){var h,t,s,a;for(h=m,s=0;s [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( 'invalid invocation. Insufficient arguments.' );\n\t\t\t}\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = dispatch;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an ndarray function interface which performs multiple dispatch.\n*\n* @module @stdlib/ndarray-dispatch\n*\n* @example\n* var dispatch = require( '@stdlib/ndarray-dispatch' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var unary = require( '@stdlib/ndarray-base-unary' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var types = [\n* 'float64', 'float64'\n* ];\n*\n* var data = [\n* abs\n* ];\n*\n* var absolute = dispatch( unary, types, data, 2, 1, 1 );\n*\n* // ...\n*\n* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] );\n* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] );\n*\n* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' );\n* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' );\n*\n* absolute( x, y );\n* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA6EA,SAASC,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,EAAU,CAClF,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,CAAU,IAAME,EAAGI,CAAG,EADjBE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,CACP,CACA,MAAO,EACR,CAKAL,EAAO,QAAUC,ICzGjB,IAAAc,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAoB,QAAS,oCAAqC,EAClEC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAkB,QAAS,kCAAmC,EAC9DC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAc,QAAS,yCAA0C,EACjEC,EAAe,IAYnB,SAASC,EAAaC,EAAQ,CAC7B,IAAIC,EACAC,EAGJ,IADAD,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIF,EAAM,OAAQE,IAC9BD,EAAI,KAAMJ,EAAaG,EAAOE,CAAE,CAAE,CAAE,EAErC,OAAOD,CACR,CAqDA,SAASE,EAAUC,EAAMJ,EAAOK,EAAMC,EAAOC,EAAKC,EAAO,CACxD,IAAIC,EACAC,EACAC,EAEJ,GAAKnB,EAAYY,CAAK,EACrBO,EAAMP,UACK,CAACb,EAAiBa,CAAK,EAClC,MAAM,IAAI,UAAWT,EAAQ,oGAAqGS,CAAK,CAAE,EAE1I,GAAK,CAACX,EAAcO,CAAM,EACzB,MAAM,IAAI,UAAWL,EAAQ,+EAAgFK,CAAM,CAAE,EAEtH,GAAK,CAACP,EAAcY,CAAK,GAAKA,IAAS,KACtC,MAAM,IAAI,UAAWV,EAAQ,sFAAuFU,CAAK,CAAE,EAE5H,GAAK,CAAChB,EAAmBiB,CAAM,EAC9B,MAAM,IAAI,UAAWX,EAAQ,6EAA8EW,CAAM,CAAE,EAEpH,GAAK,CAAClB,EAAsBmB,CAAI,EAC/B,MAAM,IAAI,UAAWZ,EAAQ,+EAAgFY,CAAI,CAAE,EAEpH,GAAK,CAACnB,EAAsBoB,CAAK,EAChC,MAAM,IAAI,UAAWb,EAAQ,+EAAgFa,CAAK,CAAE,EAGrH,GADAC,EAAUF,EAAMC,EACXC,IAAY,EAChB,MAAM,IAAI,MAAO,4IAA6I,EAE/J,GAAKH,IAAUG,EACd,MAAM,IAAI,MAAO,4FAA6F,EAE/G,GAAKE,GAEJ,GADAD,EAAQV,EAAM,OAASS,EAClB,CAACnB,EAAWoB,CAAM,EACtB,MAAM,IAAI,MAAO,8IAA+I,UAGjKA,EAAQN,EAAK,OACRJ,EAAM,SAAWU,EAAMD,EAC3B,MAAM,IAAI,MAAO,8IAA+I,EAGlK,GAAKJ,GAAQA,EAAK,SAAWK,EAC5B,MAAM,IAAI,MAAO,mGAAoG,EAEtH,OAAAV,EAAQD,EAAaC,CAAM,EACpBY,EAeP,SAASA,GAAa,CACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EAGJ,GADAa,EAAO,UAAU,OACZA,IAAST,EACb,MAAKS,EAAOT,EACL,IAAI,MAAO,6CAA8C,EAE1D,IAAI,MAAO,yCAA0C,EAI5D,IAFAO,EAAS,CAAC,EACVC,EAAS,CAAC,EACJZ,EAAI,EAAGA,EAAII,EAAOJ,IAAM,CAE7B,GADAe,EAAI,UAAWf,CAAE,EACZ,CAACR,EAAeuB,CAAE,EACtB,MAAKf,EAAIK,EACF,IAAI,UAAWZ,EAAQ,6EAA8EsB,CAAE,CAAE,EAEzG,IAAI,UAAWtB,EAAQ,8EAA+EsB,CAAE,CAAE,EAGlHJ,EAAO,KAAMI,CAAE,EACfH,EAAO,KAAMjB,EAAaD,EAAUqB,CAAE,CAAE,CAAE,CAC3C,CAKA,GAHAD,EAAMlB,EAAcY,EAAOD,EAAST,EAAOS,EAAS,EAAG,EAAGK,EAAQ,EAAG,CAAE,EAGlEE,EAAM,EACV,MAAM,IAAI,UAAW,6GAA8G,EAcpI,GAXKL,EACJO,EAAIP,EAEJO,EAAId,EAAMY,CAAI,EAGVX,EACJa,EAAGL,EAAQR,EAAMW,CAAI,CAAE,EAEvBE,EAAGL,CAAO,EAENL,IAAS,EACb,OAAOK,EAAQJ,EAAQ,CAAE,EAE1B,GAAKD,IAAS,EAGd,OAAOK,EAAO,MAAON,CAAI,CAC1B,CACD,CAKApB,EAAO,QAAUgB,IC9KjB,IAAIgB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_index_of_types", "__commonJSMin", "exports", "module", "indexOfTypes", "N", "M", "x", "strideX1", "strideX2", "offsetX", "y", "strideY", "offsetY", "ix", "iy", "i", "j", "require_main", "__commonJSMin", "exports", "module", "isNonNegativeInteger", "isPositiveInteger", "isInteger", "isFunctionArray", "isFunction", "isCollection", "isndarrayLike", "format", "getDType", "resolveEnum", "indexOfTypes", "types2enums", "types", "out", "i", "dispatch", "fcns", "data", "nargs", "nin", "nout", "narrays", "nfcns", "fcn", "dispatcher", "arrays", "dtypes", "argc", "idx", "v", "f", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 02fe150..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,87 +0,0 @@ - -{{alias}}( fcns, types, data, nargs, nin, nout ) - Returns an ndarray function interface which performs multiple dispatch. - - An ndarray function interface has the following signature: - - f( x, y, ... ) - - where - - - x: ndarray. - - y: ndarray. - - ...: additional ndarrays. - - The number of parameters is derived from `nargs`, the number of input - ndarrays is derived from `nin`, and the number of output ndarrays is derived - from `nout`. - - Parameters - ---------- - fcns: Function|ArrayLikeObject - List of ndarray functions. An ndarray function should have the following - signature: - - f( arrays, data ) - - where - - - arrays: array containing input and output ndarrays. - - data: ndarray function data (e.g., a callback). - - For convenience, a single ndarray function may be provided which will be - invoked whenever the ndarray argument data types match a sequence of - types in `types`. Providing a single ndarray function is particularly - convenient for the case where, regardless of array data types, - traversing arrays remains the same, but the ndarray function `data` - differs (e.g., callbacks which differ based on the array data types). - - types: ArrayLikeObject - One-dimensional list of ndarray argument data types. - - data: ArrayLikeObject|null - ndarray function data (e.g., callbacks). If `null`, a returned ndarray - function interface does **not** provide a `data` argument to an invoked - ndarray function. - - nargs: integer - Total number of ndarray function interface arguments. - - nin: integer - Number of input ndarrays. - - nout: integer - Number of output ndarrays. - - Returns - ------- - fcn: Function - ndarray function interface. - - Examples - -------- - // Define ndarray argument data types: - > var t = [ 'float64', 'float64', 'float32', 'float32' ]; - - // Define a list of ndarray function data (callbacks): - > var d = [ {{alias:@stdlib/math/base/special/abs}}, {{alias:@stdlib/math/base/special/absf}} ]; - - // Create an ndarray function interface for applying unary callbacks: - > var f = {{alias}}( {{alias:@stdlib/ndarray/base/unary}}, t, d, 2, 1, 1 ); - - // Create an input ndarray: - > var xbuf = new {{alias:@stdlib/array/float64}}( [ -1.0, -2.0, -3.0, -4.0 ] ); - > var x = {{alias:@stdlib/ndarray/ctor}}( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Create an output ndarray: - > var ybuf = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 0.0, 0.0 ] ); - > var y = {{alias:@stdlib/ndarray/ctor}}( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Compute the element-wise absolute value: - > f( x, y ); - > ybuf - [ 1.0, 2.0, 3.0, 4.0 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 3cba031..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,641 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable max-lines */ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import dispatch = require( './index' ); - - -// FUNCTIONS // - -/** -* Nullary callback. -* -* @return input value -*/ -function nullary(): any { - return 5.0; -} - -/** -* Unary callback. -* -* @param x - input value -* @return input value -*/ -function unary( x: any ): any { - return x; -} - -/** -* Binary callback. -* -* @param x - input value -* @param y - input value -* @return output value -*/ -function binary( x: number, y: number ): number { - return x + y; -} - -/** -* Ternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @return output value -*/ -function ternary( x: number, y: number, z: number ): number { - return x + y + z; -} - -/** -* Quaternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @param w - input value -* @return output value -*/ -function quaternary( x: number, y: number, z: number, w: number ): number { - return x + y + z + w; -} - -/** -* Mock `ind2sub` function. -* -* @param shape - dimensions -* @param idx - linear index -* @param opts - options -* @return subscripts -*/ -function ind2sub( shape: ArrayLike, idx: number, opts?: any ): Array { - let out; - let i; - - out = []; - if ( typeof opts === 'object' && opts !== null && opts.order === 'row-major' ) { no-unsafe-any - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } else { - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } - return out; -} - -/** -* Mock ndarray function. -* -* @param arrays - ndarrays -* @param fcn - callback -*/ -function ndarrayFcn( arrays: Array, fcn: ( x: any ) => any ): void { - let xord; - let yord; - let opts; - let sub; - let sh; - let N; - let x; - let y; - let v; - let i; - - x = arrays[ 0 ]; - y = arrays[ 1 ]; - sh = x.shape; - if ( sh.length === 0 ) { - return; - } - N = 1; - for ( i = 0; i < sh.length; i += 1 ) { - N *= sh[ i ]; - } - xord = x.order; - yord = y.order; - opts = { - 'order': '' - }; - opts.order = xord; - for ( i = 0; i < N; i += 1 ) { - // Convert a linear index to subscripts: - opts.order = xord; - sub = ind2sub( sh, i, opts ); - - // Retrieve an element from `x`: - v = x.get.apply( x, sub ); - - // Convert a linear index to subscripts: - opts.order = yord; - sub = ind2sub( sh, i, opts ); - - // Append the result of applying the callback: - sub[ sub.length ] = fcn( v ) as number; - - // Assign the result to an element in `y`: - y.set.apply( y, sub ); - } -} - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a dispatch function... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, 1 ); // $ExpectType Dispatcher - dispatch( [ ndarrayFcn ], types, data, 2, 1, 1 ); // $ExpectType Dispatcher -} - -// The compiler throws an error if the function is provided a first argument which is not either an ndarray function or an array-like object containing ndarray functions... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( '10', types, data, 2, 1, 1 ); // $ExpectError - dispatch( 10, types, data, 2, 1, 1 ); // $ExpectError - dispatch( true, types, data, 2, 1, 1 ); // $ExpectError - dispatch( false, types, data, 2, 1, 1 ); // $ExpectError - dispatch( null, types, data, 2, 1, 1 ); // $ExpectError - dispatch( undefined, types, data, 2, 1, 1 ); // $ExpectError - dispatch( [ '1' ], types, data, 2, 1, 1 ); // $ExpectError - dispatch( {}, types, data, 2, 1, 1 ); // $ExpectError - dispatch( ( x: number ): number => x, types, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object... -{ - const data = [ unary ]; - - dispatch( ndarrayFcn, 10, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, true, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, false, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, null, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, undefined, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, {}, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object or null... -{ - const types = [ 'float64', 'float64' ]; - - dispatch( ndarrayFcn, types, 10, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, true, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, false, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, undefined, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, {}, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, '10', 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, true, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, false, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, null, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, undefined, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, [ '1' ], 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, {}, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, ( x: number ): number => x, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, '10', 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, true, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, false, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, null, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, undefined, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, [ '1' ], 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, {}, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, ( x: number ): number => x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, '10' ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, true ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, false ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, null ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, undefined ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, [ '1' ] ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, {} ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch(); // $ExpectError - dispatch( ndarrayFcn ); // $ExpectError - dispatch( ndarrayFcn, types ); // $ExpectError - dispatch( ndarrayFcn, types, data ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, 1, 0 ); // $ExpectError -} - -// The function returns a dispatch function... -{ - const x = array(); - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const t1 = [ 'float64' ]; - const d1 = [ nullary ]; - const f1 = dispatch( ndarrayFcn, t1, d1, 1, 1, 0 ); - f1( x ); // $ExpectType void | ndarray - - const t2 = [ 'float64', 'float64' ]; - const d2 = [ unary ]; - const f2 = dispatch( ndarrayFcn, t2, d2, 2, 1, 1 ); - f2( x, y ); // $ExpectType void | ndarray - - const t3 = [ 'float64', 'float64', 'float64' ]; - const d3 = [ binary ]; - const f3 = dispatch( ndarrayFcn, t3, d3, 3, 2, 1 ); - f3( x, y, z ); // $ExpectType void | ndarray - - const t4 = [ 'float64', 'float64', 'float64', 'float64' ]; - const d4 = [ ternary ]; - const f4 = dispatch( ndarrayFcn, t4, d4, 4, 3, 1 ); - f4( x, y, z, w ); // $ExpectType void | ndarray - - const t5 = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const d5 = [ quaternary ]; - const f5 = dispatch( ndarrayFcn, t5, d5, 5, 4, 1 ); - f5( x, y, z, w, u ); // $ExpectType void | ndarray -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (1 ndarray)... -{ - const types = [ 'float64' ]; - const data = [ nullary ]; - - const f = dispatch( ndarrayFcn, types, data, 1, 0, 1 ); - f( '10' ); // $ExpectError - f( 10 ); // $ExpectError - f( true ); // $ExpectError - f( false ); // $ExpectError - f( null ); // $ExpectError - f( undefined ); // $ExpectError - f( [ '1' ] ); // $ExpectError - f( {} ); // $ExpectError - f( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( 10, y ); // $ExpectError - f( '10', y ); // $ExpectError - f( true, y ); // $ExpectError - f( false, y ); // $ExpectError - f( null, y ); // $ExpectError - f( undefined, y ); // $ExpectError - f( [ '1' ], y ); // $ExpectError - f( {}, y ); // $ExpectError - f( ( x: number ): number => x, y ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const x = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( x, 10 ); // $ExpectError - f( x, '10' ); // $ExpectError - f( x, true ); // $ExpectError - f( x, false ); // $ExpectError - f( x, null ); // $ExpectError - f( x, undefined ); // $ExpectError - f( x, [ '1' ] ); // $ExpectError - f( x, {} ); // $ExpectError - f( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( 10, y, z ); // $ExpectError - f( '10', y, z ); // $ExpectError - f( true, y, z ); // $ExpectError - f( false, y, z ); // $ExpectError - f( null, y, z ); // $ExpectError - f( undefined, y, z ); // $ExpectError - f( [ '1' ], y, z ); // $ExpectError - f( {}, y, z ); // $ExpectError - f( ( x: number ): number => x, y, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, 10, z ); // $ExpectError - f( x, '10', z ); // $ExpectError - f( x, true, z ); // $ExpectError - f( x, false, z ); // $ExpectError - f( x, null, z ); // $ExpectError - f( x, undefined, z ); // $ExpectError - f( x, [ '1' ], z ); // $ExpectError - f( x, {}, z ); // $ExpectError - f( x, ( x: number ): number => x, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, y, '10' ); // $ExpectError - f( x, y, true ); // $ExpectError - f( x, y, false ); // $ExpectError - f( x, y, null ); // $ExpectError - f( x, y, undefined ); // $ExpectError - f( x, y, [ '1' ] ); // $ExpectError - f( x, y, {} ); // $ExpectError - f( x, y, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( 10, y, z, w ); // $ExpectError - f( '10', y, z, w ); // $ExpectError - f( true, y, z, w ); // $ExpectError - f( false, y, z, w ); // $ExpectError - f( null, y, z, w ); // $ExpectError - f( undefined, y, z, w ); // $ExpectError - f( [ '1' ], y, z, w ); // $ExpectError - f( {}, y, z, w ); // $ExpectError - f( ( x: number ): number => x, y, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, 10, z, w ); // $ExpectError - f( x, '10', z, w ); // $ExpectError - f( x, true, z, w ); // $ExpectError - f( x, false, z, w ); // $ExpectError - f( x, null, z, w ); // $ExpectError - f( x, undefined, z, w ); // $ExpectError - f( x, [ '1' ], z, w ); // $ExpectError - f( x, {}, z, w ); // $ExpectError - f( x, ( x: number ): number => x, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, 10, w ); // $ExpectError - f( x, y, '10', w ); // $ExpectError - f( x, y, true, w ); // $ExpectError - f( x, y, false, w ); // $ExpectError - f( x, y, null, w ); // $ExpectError - f( x, y, undefined, w ); // $ExpectError - f( x, y, [ '1' ], w ); // $ExpectError - f( x, y, {}, w ); // $ExpectError - f( x, y, ( x: number ): number => x, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, z, 10 ); // $ExpectError - f( x, y, z, '10' ); // $ExpectError - f( x, y, z, true ); // $ExpectError - f( x, y, z, false ); // $ExpectError - f( x, y, z, null ); // $ExpectError - f( x, y, z, undefined ); // $ExpectError - f( x, y, z, [ '1' ] ); // $ExpectError - f( x, y, z, {} ); // $ExpectError - f( x, y, z, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( 10, y, z, w, u ); // $ExpectError - f( '10', y, z, w, u ); // $ExpectError - f( true, y, z, w, u ); // $ExpectError - f( false, y, z, w, u ); // $ExpectError - f( null, y, z, w, u ); // $ExpectError - f( undefined, y, z, w, u ); // $ExpectError - f( [ '1' ], y, z, w, u ); // $ExpectError - f( {}, y, z, w, u ); // $ExpectError - f( ( x: number ): number => x, y, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, 10, z, w, u ); // $ExpectError - f( x, '10', z, w, u ); // $ExpectError - f( x, true, z, w, u ); // $ExpectError - f( x, false, z, w, u ); // $ExpectError - f( x, null, z, w, u ); // $ExpectError - f( x, undefined, z, w, u ); // $ExpectError - f( x, [ '1' ], z, w, u ); // $ExpectError - f( x, {}, z, w, u ); // $ExpectError - f( x, ( x: number ): number => x, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, 10, w, u ); // $ExpectError - f( x, y, '10', w, u ); // $ExpectError - f( x, y, true, w, u ); // $ExpectError - f( x, y, false, w, u ); // $ExpectError - f( x, y, null, w, u ); // $ExpectError - f( x, y, undefined, w, u ); // $ExpectError - f( x, y, [ '1' ], w, u ); // $ExpectError - f( x, y, {}, w, u ); // $ExpectError - f( x, y, ( x: number ): number => x, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, 10, u ); // $ExpectError - f( x, y, z, '10', u ); // $ExpectError - f( x, y, z, true, u ); // $ExpectError - f( x, y, z, false, u ); // $ExpectError - f( x, y, z, null, u ); // $ExpectError - f( x, y, z, undefined, u ); // $ExpectError - f( x, y, z, [ '1' ], u ); // $ExpectError - f( x, y, z, {}, u ); // $ExpectError - f( x, y, z, ( x: number ): number => x, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fifth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, w, 10 ); // $ExpectError - f( x, y, z, w, '10' ); // $ExpectError - f( x, y, z, w, true ); // $ExpectError - f( x, y, z, w, false ); // $ExpectError - f( x, y, z, w, null ); // $ExpectError - f( x, y, z, w, undefined ); // $ExpectError - f( x, y, z, w, [ '1' ] ); // $ExpectError - f( x, y, z, w, {} ); // $ExpectError - f( x, y, z, w, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/add.js b/examples/add.js deleted file mode 100644 index 775b711..0000000 --- a/examples/add.js +++ /dev/null @@ -1,121 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var dispatch = require( './../lib' ); - -function add2( arrays ) { - var opts; - var xo; - var yo; - var zo; - var sx; - var sy; - var sz; - var sh; - var N; - var x; - var y; - var z; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - z = arrays[ 2 ]; - xo = x.order; - yo = y.order; - zo = z.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - opts.order = yo; - sy = ind2sub( sh, i, opts ); - v = x.get.apply( x, sx ) + y.get.apply( y, sy ); - - opts.order = zo; - sz = ind2sub( sh, i, opts ); - sz.push( v ); - z.set.apply( z, sz ); - } -} - -var fcns = [ - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2 -]; - -var types = [ - dtypes.float64, dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.int32, dtypes.int32, - dtypes.uint32, dtypes.uint32, dtypes.uint32, - dtypes.int16, dtypes.int16, dtypes.int16, - dtypes.uint16, dtypes.uint16, dtypes.uint16, - dtypes.int8, dtypes.int8, dtypes.int8, - dtypes.uint8, dtypes.uint8, dtypes.uint8, - dtypes.uint8c, dtypes.uint8c, dtypes.uint8c -]; - -var add = dispatch( fcns, types, null, 3, 2, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var zbuf = new Float64Array( xbuf.length ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var z = ndarray( 'float64', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); - -xbuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -ybuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -zbuf = new Int32Array( xbuf.length ); - -x = ndarray( 'int32', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'int32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -z = ndarray( 'int32', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); diff --git a/examples/sin.js b/examples/sin.js deleted file mode 100644 index 8cd4871..0000000 --- a/examples/sin.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int8Array = require( '@stdlib/array-int8' ); -var sin = require( '@stdlib/math-base-special-sin' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/strided-dtypes' ); -var dispatch = require( './../lib' ); - -function apply( arrays, fcn ) { - var opts; - var xo; - var yo; - var sx; - var sy; - var sh; - var N; - var x; - var y; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - xo = x.order; - yo = y.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - v = fcn( x.get.apply( x, sx ) ); - - opts.order = yo; - sy = ind2sub( sh, i, opts ); - sy.push( v ); - y.set.apply( y, sy ); - } -} - -var fcns = [ - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply -]; - -var types = [ - dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float64, - dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.float64, - dtypes.uint32, dtypes.float64, - dtypes.int16, dtypes.float64, - dtypes.int16, dtypes.float32, - dtypes.uint16, dtypes.float64, - dtypes.uint16, dtypes.float32, - dtypes.int8, dtypes.float64, - dtypes.int8, dtypes.float32, - dtypes.uint8, dtypes.float64, - dtypes.uint8, dtypes.float32, - dtypes.uint8c, dtypes.float64, - dtypes.uint8c, dtypes.float32 -]; - -var data = [ - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin -]; - -var sine = dispatch( fcns, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); - -xbuf = new Int8Array( [ 1, 2, 3, 4, 5 ] ); -ybuf = new Float32Array( xbuf.length ); - -x = ndarray( 'int8', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'float32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); diff --git a/examples/unary.js b/examples/unary.js deleted file mode 100644 index e9c3fb4..0000000 --- a/examples/unary.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -var unary = require( '@stdlib/ndarray-base-unary' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var dispatch = require( './../lib' ); - -var types = [ 'float64', 'float64' ]; - -var data = [ - abs -]; - -var absolute = dispatch( unary, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -absolute( x, y ); -console.log( ybuf ); -// => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 5f280a1..c49a4e4 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..61e1ca6 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@v0.1.0-esm/index.mjs";function m(e,r,t,n,i,a,s,o,u){var d,m,l,f;for(d=a,l=0;l [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( 'invalid invocation. Insufficient arguments.' );\n\t\t\t}\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n"],"names":["indexOfTypes","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","i","j","dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","out","push","resolveEnum","types2enums","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","getDType","slice"],"mappings":";;i+BA6EA,SAASA,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,KAAgBE,EAAGI,GADdE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,CACN,CACD,OAAQ,CACT,CCMA,SAASU,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,oGAAqGZ,IAEnI,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,+EAAgFX,IAE9G,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,sFAAuFV,IAErH,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,6EAA8ET,IAE5G,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,+EAAgFR,IAE9G,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,+EAAgFP,IAG9G,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAO,8IAElB,GAAKb,IAAUG,EACd,MAAM,IAAIU,MAAO,8FAElB,GAAKR,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAO,qJAIlB,GADAT,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAO,gJAGnB,GAAKd,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAO,qGAGlB,OADAf,EA5GD,SAAsBA,GACrB,IAAIkB,EACAtB,EAGJ,IADAsB,EAAM,GACAtB,EAAI,EAAGA,EAAII,EAAMgB,OAAQpB,IAC9BsB,EAAIC,KAAMC,EAAapB,EAAOJ,KAE/B,OAAOsB,CACR,CAmGSG,CAAarB,GAgBrB,WACC,IAAIsB,EACAC,EACAC,EACAC,EACAC,EACAC,EACA/B,EAGJ,IADA4B,EAAOI,UAAUZ,UACHd,EAAQ,CACrB,GAAKsB,EAAOtB,EACX,MAAM,IAAIa,MAAO,+CAElB,MAAM,IAAIA,MAAO,0CACjB,CAGD,IAFAO,EAAS,GACTC,EAAS,GACH3B,EAAI,EAAGA,EAAIM,EAAON,IAAM,CAE7B,IAAMiC,EADNH,EAAIE,UAAWhC,IAEd,MAAKA,EAAIO,EACF,IAAIO,UAAWC,EAAQ,6EAA8Ee,IAErG,IAAIhB,UAAWC,EAAQ,8EAA+Ee,IAG9GJ,EAAOH,KAAMO,GACbH,EAAOJ,KAAMC,EAAaU,EAAUJ,IACpC,CAKD,IAHAD,EAAMzC,EAAcsB,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGkB,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAIb,UAAW,+GAIrBiB,EADIpB,GAGAR,EAAM0B,GAGNxB,EACJ0B,EAAGL,EAAQrB,EAAMwB,IAEjBE,EAAGL,GAEJ,GAAc,IAATlB,EACJ,OAAOkB,EAAQjB,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOkB,EAAOS,MAAO5B,EACrB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 291641d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Create an ndarray function interface which performs multiple dispatch. -* -* @module @stdlib/ndarray-dispatch -* -* @example -* var dispatch = require( '@stdlib/ndarray-dispatch' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/index_of_types.js b/lib/index_of_types.js deleted file mode 100644 index fda2297..0000000 --- a/lib/index_of_types.js +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found). -* -* ## Notes -* -* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types). -* - The function assumes that `x` is stored in row-major order. -* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`. -* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value. -* -* @private -* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension) -* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension) -* @param {ArrayLikeObject} x - input two-dimensional reference array -* @param {integer} strideX1 - `x` stride length along first dimension -* @param {integer} strideX2 - `x` stride length along second dimension -* @param {NonNegativeInteger} offsetX - `x` starting index -* @param {ArrayLikeObject} y - search array -* @param {integer} strideY - `y` stride length -* @param {NonNegativeInteger} offsetY - `y` starting index -* @returns {integer} row index (if found) and `-1` otherwise -* -* @example -* // Define a reference array to search: -* var types = [ -* 'float64', 'float64', 'float64', -* 'float32', 'float32', 'float32', -* 'uint32', 'uint32', 'float64', -* 'int32', 'int32', 'float64', -* 'uint16', 'uint16', 'float64', -* 'int16', 'int16', 'float64', -* 'uint8', 'uint8', 'float64', -* 'int8', 'int8', 'float64' -* ]; -* -* // Define reference array dimensions: -* var N = 8; // rows -* var M = 3; // columns -* -* // Define a search array: -* y1 = [ -* 'float32', 'float32', 'float32', -* ]; -* -* // Find the list of types: -* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 ); -* // returns 1 -* -// Define a search array: -* y2 = [ -* 'float32', 'float32', 'float64', -* ]; -* -* // Find the list of types: -* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 ); -* // returns -1 -*/ -function indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len - var ix; - var iy; - var i; - var j; - - // Search for the first row which matches `y`... - ix = offsetX; - for ( i = 0; i < N; i++ ) { - iy = offsetY; - for ( j = 0; j < M; j++ ) { - if ( x[ ix+(j*strideX2) ] !== y[ iy ] ) { - break; - } - iy += strideY; - } - // If we successfully iterated over all columns, then that means we've found a match... - if ( j === M ) { - return i; - } - ix += strideX1; - } - return -1; -} - - -// EXPORTS // - -module.exports = indexOfTypes; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 5f4bb5d..0000000 --- a/lib/main.js +++ /dev/null @@ -1,231 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isFunctionArray = require( '@stdlib/assert-is-function-array' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/string-format' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var resolveEnum = require( '@stdlib/ndarray-base-dtype-resolve-enum' ); -var indexOfTypes = require( './index_of_types.js' ); - - -// FUNCTIONS // - -/** -* Returns a list of data type enumeration constants. -* -* @private -* @param {Collection} types - list of types -* @returns {IntegerArray} list of data type enumeration constants -*/ -function types2enums( types ) { - var out; - var i; - - out = []; - for ( i = 0; i < types.length; i++ ) { - out.push( resolveEnum( types[ i ] ) ); - } - return out; -} - - -// MAIN // - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param {(FunctionArray|Function)} fcns - list of ndarray functions -* @param {Collection} types - one-dimensional list of ndarray argument data types -* @param {(Collection|null)} data - ndarray function data (e.g., callbacks) -* @param {PositiveInteger} nargs - total number of ndarray function interface arguments -* @param {NonNegativeInteger} nin - number of input ndarrays -* @param {NonNegativeInteger} nout - number of output ndarrays -* @throws {TypeError} first argument must be either a function or an array of functions -* @throws {TypeError} second argument must be an array-like object -* @throws {TypeError} third argument must be an array-like object or `null` -* @throws {Error} third and first arguments must have the same number of elements -* @throws {TypeError} fourth argument must be a positive integer -* @throws {TypeError} fifth argument must be a nonnegative integer -* @throws {TypeError} sixth argument must be a nonnegative integer -* @throws {Error} fourth argument must equal the specified number of input and output arrays -* @throws {Error} number of types must match the number of functions times the total number of array arguments for each function -* @throws {Error} interface must accept at least one input and/or output ndarray -* @returns {Function} ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function dispatch( fcns, types, data, nargs, nin, nout ) { - var narrays; - var nfcns; - var fcn; - - if ( isFunction( fcns ) ) { - fcn = fcns; - } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) ); - } - if ( !isCollection( types ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) ); - } - if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); - } - if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) ); - } - if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) ); - } - if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) ); - } - narrays = nin + nout; - if ( narrays === 0 ) { - throw new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' ); - } - if ( nargs !== narrays ) { - throw new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' ); - } - if ( fcn ) { - nfcns = types.length / narrays; - if ( !isInteger( nfcns ) ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); - } - } else { - nfcns = fcns.length; - if ( types.length !== nfcns*narrays ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); - } - } - if ( data && data.length !== nfcns ) { - throw new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' ); - } - types = types2enums( types ); - return dispatcher; - - /** - * ndarray function interface which performs multiple dispatch. - * - * @private - * @param {ndarrayLike} x - ndarray - * @param {...ndarrayLike} args - ndarray arguments - * @throws {Error} insufficient arguments - * @throws {Error} too many arguments - * @throws {TypeError} input array arguments must be ndarray-like objects - * @throws {TypeError} output array arguments must be ndarray-like objects - * @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types - * @returns {(ndarrayLike|Array|void)} destination array(s) - */ - function dispatcher() { - var arrays; - var dtypes; - var argc; - var idx; - var v; - var f; - var i; - - argc = arguments.length; - if ( argc !== nargs ) { - if ( argc < nargs ) { - throw new Error( 'invalid invocation. Insufficient arguments.' ); - } - throw new Error( 'invalid invocation. Too many arguments.' ); - } - arrays = []; - dtypes = []; - for ( i = 0; i < nargs; i++ ) { - v = arguments[ i ]; - if ( !isndarrayLike( v ) ) { - if ( i < nin ) { - throw new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) ); - } else { - throw new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) ); - } - } - arrays.push( v ); - dtypes.push( resolveEnum( getDType( v ) ) ); - } - // Resolve the ndarray function satisfying the input array types: - idx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len - - // Check whether we were able to successfully resolve an ndarray function: - if ( idx < 0 ) { - throw new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' ); - } - // Retrieve the ndarray function: - if ( fcn ) { - f = fcn; - } else { - f = fcns[ idx ]; - } - // Evaluate the ndarray function: - if ( data ) { - f( arrays, data[ idx ] ); - } else { - f( arrays ); - } - if ( nout === 1 ) { - return arrays[ narrays-1 ]; - } - if ( nout === 0 ) { - return; - } - return arrays.slice( nin ); - } -} - - -// EXPORTS // - -module.exports = dispatch; diff --git a/package.json b/package.json index 5e6762c..06365f4 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Create an ndarray function interface which performs multiple dispatch.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-collection": "^0.1.0", - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/assert-is-function-array": "^0.1.0", - "@stdlib/assert-is-integer": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/assert-is-nonnegative-integer": "^0.1.0", - "@stdlib/assert-is-positive-integer": "^0.1.0", - "@stdlib/ndarray-base-dtype-resolve-enum": "^0.1.0", - "@stdlib/ndarray-dtype": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.1.1", - "@stdlib/array-float64": "^0.1.1", - "@stdlib/array-int32": "^0.1.1", - "@stdlib/array-int8": "^0.1.1", - "@stdlib/array-uint8": "^0.1.1", - "@stdlib/math-base-assert-is-nan": "^0.1.1", - "@stdlib/math-base-special-abs": "^0.1.1", - "@stdlib/math-base-special-pow": "^0.1.0", - "@stdlib/math-base-special-sin": "^0.1.0", - "@stdlib/ndarray-base-buffer-dtype": "^0.1.0", - "@stdlib/ndarray-base-numel": "^0.1.1", - "@stdlib/ndarray-base-unary": "^0.1.0", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-dtypes": "^0.1.0", - "@stdlib/ndarray-ind2sub": "^0.1.1", - "@stdlib/strided-dtypes": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "ndarray", @@ -99,7 +26,6 @@ "multimethod", "multimethods" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..0a44adb --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/fixtures/binary.js b/test/fixtures/binary.js deleted file mode 100644 index a60dfa2..0000000 --- a/test/fixtures/binary.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Binary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @returns {number} sum -*/ -function binary( x, y ) { - return x + y; -} - - -// EXPORTS // - -module.exports = binary; diff --git a/test/fixtures/fill.js b/test/fixtures/fill.js deleted file mode 100644 index 41b2958..0000000 --- a/test/fixtures/fill.js +++ /dev/null @@ -1,76 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which fills one or more ndarrays. -* -* @private -* @param {*} value - fill value -* @returns {Function} ndarray function -*/ -function fill( value ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - */ - function ndarrayFcn( arrays ) { - var opts; - var sub; - var arr; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - opts = { - 'order': '' - }; - for ( j = 0; j < M; j++ ) { - arr = arrays[ j ]; - opts.order = arrays[ j ].order; - for ( i = 0; i < N; i++ ) { - sub = ind2sub( sh, i, opts ); - sub.push( value ); - arr.set.apply( arr, sub ); - } - } - } -} - - -// EXPORTS // - -module.exports = fill; diff --git a/test/fixtures/foreach.js b/test/fixtures/foreach.js deleted file mode 100644 index a426290..0000000 --- a/test/fixtures/foreach.js +++ /dev/null @@ -1,72 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function forEach( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - fcn.apply( null, args ); - } -} - - -// EXPORTS // - -module.exports = forEach; diff --git a/test/fixtures/map1n.js b/test/fixtures/map1n.js deleted file mode 100644 index 614196b..0000000 --- a/test/fixtures/map1n.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function which maps the return value of a callback to `N` arrays. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function map1N( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var v; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - v = fcn(); - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - sub.push( v ); - arrays[ j ].set.apply( arrays[ j ], sub ); - } - } -} - - -// EXPORTS // - -module.exports = map1N; diff --git a/test/fixtures/nullary.js b/test/fixtures/nullary.js deleted file mode 100644 index 4f22126..0000000 --- a/test/fixtures/nullary.js +++ /dev/null @@ -1,36 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Nullary callback. -* -* @private -* @returns {number} value -*/ -function nullary() { - return 3.0; -} - - -// EXPORTS // - -module.exports = nullary; diff --git a/test/fixtures/quaternary.js b/test/fixtures/quaternary.js deleted file mode 100644 index 548437b..0000000 --- a/test/fixtures/quaternary.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quaternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @returns {number} sum -*/ -function quaternary( x, y, z, w ) { - return x + y + z + w; -} - - -// EXPORTS // - -module.exports = quaternary; diff --git a/test/fixtures/quinary.js b/test/fixtures/quinary.js deleted file mode 100644 index 36068de..0000000 --- a/test/fixtures/quinary.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quinary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @param {number} u - input value -* @returns {number} sum -*/ -function quinary( x, y, z, w, u ) { - return x + y + z + w + u; -} - - -// EXPORTS // - -module.exports = quinary; diff --git a/test/fixtures/sum.js b/test/fixtures/sum.js deleted file mode 100644 index efdbb1b..0000000 --- a/test/fixtures/sum.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which computes the sum across one or more ndarrays. -* -* @private -* @param {Object} ctx - context -* @param {number} ctx.sum - initial sum -* @returns {Function} ndarray function -*/ -function wrapper( ctx ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - * @param {Function} [fcn] - callback - */ - function ndarrayFcn( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var f; - var i; - var j; - - if ( arguments.length > 1 ) { - f = fcn; - } - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - if ( f ) { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - ctx.sum += f.apply( null, args ); - } - } else { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - ctx.sum += arrays[ j ].get.apply( arrays[ j ], sub ); - } - } - } - } -} - - -// EXPORTS // - -module.exports = wrapper; diff --git a/test/fixtures/ternary.js b/test/fixtures/ternary.js deleted file mode 100644 index 0595d5f..0000000 --- a/test/fixtures/ternary.js +++ /dev/null @@ -1,39 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Ternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @returns {number} sum -*/ -function ternary( x, y, z ) { - return x + y + z; -} - - -// EXPORTS // - -module.exports = ternary; diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d6c2c8e..0000000 --- a/test/test.js +++ /dev/null @@ -1,363 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var fill = require( './fixtures/fill.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either a function or an array of functions as a first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( value, types, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object as a second argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided either an array-like object or `null` as a third argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - dispatch( unary, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a positive integer for a fourth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 0, - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a fifth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, value, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a sixth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, 1, value ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function array)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var fcns = [ unary, unary, unary ]; - var data = [ abs, abs, abs ]; - dispatch( fcns, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function argument)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs, abs, abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the length of `data` argument does not match the number of ndarray functions', function test( t ) { - var values; - var i; - - values = [ - [], - [ abs, abs ], - [ abs, abs, abs ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var fcns = [ unary ]; - dispatch( fcns, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the fourth argument is incompatible with the number of input and output ndarrays', function test( t ) { - var values; - var i; - - values = [ - 0, - 1, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of specified input and output ndarrays is zero', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var types = [ 'float64' ]; - dispatch( fill( 3 ), types, null, 1, 0, 0 ); - } -}); - -tape( 'the function returns an ndarray function interface', function test( t ) { - var types; - var data; - var f; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - f = dispatch( unary, types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ unary ], types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( fill( 3 ), types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ fill( 3 ) ], types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.two_arrays.js b/test/test.two_arrays.js deleted file mode 100644 index 16eb61b..0000000 --- a/test/test.two_arrays.js +++ /dev/null @@ -1,814 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var dtype = require( '@stdlib/ndarray-base-buffer-dtype' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var forEach = require( './fixtures/foreach.js' ); -var map1N = require( './fixtures/map1n.js' ); -var fill = require( './fixtures/fill.js' ); -var sum = require( './fixtures/sum.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the first argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var ybuf = new Float64Array( 10 ); - var y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( value, y ); - }; - } -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the second argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var xbuf = new Float64Array( 10 ); - var x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( x, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided insufficient arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var f; - var x; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [], - [ x ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided too many arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var ybuf; - var f; - var x; - var y; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [ x, y, y ], - [ x, y, y, y ], - [ x, y, y, y, y ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if unable to resolve a ndarray function supporting the provided array argument data types', function test( t ) { - var values; - var types; - var data; - var xbuf; - var fcn; - var x; - var i; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ abs, abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 4 ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - values = [ - new Uint8Array( 4 ), - new Int32Array( 4 ), - [ 0, 0, 0, 0 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided an array having data type: ' + dtype( values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var y = ndarray( dtype( value ), value, [ value.length ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - }; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only input arrays)', function test( t ) { - var types; - var xbuf; - var ybuf; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only output arrays)', function test( t ) { - var expected; - var types; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only input arrays)', function test( t ) { - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var ctx; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcns = [ - sum( ctx ), - sum( ctx ) - ]; - fcn = dispatch( fcns, types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only output arrays)', function test( t ) { - var expected; - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcns = [ - fill( 3.0 ), - fill( 4.0 ) - ]; - fcn = dispatch( fcns, types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - - fcn = dispatch( forEach, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - - fcn = dispatch( map1N, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - fcns = [ - forEach, - forEach - ]; - fcn = dispatch( fcns, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - fcns = [ - map1N, - map1N - ]; - fcn = dispatch( fcns, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - fcns = [ - unary, - unary - ]; - fcn = dispatch( fcns, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which returns one or more output arrays, if one or more output arrays is specified, and otherwise returns `undefined`', function test( t ) { - var types; - var data; - var xbuf; - var ybuf; - var out; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - // No output arrays... - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, void 0, 'returns expected value' ); - - // One output array... - data = [ - abs, - abs - ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - fcn = dispatch( fill( 3.0 ), types, null, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - // Two output arrays... - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.end(); -}); From ebcf5891681d4ed0632504bedbdaf15b59f121fa Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 01:13:43 +0000 Subject: [PATCH 059/109] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 403d0df..766ba14 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/assert-is-positive-integer": "^0.2.0", "@stdlib/ndarray-base-dtype-resolve-enum": "^0.2.0", "@stdlib/ndarray-dtype": "^0.2.0", - "@stdlib/string-format": "^0.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.2.0", "@stdlib/types": "^0.3.1" }, "devDependencies": { From b84a70f0390762bb3b40dd394633812cedec83b4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 04:40:25 +0000 Subject: [PATCH 060/109] Remove files --- index.d.ts | 334 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6516 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index c49a4e4..0000000 --- a/index.d.ts +++ /dev/null @@ -1,334 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* ndarray function. -* -* @param arrays - array containing input and output ndarrays -* @param data - ndarray function data (e.g., a callback) -* -* @example -* var numel = require( '@stdlib/ndarray-base-numel' ); -* var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -* -* function ndarrayFcn( arrays, fcn ) { -* var xord; -* var yord; -* var opts; -* var sub; -* var sh; -* var N; -* var x; -* var y; -* var v; -* var i; -* -* x = arrays[ 0 ]; -* y = arrays[ 1 ]; -* sh = x.shape; -* N = numel( sh ); -* if ( N <= 0 ) { -* return; -* } -* xord = x.order; -* yord = y.order; -* opts = {}; -* opts.order = xord; -* for ( i = 0; i < N; i++ ) { -* // Convert a linear index to subscripts: -* opts.order = xord; -* sub = ind2sub( sh, i, opts ); -* -* // Retrieve an element from `x`: -* v = x.get.apply( x, sub ); -* -* // Convert a linear index to subscripts: -* opts.order = yord; -* sub = ind2sub( sh, i, opts ); -* -* // Append the result of applying the callback: -* sub.push( fcn( v ) ); -* -* // Assign the result to an element in `y`: -* y.set.apply( y, sub ); -* } -* } -*/ -type ndarrayFcn = ( arrays: Array, data?: any ) => void; - -/** -* Interface describing an ndarray function dispatcher. -*/ -interface Dispatcher { - /** - * Invokes an ndarray function based on the provided array data type(s). - * - * @param x - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array - * - * @example - * var nullary = require( '@stdlib/ndarray-base-nullary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function value() { - * return 3.14; - * } - * - * var types = [ 'float64' ]; - * var data = [ value ]; - * - * var fcn = dispatch( nullary, types, data, 1, 0, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( 5 ); - * var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x ); - * // xbuf => [ 3.14, 3.14, 3.14, 3.14, 3.14 ] - */ - ( x: ndarray ): ndarray | void; - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var unary = require( '@stdlib/ndarray-base-unary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * var abs = require( '@stdlib/math-base-special-abs' ); - * - * var types = [ 'float64', 'float64' ]; - * var data = [ abs ]; - * - * var fcn = dispatch( unary, types, data, 2, 1, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - * var ybuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y ); - * // ybuf => [ 1.0, 2.0, 3.0 ] - */ - ( x: ndarray, y: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var ternary = require( '@stdlib/ndarray-base-ternary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function add2( x, y ) { - * return x + y; - * } - * - * var types = [ 'float64', 'float64', 'float64' ]; - * var data = [ add2 ]; - * - * var fcn = dispatch( ternary, types, data, 3, 2, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z ); - * // zbuf => [ 2.0, 4.0, 6.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quaternary = require( '@stdlib/ndarray-base-quaternary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function add3( x, y, z ) { - * return x + y + z; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add3 ]; - * - * var fcn = dispatch( quaternary, types, data, 4, 3, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w ); - * // wbuf => [ 3.0, 6.0, 9.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @param args - ndarray arguments - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quinary = require( '@stdlib/ndarray-base-quinary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function add4( x, y, z, w ) { - * return x + y + z + w; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add4 ]; - * - * var fcn = dispatch( quinary, types, data, 5, 4, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ubuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var u = ndarray( 'float64', ubuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w, u ); - * // ubuf => [ 4.0, 8.0, 12.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray, ...args: Array ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures -} - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param fcns - list of ndarray functions -* @param types - one-dimensional list of ndarray argument data types -* @param data - ndarray function data (e.g., callbacks) -* @param nargs - total number of ndarray function interface arguments -* @param nin - number of input ndarrays -* @param nout - number of output ndarrays -* @throws first argument must be either a function or an array of functions -* @throws second argument must be an array-like object -* @throws third argument must be an array-like object or `null` -* @throws third and first arguments must have the same number of elements -* @throws fourth argument must be a positive integer -* @throws fifth argument must be a nonnegative integer -* @throws sixth argument must be a nonnegative integer -* @throws fourth argument must equal the specified number of input and output arrays -* @throws number of types must match the number of functions times the total number of array arguments for each function -* @throws interface must accept at least one input and/or output ndarray -* @returns ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var fcn = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* fcn( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function dispatch( fcns: ndarrayFcn | ArrayLike, types: ArrayLike, data: ArrayLike | null, nargs: number, nin: number, nout: number ): Dispatcher; - - -// EXPORTS // - -export = dispatch; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 61e1ca6..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.1.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.1.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.1.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@v0.1.0-esm/index.mjs";function m(e,r,t,n,i,a,s,o,u){var d,m,l,f;for(d=a,l=0;l [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( 'invalid invocation. Insufficient arguments.' );\n\t\t\t}\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n"],"names":["indexOfTypes","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","i","j","dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","out","push","resolveEnum","types2enums","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","getDType","slice"],"mappings":";;i+BA6EA,SAASA,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,KAAgBE,EAAGI,GADdE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,CACN,CACD,OAAQ,CACT,CCMA,SAASU,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,oGAAqGZ,IAEnI,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,+EAAgFX,IAE9G,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,sFAAuFV,IAErH,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,6EAA8ET,IAE5G,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,+EAAgFR,IAE9G,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,+EAAgFP,IAG9G,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAO,8IAElB,GAAKb,IAAUG,EACd,MAAM,IAAIU,MAAO,8FAElB,GAAKR,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAO,qJAIlB,GADAT,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAO,gJAGnB,GAAKd,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAO,qGAGlB,OADAf,EA5GD,SAAsBA,GACrB,IAAIkB,EACAtB,EAGJ,IADAsB,EAAM,GACAtB,EAAI,EAAGA,EAAII,EAAMgB,OAAQpB,IAC9BsB,EAAIC,KAAMC,EAAapB,EAAOJ,KAE/B,OAAOsB,CACR,CAmGSG,CAAarB,GAgBrB,WACC,IAAIsB,EACAC,EACAC,EACAC,EACAC,EACAC,EACA/B,EAGJ,IADA4B,EAAOI,UAAUZ,UACHd,EAAQ,CACrB,GAAKsB,EAAOtB,EACX,MAAM,IAAIa,MAAO,+CAElB,MAAM,IAAIA,MAAO,0CACjB,CAGD,IAFAO,EAAS,GACTC,EAAS,GACH3B,EAAI,EAAGA,EAAIM,EAAON,IAAM,CAE7B,IAAMiC,EADNH,EAAIE,UAAWhC,IAEd,MAAKA,EAAIO,EACF,IAAIO,UAAWC,EAAQ,6EAA8Ee,IAErG,IAAIhB,UAAWC,EAAQ,8EAA+Ee,IAG9GJ,EAAOH,KAAMO,GACbH,EAAOJ,KAAMC,EAAaU,EAAUJ,IACpC,CAKD,IAHAD,EAAMzC,EAAcsB,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGkB,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAIb,UAAW,+GAIrBiB,EADIpB,GAGAR,EAAM0B,GAGNxB,EACJ0B,EAAGL,EAAQrB,EAAMwB,IAEjBE,EAAGL,GAEJ,GAAc,IAATlB,EACJ,OAAOkB,EAAQjB,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOkB,EAAOS,MAAO5B,EACrB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 0a44adb..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 9481a2db6183508e9b905f0610d3de8a2abc79fb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 04:41:11 +0000 Subject: [PATCH 061/109] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 61 +- SECURITY.md | 5 - benchmark/benchmark.dispatch_size.js | 156 - benchmark/benchmark.js | 81 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 87 - docs/types/test.ts | 641 --- examples/add.js | 121 - examples/sin.js | 142 - examples/unary.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/index_of_types.js | 106 - lib/main.js | 231 - package.json | 78 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/binary.js | 38 - test/fixtures/fill.js | 76 - test/fixtures/foreach.js | 72 - test/fixtures/map1n.js | 74 - test/fixtures/nullary.js | 36 - test/fixtures/quaternary.js | 40 - test/fixtures/quinary.js | 41 - test/fixtures/sum.js | 98 - test/fixtures/ternary.js | 39 - test/test.js | 363 -- test/test.two_arrays.js | 814 --- 56 files changed, 6211 insertions(+), 6751 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.dispatch_size.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/add.js delete mode 100644 examples/sin.js delete mode 100644 examples/unary.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/index_of_types.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/fixtures/binary.js delete mode 100644 test/fixtures/fill.js delete mode 100644 test/fixtures/foreach.js delete mode 100644 test/fixtures/map1n.js delete mode 100644 test/fixtures/nullary.js delete mode 100644 test/fixtures/quaternary.js delete mode 100644 test/fixtures/quinary.js delete mode 100644 test/fixtures/sum.js delete mode 100644 test/fixtures/ternary.js delete mode 100644 test/test.js delete mode 100644 test/test.two_arrays.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ac0b7cd..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 5e92c3e..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 69b9dc2..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '43 7 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -304,7 +295,7 @@ console.log( ybuf ); ## 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. +This package is part of [stdlib][stdlib], a standard library 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]. @@ -367,11 +358,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-dispatch/main/LICENSE -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.dispatch_size.js b/benchmark/benchmark.dispatch_size.js deleted file mode 100644 index 15805ba..0000000 --- a/benchmark/benchmark.dispatch_size.js +++ /dev/null @@ -1,156 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib/main.js' ); - - -// FUNCTIONS // - -/** -* Evaluates the identity function. -* -* @private -* @param {*} v - value -* @returns {*} input value -*/ -function identity( v ) { - return v; -} - -/** -* Dummy function which throws an error. -* -* @private -* @throws {Error} unexpected error -*/ -function throwError() { - throw new Error( 'unexpected error' ); -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} size - dispatch size -* @returns {Function} benchmark function -*/ -function createBenchmark( size ) { - var types; - var data; - var fcn; - var x; - var y; - var t; - var i; - - types = []; - - // Create dummy types... - for ( i = 0; i < (size-1)*2; i += 2 ) { - t = 'foo' + i; - types.push( t ); - types.push( t ); - } - // Append test types: - types.push( 'float64' ); - types.push( 'float64' ); - - // Define a list of callbacks: - data = []; - for ( i = 0; i < size-1; i++ ) { - data.push( throwError ); - } - // Append a test callback: - data.push( identity ); - - // Create the dispatcher: - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - // Create sample arrays: - x = new Float64Array( 1 ); - y = new Float64Array( x.length ); - - x = ndarray( 'float64', x, [ 1 ], [ 1 ], 0, 'row-major' ); - y = ndarray( 'float64', y, [ 1 ], [ 1 ], 0, 'row-major' ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var z; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x.data[ 0 ] = i; - z = fcn( x, y ); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var size; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - size = pow( 2, i ); - f = createBenchmark( size ); - bench( pkg+':size='+size, f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 3c6f450..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::fcns_array', function benchmark( b ) { - var types; - var fcns; - var data; - var out; - var i; - - fcns = [ unary ]; - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( fcns, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::fcn_arg', function benchmark( b ) { - var types; - var data; - var out; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( unary, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0aae4af..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch" -%% click B href "https://github.com/stdlib-js/ndarray-dispatch/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-dispatch/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-dispatch/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-dispatch/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-dispatch/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch -[production-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 1295a44..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import dispatch from '../docs/types/index'; -export = dispatch; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7fb29cb..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var y=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var b=y(function(D,w){ -function k(i,r,e,u,f,m,n,o,l){var h,t,s,a;for(h=m,s=0;s [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( 'invalid invocation. Insufficient arguments.' );\n\t\t\t}\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = dispatch;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an ndarray function interface which performs multiple dispatch.\n*\n* @module @stdlib/ndarray-dispatch\n*\n* @example\n* var dispatch = require( '@stdlib/ndarray-dispatch' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var unary = require( '@stdlib/ndarray-base-unary' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var types = [\n* 'float64', 'float64'\n* ];\n*\n* var data = [\n* abs\n* ];\n*\n* var absolute = dispatch( unary, types, data, 2, 1, 1 );\n*\n* // ...\n*\n* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] );\n* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] );\n*\n* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' );\n* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' );\n*\n* absolute( x, y );\n* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA6EA,SAASC,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,EAAU,CAClF,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,CAAU,IAAME,EAAGI,CAAG,EADjBE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,CACP,CACA,MAAO,EACR,CAKAL,EAAO,QAAUC,ICzGjB,IAAAc,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAoB,QAAS,oCAAqC,EAClEC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAkB,QAAS,kCAAmC,EAC9DC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAc,QAAS,yCAA0C,EACjEC,EAAe,IAYnB,SAASC,EAAaC,EAAQ,CAC7B,IAAIC,EACAC,EAGJ,IADAD,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIF,EAAM,OAAQE,IAC9BD,EAAI,KAAMJ,EAAaG,EAAOE,CAAE,CAAE,CAAE,EAErC,OAAOD,CACR,CAqDA,SAASE,EAAUC,EAAMJ,EAAOK,EAAMC,EAAOC,EAAKC,EAAO,CACxD,IAAIC,EACAC,EACAC,EAEJ,GAAKnB,EAAYY,CAAK,EACrBO,EAAMP,UACK,CAACb,EAAiBa,CAAK,EAClC,MAAM,IAAI,UAAWT,EAAQ,oGAAqGS,CAAK,CAAE,EAE1I,GAAK,CAACX,EAAcO,CAAM,EACzB,MAAM,IAAI,UAAWL,EAAQ,+EAAgFK,CAAM,CAAE,EAEtH,GAAK,CAACP,EAAcY,CAAK,GAAKA,IAAS,KACtC,MAAM,IAAI,UAAWV,EAAQ,sFAAuFU,CAAK,CAAE,EAE5H,GAAK,CAAChB,EAAmBiB,CAAM,EAC9B,MAAM,IAAI,UAAWX,EAAQ,6EAA8EW,CAAM,CAAE,EAEpH,GAAK,CAAClB,EAAsBmB,CAAI,EAC/B,MAAM,IAAI,UAAWZ,EAAQ,+EAAgFY,CAAI,CAAE,EAEpH,GAAK,CAACnB,EAAsBoB,CAAK,EAChC,MAAM,IAAI,UAAWb,EAAQ,+EAAgFa,CAAK,CAAE,EAGrH,GADAC,EAAUF,EAAMC,EACXC,IAAY,EAChB,MAAM,IAAI,MAAO,4IAA6I,EAE/J,GAAKH,IAAUG,EACd,MAAM,IAAI,MAAO,4FAA6F,EAE/G,GAAKE,GAEJ,GADAD,EAAQV,EAAM,OAASS,EAClB,CAACnB,EAAWoB,CAAM,EACtB,MAAM,IAAI,MAAO,8IAA+I,UAGjKA,EAAQN,EAAK,OACRJ,EAAM,SAAWU,EAAMD,EAC3B,MAAM,IAAI,MAAO,8IAA+I,EAGlK,GAAKJ,GAAQA,EAAK,SAAWK,EAC5B,MAAM,IAAI,MAAO,mGAAoG,EAEtH,OAAAV,EAAQD,EAAaC,CAAM,EACpBY,EAeP,SAASA,GAAa,CACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EAGJ,GADAa,EAAO,UAAU,OACZA,IAAST,EACb,MAAKS,EAAOT,EACL,IAAI,MAAO,6CAA8C,EAE1D,IAAI,MAAO,yCAA0C,EAI5D,IAFAO,EAAS,CAAC,EACVC,EAAS,CAAC,EACJZ,EAAI,EAAGA,EAAII,EAAOJ,IAAM,CAE7B,GADAe,EAAI,UAAWf,CAAE,EACZ,CAACR,EAAeuB,CAAE,EACtB,MAAKf,EAAIK,EACF,IAAI,UAAWZ,EAAQ,6EAA8EsB,CAAE,CAAE,EAEzG,IAAI,UAAWtB,EAAQ,8EAA+EsB,CAAE,CAAE,EAGlHJ,EAAO,KAAMI,CAAE,EACfH,EAAO,KAAMjB,EAAaD,EAAUqB,CAAE,CAAE,CAAE,CAC3C,CAKA,GAHAD,EAAMlB,EAAcY,EAAOD,EAAST,EAAOS,EAAS,EAAG,EAAGK,EAAQ,EAAG,CAAE,EAGlEE,EAAM,EACV,MAAM,IAAI,UAAW,6GAA8G,EAcpI,GAXKL,EACJO,EAAIP,EAEJO,EAAId,EAAMY,CAAI,EAGVX,EACJa,EAAGL,EAAQR,EAAMW,CAAI,CAAE,EAEvBE,EAAGL,CAAO,EAENL,IAAS,EACb,OAAOK,EAAQJ,EAAQ,CAAE,EAE1B,GAAKD,IAAS,EAGd,OAAOK,EAAO,MAAON,CAAI,CAC1B,CACD,CAKApB,EAAO,QAAUgB,IC9KjB,IAAIgB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_index_of_types", "__commonJSMin", "exports", "module", "indexOfTypes", "N", "M", "x", "strideX1", "strideX2", "offsetX", "y", "strideY", "offsetY", "ix", "iy", "i", "j", "require_main", "__commonJSMin", "exports", "module", "isNonNegativeInteger", "isPositiveInteger", "isInteger", "isFunctionArray", "isFunction", "isCollection", "isndarrayLike", "format", "getDType", "resolveEnum", "indexOfTypes", "types2enums", "types", "out", "i", "dispatch", "fcns", "data", "nargs", "nin", "nout", "narrays", "nfcns", "fcn", "dispatcher", "arrays", "dtypes", "argc", "idx", "v", "f", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 02fe150..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,87 +0,0 @@ - -{{alias}}( fcns, types, data, nargs, nin, nout ) - Returns an ndarray function interface which performs multiple dispatch. - - An ndarray function interface has the following signature: - - f( x, y, ... ) - - where - - - x: ndarray. - - y: ndarray. - - ...: additional ndarrays. - - The number of parameters is derived from `nargs`, the number of input - ndarrays is derived from `nin`, and the number of output ndarrays is derived - from `nout`. - - Parameters - ---------- - fcns: Function|ArrayLikeObject - List of ndarray functions. An ndarray function should have the following - signature: - - f( arrays, data ) - - where - - - arrays: array containing input and output ndarrays. - - data: ndarray function data (e.g., a callback). - - For convenience, a single ndarray function may be provided which will be - invoked whenever the ndarray argument data types match a sequence of - types in `types`. Providing a single ndarray function is particularly - convenient for the case where, regardless of array data types, - traversing arrays remains the same, but the ndarray function `data` - differs (e.g., callbacks which differ based on the array data types). - - types: ArrayLikeObject - One-dimensional list of ndarray argument data types. - - data: ArrayLikeObject|null - ndarray function data (e.g., callbacks). If `null`, a returned ndarray - function interface does **not** provide a `data` argument to an invoked - ndarray function. - - nargs: integer - Total number of ndarray function interface arguments. - - nin: integer - Number of input ndarrays. - - nout: integer - Number of output ndarrays. - - Returns - ------- - fcn: Function - ndarray function interface. - - Examples - -------- - // Define ndarray argument data types: - > var t = [ 'float64', 'float64', 'float32', 'float32' ]; - - // Define a list of ndarray function data (callbacks): - > var d = [ {{alias:@stdlib/math/base/special/abs}}, {{alias:@stdlib/math/base/special/absf}} ]; - - // Create an ndarray function interface for applying unary callbacks: - > var f = {{alias}}( {{alias:@stdlib/ndarray/base/unary}}, t, d, 2, 1, 1 ); - - // Create an input ndarray: - > var xbuf = new {{alias:@stdlib/array/float64}}( [ -1.0, -2.0, -3.0, -4.0 ] ); - > var x = {{alias:@stdlib/ndarray/ctor}}( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Create an output ndarray: - > var ybuf = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 0.0, 0.0 ] ); - > var y = {{alias:@stdlib/ndarray/ctor}}( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Compute the element-wise absolute value: - > f( x, y ); - > ybuf - [ 1.0, 2.0, 3.0, 4.0 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 3cba031..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,641 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable max-lines */ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import dispatch = require( './index' ); - - -// FUNCTIONS // - -/** -* Nullary callback. -* -* @return input value -*/ -function nullary(): any { - return 5.0; -} - -/** -* Unary callback. -* -* @param x - input value -* @return input value -*/ -function unary( x: any ): any { - return x; -} - -/** -* Binary callback. -* -* @param x - input value -* @param y - input value -* @return output value -*/ -function binary( x: number, y: number ): number { - return x + y; -} - -/** -* Ternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @return output value -*/ -function ternary( x: number, y: number, z: number ): number { - return x + y + z; -} - -/** -* Quaternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @param w - input value -* @return output value -*/ -function quaternary( x: number, y: number, z: number, w: number ): number { - return x + y + z + w; -} - -/** -* Mock `ind2sub` function. -* -* @param shape - dimensions -* @param idx - linear index -* @param opts - options -* @return subscripts -*/ -function ind2sub( shape: ArrayLike, idx: number, opts?: any ): Array { - let out; - let i; - - out = []; - if ( typeof opts === 'object' && opts !== null && opts.order === 'row-major' ) { no-unsafe-any - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } else { - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } - return out; -} - -/** -* Mock ndarray function. -* -* @param arrays - ndarrays -* @param fcn - callback -*/ -function ndarrayFcn( arrays: Array, fcn: ( x: any ) => any ): void { - let xord; - let yord; - let opts; - let sub; - let sh; - let N; - let x; - let y; - let v; - let i; - - x = arrays[ 0 ]; - y = arrays[ 1 ]; - sh = x.shape; - if ( sh.length === 0 ) { - return; - } - N = 1; - for ( i = 0; i < sh.length; i += 1 ) { - N *= sh[ i ]; - } - xord = x.order; - yord = y.order; - opts = { - 'order': '' - }; - opts.order = xord; - for ( i = 0; i < N; i += 1 ) { - // Convert a linear index to subscripts: - opts.order = xord; - sub = ind2sub( sh, i, opts ); - - // Retrieve an element from `x`: - v = x.get.apply( x, sub ); - - // Convert a linear index to subscripts: - opts.order = yord; - sub = ind2sub( sh, i, opts ); - - // Append the result of applying the callback: - sub[ sub.length ] = fcn( v ) as number; - - // Assign the result to an element in `y`: - y.set.apply( y, sub ); - } -} - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a dispatch function... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, 1 ); // $ExpectType Dispatcher - dispatch( [ ndarrayFcn ], types, data, 2, 1, 1 ); // $ExpectType Dispatcher -} - -// The compiler throws an error if the function is provided a first argument which is not either an ndarray function or an array-like object containing ndarray functions... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( '10', types, data, 2, 1, 1 ); // $ExpectError - dispatch( 10, types, data, 2, 1, 1 ); // $ExpectError - dispatch( true, types, data, 2, 1, 1 ); // $ExpectError - dispatch( false, types, data, 2, 1, 1 ); // $ExpectError - dispatch( null, types, data, 2, 1, 1 ); // $ExpectError - dispatch( undefined, types, data, 2, 1, 1 ); // $ExpectError - dispatch( [ '1' ], types, data, 2, 1, 1 ); // $ExpectError - dispatch( {}, types, data, 2, 1, 1 ); // $ExpectError - dispatch( ( x: number ): number => x, types, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object... -{ - const data = [ unary ]; - - dispatch( ndarrayFcn, 10, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, true, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, false, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, null, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, undefined, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, {}, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object or null... -{ - const types = [ 'float64', 'float64' ]; - - dispatch( ndarrayFcn, types, 10, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, true, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, false, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, undefined, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, {}, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, '10', 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, true, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, false, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, null, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, undefined, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, [ '1' ], 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, {}, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, ( x: number ): number => x, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, '10', 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, true, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, false, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, null, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, undefined, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, [ '1' ], 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, {}, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, ( x: number ): number => x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, '10' ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, true ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, false ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, null ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, undefined ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, [ '1' ] ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, {} ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch(); // $ExpectError - dispatch( ndarrayFcn ); // $ExpectError - dispatch( ndarrayFcn, types ); // $ExpectError - dispatch( ndarrayFcn, types, data ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, 1, 0 ); // $ExpectError -} - -// The function returns a dispatch function... -{ - const x = array(); - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const t1 = [ 'float64' ]; - const d1 = [ nullary ]; - const f1 = dispatch( ndarrayFcn, t1, d1, 1, 1, 0 ); - f1( x ); // $ExpectType void | ndarray - - const t2 = [ 'float64', 'float64' ]; - const d2 = [ unary ]; - const f2 = dispatch( ndarrayFcn, t2, d2, 2, 1, 1 ); - f2( x, y ); // $ExpectType void | ndarray - - const t3 = [ 'float64', 'float64', 'float64' ]; - const d3 = [ binary ]; - const f3 = dispatch( ndarrayFcn, t3, d3, 3, 2, 1 ); - f3( x, y, z ); // $ExpectType void | ndarray - - const t4 = [ 'float64', 'float64', 'float64', 'float64' ]; - const d4 = [ ternary ]; - const f4 = dispatch( ndarrayFcn, t4, d4, 4, 3, 1 ); - f4( x, y, z, w ); // $ExpectType void | ndarray - - const t5 = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const d5 = [ quaternary ]; - const f5 = dispatch( ndarrayFcn, t5, d5, 5, 4, 1 ); - f5( x, y, z, w, u ); // $ExpectType void | ndarray -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (1 ndarray)... -{ - const types = [ 'float64' ]; - const data = [ nullary ]; - - const f = dispatch( ndarrayFcn, types, data, 1, 0, 1 ); - f( '10' ); // $ExpectError - f( 10 ); // $ExpectError - f( true ); // $ExpectError - f( false ); // $ExpectError - f( null ); // $ExpectError - f( undefined ); // $ExpectError - f( [ '1' ] ); // $ExpectError - f( {} ); // $ExpectError - f( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( 10, y ); // $ExpectError - f( '10', y ); // $ExpectError - f( true, y ); // $ExpectError - f( false, y ); // $ExpectError - f( null, y ); // $ExpectError - f( undefined, y ); // $ExpectError - f( [ '1' ], y ); // $ExpectError - f( {}, y ); // $ExpectError - f( ( x: number ): number => x, y ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const x = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( x, 10 ); // $ExpectError - f( x, '10' ); // $ExpectError - f( x, true ); // $ExpectError - f( x, false ); // $ExpectError - f( x, null ); // $ExpectError - f( x, undefined ); // $ExpectError - f( x, [ '1' ] ); // $ExpectError - f( x, {} ); // $ExpectError - f( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( 10, y, z ); // $ExpectError - f( '10', y, z ); // $ExpectError - f( true, y, z ); // $ExpectError - f( false, y, z ); // $ExpectError - f( null, y, z ); // $ExpectError - f( undefined, y, z ); // $ExpectError - f( [ '1' ], y, z ); // $ExpectError - f( {}, y, z ); // $ExpectError - f( ( x: number ): number => x, y, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, 10, z ); // $ExpectError - f( x, '10', z ); // $ExpectError - f( x, true, z ); // $ExpectError - f( x, false, z ); // $ExpectError - f( x, null, z ); // $ExpectError - f( x, undefined, z ); // $ExpectError - f( x, [ '1' ], z ); // $ExpectError - f( x, {}, z ); // $ExpectError - f( x, ( x: number ): number => x, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, y, '10' ); // $ExpectError - f( x, y, true ); // $ExpectError - f( x, y, false ); // $ExpectError - f( x, y, null ); // $ExpectError - f( x, y, undefined ); // $ExpectError - f( x, y, [ '1' ] ); // $ExpectError - f( x, y, {} ); // $ExpectError - f( x, y, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( 10, y, z, w ); // $ExpectError - f( '10', y, z, w ); // $ExpectError - f( true, y, z, w ); // $ExpectError - f( false, y, z, w ); // $ExpectError - f( null, y, z, w ); // $ExpectError - f( undefined, y, z, w ); // $ExpectError - f( [ '1' ], y, z, w ); // $ExpectError - f( {}, y, z, w ); // $ExpectError - f( ( x: number ): number => x, y, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, 10, z, w ); // $ExpectError - f( x, '10', z, w ); // $ExpectError - f( x, true, z, w ); // $ExpectError - f( x, false, z, w ); // $ExpectError - f( x, null, z, w ); // $ExpectError - f( x, undefined, z, w ); // $ExpectError - f( x, [ '1' ], z, w ); // $ExpectError - f( x, {}, z, w ); // $ExpectError - f( x, ( x: number ): number => x, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, 10, w ); // $ExpectError - f( x, y, '10', w ); // $ExpectError - f( x, y, true, w ); // $ExpectError - f( x, y, false, w ); // $ExpectError - f( x, y, null, w ); // $ExpectError - f( x, y, undefined, w ); // $ExpectError - f( x, y, [ '1' ], w ); // $ExpectError - f( x, y, {}, w ); // $ExpectError - f( x, y, ( x: number ): number => x, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, z, 10 ); // $ExpectError - f( x, y, z, '10' ); // $ExpectError - f( x, y, z, true ); // $ExpectError - f( x, y, z, false ); // $ExpectError - f( x, y, z, null ); // $ExpectError - f( x, y, z, undefined ); // $ExpectError - f( x, y, z, [ '1' ] ); // $ExpectError - f( x, y, z, {} ); // $ExpectError - f( x, y, z, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( 10, y, z, w, u ); // $ExpectError - f( '10', y, z, w, u ); // $ExpectError - f( true, y, z, w, u ); // $ExpectError - f( false, y, z, w, u ); // $ExpectError - f( null, y, z, w, u ); // $ExpectError - f( undefined, y, z, w, u ); // $ExpectError - f( [ '1' ], y, z, w, u ); // $ExpectError - f( {}, y, z, w, u ); // $ExpectError - f( ( x: number ): number => x, y, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, 10, z, w, u ); // $ExpectError - f( x, '10', z, w, u ); // $ExpectError - f( x, true, z, w, u ); // $ExpectError - f( x, false, z, w, u ); // $ExpectError - f( x, null, z, w, u ); // $ExpectError - f( x, undefined, z, w, u ); // $ExpectError - f( x, [ '1' ], z, w, u ); // $ExpectError - f( x, {}, z, w, u ); // $ExpectError - f( x, ( x: number ): number => x, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, 10, w, u ); // $ExpectError - f( x, y, '10', w, u ); // $ExpectError - f( x, y, true, w, u ); // $ExpectError - f( x, y, false, w, u ); // $ExpectError - f( x, y, null, w, u ); // $ExpectError - f( x, y, undefined, w, u ); // $ExpectError - f( x, y, [ '1' ], w, u ); // $ExpectError - f( x, y, {}, w, u ); // $ExpectError - f( x, y, ( x: number ): number => x, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, 10, u ); // $ExpectError - f( x, y, z, '10', u ); // $ExpectError - f( x, y, z, true, u ); // $ExpectError - f( x, y, z, false, u ); // $ExpectError - f( x, y, z, null, u ); // $ExpectError - f( x, y, z, undefined, u ); // $ExpectError - f( x, y, z, [ '1' ], u ); // $ExpectError - f( x, y, z, {}, u ); // $ExpectError - f( x, y, z, ( x: number ): number => x, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fifth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, w, 10 ); // $ExpectError - f( x, y, z, w, '10' ); // $ExpectError - f( x, y, z, w, true ); // $ExpectError - f( x, y, z, w, false ); // $ExpectError - f( x, y, z, w, null ); // $ExpectError - f( x, y, z, w, undefined ); // $ExpectError - f( x, y, z, w, [ '1' ] ); // $ExpectError - f( x, y, z, w, {} ); // $ExpectError - f( x, y, z, w, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/add.js b/examples/add.js deleted file mode 100644 index 775b711..0000000 --- a/examples/add.js +++ /dev/null @@ -1,121 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var dispatch = require( './../lib' ); - -function add2( arrays ) { - var opts; - var xo; - var yo; - var zo; - var sx; - var sy; - var sz; - var sh; - var N; - var x; - var y; - var z; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - z = arrays[ 2 ]; - xo = x.order; - yo = y.order; - zo = z.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - opts.order = yo; - sy = ind2sub( sh, i, opts ); - v = x.get.apply( x, sx ) + y.get.apply( y, sy ); - - opts.order = zo; - sz = ind2sub( sh, i, opts ); - sz.push( v ); - z.set.apply( z, sz ); - } -} - -var fcns = [ - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2 -]; - -var types = [ - dtypes.float64, dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.int32, dtypes.int32, - dtypes.uint32, dtypes.uint32, dtypes.uint32, - dtypes.int16, dtypes.int16, dtypes.int16, - dtypes.uint16, dtypes.uint16, dtypes.uint16, - dtypes.int8, dtypes.int8, dtypes.int8, - dtypes.uint8, dtypes.uint8, dtypes.uint8, - dtypes.uint8c, dtypes.uint8c, dtypes.uint8c -]; - -var add = dispatch( fcns, types, null, 3, 2, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var zbuf = new Float64Array( xbuf.length ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var z = ndarray( 'float64', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); - -xbuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -ybuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -zbuf = new Int32Array( xbuf.length ); - -x = ndarray( 'int32', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'int32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -z = ndarray( 'int32', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); diff --git a/examples/sin.js b/examples/sin.js deleted file mode 100644 index 8cd4871..0000000 --- a/examples/sin.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int8Array = require( '@stdlib/array-int8' ); -var sin = require( '@stdlib/math-base-special-sin' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/strided-dtypes' ); -var dispatch = require( './../lib' ); - -function apply( arrays, fcn ) { - var opts; - var xo; - var yo; - var sx; - var sy; - var sh; - var N; - var x; - var y; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - xo = x.order; - yo = y.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - v = fcn( x.get.apply( x, sx ) ); - - opts.order = yo; - sy = ind2sub( sh, i, opts ); - sy.push( v ); - y.set.apply( y, sy ); - } -} - -var fcns = [ - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply -]; - -var types = [ - dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float64, - dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.float64, - dtypes.uint32, dtypes.float64, - dtypes.int16, dtypes.float64, - dtypes.int16, dtypes.float32, - dtypes.uint16, dtypes.float64, - dtypes.uint16, dtypes.float32, - dtypes.int8, dtypes.float64, - dtypes.int8, dtypes.float32, - dtypes.uint8, dtypes.float64, - dtypes.uint8, dtypes.float32, - dtypes.uint8c, dtypes.float64, - dtypes.uint8c, dtypes.float32 -]; - -var data = [ - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin -]; - -var sine = dispatch( fcns, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); - -xbuf = new Int8Array( [ 1, 2, 3, 4, 5 ] ); -ybuf = new Float32Array( xbuf.length ); - -x = ndarray( 'int8', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'float32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); diff --git a/examples/unary.js b/examples/unary.js deleted file mode 100644 index e9c3fb4..0000000 --- a/examples/unary.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -var unary = require( '@stdlib/ndarray-base-unary' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var dispatch = require( './../lib' ); - -var types = [ 'float64', 'float64' ]; - -var data = [ - abs -]; - -var absolute = dispatch( unary, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -absolute( x, y ); -console.log( ybuf ); -// => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 5f280a1..c49a4e4 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..fa1e0f5 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@v0.2.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@v0.2.0-esm/index.mjs";function m(e,r,t,n,i,a,s,o,u){var d,m,l,f;for(d=a,l=0;l [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( 'invalid invocation. Insufficient arguments.' );\n\t\t\t}\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n"],"names":["indexOfTypes","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","i","j","dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","out","push","resolveEnum","types2enums","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","getDType","slice"],"mappings":";;i+BA6EA,SAASA,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,KAAgBE,EAAGI,GADdE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,CACN,CACD,OAAQ,CACT,CCMA,SAASU,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,oGAAqGZ,IAEnI,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,+EAAgFX,IAE9G,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,sFAAuFV,IAErH,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,6EAA8ET,IAE5G,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,+EAAgFR,IAE9G,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,+EAAgFP,IAG9G,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAO,8IAElB,GAAKb,IAAUG,EACd,MAAM,IAAIU,MAAO,8FAElB,GAAKR,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAO,qJAIlB,GADAT,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAO,gJAGnB,GAAKd,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAO,qGAGlB,OADAf,EA5GD,SAAsBA,GACrB,IAAIkB,EACAtB,EAGJ,IADAsB,EAAM,GACAtB,EAAI,EAAGA,EAAII,EAAMgB,OAAQpB,IAC9BsB,EAAIC,KAAMC,EAAapB,EAAOJ,KAE/B,OAAOsB,CACR,CAmGSG,CAAarB,GAgBrB,WACC,IAAIsB,EACAC,EACAC,EACAC,EACAC,EACAC,EACA/B,EAGJ,IADA4B,EAAOI,UAAUZ,UACHd,EAAQ,CACrB,GAAKsB,EAAOtB,EACX,MAAM,IAAIa,MAAO,+CAElB,MAAM,IAAIA,MAAO,0CACjB,CAGD,IAFAO,EAAS,GACTC,EAAS,GACH3B,EAAI,EAAGA,EAAIM,EAAON,IAAM,CAE7B,IAAMiC,EADNH,EAAIE,UAAWhC,IAEd,MAAKA,EAAIO,EACF,IAAIO,UAAWC,EAAQ,6EAA8Ee,IAErG,IAAIhB,UAAWC,EAAQ,8EAA+Ee,IAG9GJ,EAAOH,KAAMO,GACbH,EAAOJ,KAAMC,EAAaU,EAAUJ,IACpC,CAKD,IAHAD,EAAMzC,EAAcsB,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGkB,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAIb,UAAW,+GAIrBiB,EADIpB,GAGAR,EAAM0B,GAGNxB,EACJ0B,EAAGL,EAAQrB,EAAMwB,IAEjBE,EAAGL,GAEJ,GAAc,IAATlB,EACJ,OAAOkB,EAAQjB,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOkB,EAAOS,MAAO5B,EACrB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 291641d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Create an ndarray function interface which performs multiple dispatch. -* -* @module @stdlib/ndarray-dispatch -* -* @example -* var dispatch = require( '@stdlib/ndarray-dispatch' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/index_of_types.js b/lib/index_of_types.js deleted file mode 100644 index fda2297..0000000 --- a/lib/index_of_types.js +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found). -* -* ## Notes -* -* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types). -* - The function assumes that `x` is stored in row-major order. -* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`. -* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value. -* -* @private -* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension) -* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension) -* @param {ArrayLikeObject} x - input two-dimensional reference array -* @param {integer} strideX1 - `x` stride length along first dimension -* @param {integer} strideX2 - `x` stride length along second dimension -* @param {NonNegativeInteger} offsetX - `x` starting index -* @param {ArrayLikeObject} y - search array -* @param {integer} strideY - `y` stride length -* @param {NonNegativeInteger} offsetY - `y` starting index -* @returns {integer} row index (if found) and `-1` otherwise -* -* @example -* // Define a reference array to search: -* var types = [ -* 'float64', 'float64', 'float64', -* 'float32', 'float32', 'float32', -* 'uint32', 'uint32', 'float64', -* 'int32', 'int32', 'float64', -* 'uint16', 'uint16', 'float64', -* 'int16', 'int16', 'float64', -* 'uint8', 'uint8', 'float64', -* 'int8', 'int8', 'float64' -* ]; -* -* // Define reference array dimensions: -* var N = 8; // rows -* var M = 3; // columns -* -* // Define a search array: -* y1 = [ -* 'float32', 'float32', 'float32', -* ]; -* -* // Find the list of types: -* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 ); -* // returns 1 -* -// Define a search array: -* y2 = [ -* 'float32', 'float32', 'float64', -* ]; -* -* // Find the list of types: -* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 ); -* // returns -1 -*/ -function indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len - var ix; - var iy; - var i; - var j; - - // Search for the first row which matches `y`... - ix = offsetX; - for ( i = 0; i < N; i++ ) { - iy = offsetY; - for ( j = 0; j < M; j++ ) { - if ( x[ ix+(j*strideX2) ] !== y[ iy ] ) { - break; - } - iy += strideY; - } - // If we successfully iterated over all columns, then that means we've found a match... - if ( j === M ) { - return i; - } - ix += strideX1; - } - return -1; -} - - -// EXPORTS // - -module.exports = indexOfTypes; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 5f4bb5d..0000000 --- a/lib/main.js +++ /dev/null @@ -1,231 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isFunctionArray = require( '@stdlib/assert-is-function-array' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/string-format' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var resolveEnum = require( '@stdlib/ndarray-base-dtype-resolve-enum' ); -var indexOfTypes = require( './index_of_types.js' ); - - -// FUNCTIONS // - -/** -* Returns a list of data type enumeration constants. -* -* @private -* @param {Collection} types - list of types -* @returns {IntegerArray} list of data type enumeration constants -*/ -function types2enums( types ) { - var out; - var i; - - out = []; - for ( i = 0; i < types.length; i++ ) { - out.push( resolveEnum( types[ i ] ) ); - } - return out; -} - - -// MAIN // - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param {(FunctionArray|Function)} fcns - list of ndarray functions -* @param {Collection} types - one-dimensional list of ndarray argument data types -* @param {(Collection|null)} data - ndarray function data (e.g., callbacks) -* @param {PositiveInteger} nargs - total number of ndarray function interface arguments -* @param {NonNegativeInteger} nin - number of input ndarrays -* @param {NonNegativeInteger} nout - number of output ndarrays -* @throws {TypeError} first argument must be either a function or an array of functions -* @throws {TypeError} second argument must be an array-like object -* @throws {TypeError} third argument must be an array-like object or `null` -* @throws {Error} third and first arguments must have the same number of elements -* @throws {TypeError} fourth argument must be a positive integer -* @throws {TypeError} fifth argument must be a nonnegative integer -* @throws {TypeError} sixth argument must be a nonnegative integer -* @throws {Error} fourth argument must equal the specified number of input and output arrays -* @throws {Error} number of types must match the number of functions times the total number of array arguments for each function -* @throws {Error} interface must accept at least one input and/or output ndarray -* @returns {Function} ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function dispatch( fcns, types, data, nargs, nin, nout ) { - var narrays; - var nfcns; - var fcn; - - if ( isFunction( fcns ) ) { - fcn = fcns; - } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) ); - } - if ( !isCollection( types ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) ); - } - if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); - } - if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) ); - } - if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) ); - } - if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) ); - } - narrays = nin + nout; - if ( narrays === 0 ) { - throw new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' ); - } - if ( nargs !== narrays ) { - throw new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' ); - } - if ( fcn ) { - nfcns = types.length / narrays; - if ( !isInteger( nfcns ) ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); - } - } else { - nfcns = fcns.length; - if ( types.length !== nfcns*narrays ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); - } - } - if ( data && data.length !== nfcns ) { - throw new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' ); - } - types = types2enums( types ); - return dispatcher; - - /** - * ndarray function interface which performs multiple dispatch. - * - * @private - * @param {ndarrayLike} x - ndarray - * @param {...ndarrayLike} args - ndarray arguments - * @throws {Error} insufficient arguments - * @throws {Error} too many arguments - * @throws {TypeError} input array arguments must be ndarray-like objects - * @throws {TypeError} output array arguments must be ndarray-like objects - * @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types - * @returns {(ndarrayLike|Array|void)} destination array(s) - */ - function dispatcher() { - var arrays; - var dtypes; - var argc; - var idx; - var v; - var f; - var i; - - argc = arguments.length; - if ( argc !== nargs ) { - if ( argc < nargs ) { - throw new Error( 'invalid invocation. Insufficient arguments.' ); - } - throw new Error( 'invalid invocation. Too many arguments.' ); - } - arrays = []; - dtypes = []; - for ( i = 0; i < nargs; i++ ) { - v = arguments[ i ]; - if ( !isndarrayLike( v ) ) { - if ( i < nin ) { - throw new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) ); - } else { - throw new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) ); - } - } - arrays.push( v ); - dtypes.push( resolveEnum( getDType( v ) ) ); - } - // Resolve the ndarray function satisfying the input array types: - idx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len - - // Check whether we were able to successfully resolve an ndarray function: - if ( idx < 0 ) { - throw new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' ); - } - // Retrieve the ndarray function: - if ( fcn ) { - f = fcn; - } else { - f = fcns[ idx ]; - } - // Evaluate the ndarray function: - if ( data ) { - f( arrays, data[ idx ] ); - } else { - f( arrays ); - } - if ( nout === 1 ) { - return arrays[ narrays-1 ]; - } - if ( nout === 0 ) { - return; - } - return arrays.slice( nin ); - } -} - - -// EXPORTS // - -module.exports = dispatch; diff --git a/package.json b/package.json index 766ba14..0e51681 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.0", "description": "Create an ndarray function interface which performs multiple dispatch.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-collection": "^0.2.0", - "@stdlib/assert-is-function": "^0.2.0", - "@stdlib/assert-is-function-array": "^0.2.0", - "@stdlib/assert-is-integer": "^0.2.0", - "@stdlib/assert-is-ndarray-like": "^0.2.0", - "@stdlib/assert-is-nonnegative-integer": "^0.2.0", - "@stdlib/assert-is-positive-integer": "^0.2.0", - "@stdlib/ndarray-base-dtype-resolve-enum": "^0.2.0", - "@stdlib/ndarray-dtype": "^0.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.0", - "@stdlib/types": "^0.3.1" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.2.0", - "@stdlib/array-float64": "^0.2.0", - "@stdlib/array-int32": "^0.2.0", - "@stdlib/array-int8": "^0.2.0", - "@stdlib/array-uint8": "^0.2.0", - "@stdlib/math-base-assert-is-nan": "^0.2.0", - "@stdlib/math-base-special-abs": "^0.2.0", - "@stdlib/math-base-special-pow": "^0.2.0", - "@stdlib/math-base-special-sin": "^0.2.0", - "@stdlib/ndarray-base-buffer-dtype": "^0.2.0", - "@stdlib/ndarray-base-numel": "^0.2.0", - "@stdlib/ndarray-base-unary": "^0.1.0", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-dtypes": "^0.2.0", - "@stdlib/ndarray-ind2sub": "^0.1.1", - "@stdlib/strided-dtypes": "^0.2.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.0" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "ndarray", @@ -99,7 +26,6 @@ "multimethod", "multimethods" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..c2411e2 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/fixtures/binary.js b/test/fixtures/binary.js deleted file mode 100644 index a60dfa2..0000000 --- a/test/fixtures/binary.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Binary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @returns {number} sum -*/ -function binary( x, y ) { - return x + y; -} - - -// EXPORTS // - -module.exports = binary; diff --git a/test/fixtures/fill.js b/test/fixtures/fill.js deleted file mode 100644 index 41b2958..0000000 --- a/test/fixtures/fill.js +++ /dev/null @@ -1,76 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which fills one or more ndarrays. -* -* @private -* @param {*} value - fill value -* @returns {Function} ndarray function -*/ -function fill( value ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - */ - function ndarrayFcn( arrays ) { - var opts; - var sub; - var arr; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - opts = { - 'order': '' - }; - for ( j = 0; j < M; j++ ) { - arr = arrays[ j ]; - opts.order = arrays[ j ].order; - for ( i = 0; i < N; i++ ) { - sub = ind2sub( sh, i, opts ); - sub.push( value ); - arr.set.apply( arr, sub ); - } - } - } -} - - -// EXPORTS // - -module.exports = fill; diff --git a/test/fixtures/foreach.js b/test/fixtures/foreach.js deleted file mode 100644 index a426290..0000000 --- a/test/fixtures/foreach.js +++ /dev/null @@ -1,72 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function forEach( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - fcn.apply( null, args ); - } -} - - -// EXPORTS // - -module.exports = forEach; diff --git a/test/fixtures/map1n.js b/test/fixtures/map1n.js deleted file mode 100644 index 614196b..0000000 --- a/test/fixtures/map1n.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function which maps the return value of a callback to `N` arrays. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function map1N( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var v; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - v = fcn(); - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - sub.push( v ); - arrays[ j ].set.apply( arrays[ j ], sub ); - } - } -} - - -// EXPORTS // - -module.exports = map1N; diff --git a/test/fixtures/nullary.js b/test/fixtures/nullary.js deleted file mode 100644 index 4f22126..0000000 --- a/test/fixtures/nullary.js +++ /dev/null @@ -1,36 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Nullary callback. -* -* @private -* @returns {number} value -*/ -function nullary() { - return 3.0; -} - - -// EXPORTS // - -module.exports = nullary; diff --git a/test/fixtures/quaternary.js b/test/fixtures/quaternary.js deleted file mode 100644 index 548437b..0000000 --- a/test/fixtures/quaternary.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quaternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @returns {number} sum -*/ -function quaternary( x, y, z, w ) { - return x + y + z + w; -} - - -// EXPORTS // - -module.exports = quaternary; diff --git a/test/fixtures/quinary.js b/test/fixtures/quinary.js deleted file mode 100644 index 36068de..0000000 --- a/test/fixtures/quinary.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quinary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @param {number} u - input value -* @returns {number} sum -*/ -function quinary( x, y, z, w, u ) { - return x + y + z + w + u; -} - - -// EXPORTS // - -module.exports = quinary; diff --git a/test/fixtures/sum.js b/test/fixtures/sum.js deleted file mode 100644 index efdbb1b..0000000 --- a/test/fixtures/sum.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which computes the sum across one or more ndarrays. -* -* @private -* @param {Object} ctx - context -* @param {number} ctx.sum - initial sum -* @returns {Function} ndarray function -*/ -function wrapper( ctx ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - * @param {Function} [fcn] - callback - */ - function ndarrayFcn( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var f; - var i; - var j; - - if ( arguments.length > 1 ) { - f = fcn; - } - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - if ( f ) { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - ctx.sum += f.apply( null, args ); - } - } else { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - ctx.sum += arrays[ j ].get.apply( arrays[ j ], sub ); - } - } - } - } -} - - -// EXPORTS // - -module.exports = wrapper; diff --git a/test/fixtures/ternary.js b/test/fixtures/ternary.js deleted file mode 100644 index 0595d5f..0000000 --- a/test/fixtures/ternary.js +++ /dev/null @@ -1,39 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Ternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @returns {number} sum -*/ -function ternary( x, y, z ) { - return x + y + z; -} - - -// EXPORTS // - -module.exports = ternary; diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d6c2c8e..0000000 --- a/test/test.js +++ /dev/null @@ -1,363 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var fill = require( './fixtures/fill.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either a function or an array of functions as a first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( value, types, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object as a second argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided either an array-like object or `null` as a third argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - dispatch( unary, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a positive integer for a fourth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 0, - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a fifth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, value, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a sixth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, 1, value ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function array)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var fcns = [ unary, unary, unary ]; - var data = [ abs, abs, abs ]; - dispatch( fcns, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function argument)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs, abs, abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the length of `data` argument does not match the number of ndarray functions', function test( t ) { - var values; - var i; - - values = [ - [], - [ abs, abs ], - [ abs, abs, abs ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var fcns = [ unary ]; - dispatch( fcns, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the fourth argument is incompatible with the number of input and output ndarrays', function test( t ) { - var values; - var i; - - values = [ - 0, - 1, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of specified input and output ndarrays is zero', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var types = [ 'float64' ]; - dispatch( fill( 3 ), types, null, 1, 0, 0 ); - } -}); - -tape( 'the function returns an ndarray function interface', function test( t ) { - var types; - var data; - var f; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - f = dispatch( unary, types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ unary ], types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( fill( 3 ), types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ fill( 3 ) ], types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.two_arrays.js b/test/test.two_arrays.js deleted file mode 100644 index 16eb61b..0000000 --- a/test/test.two_arrays.js +++ /dev/null @@ -1,814 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var dtype = require( '@stdlib/ndarray-base-buffer-dtype' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var forEach = require( './fixtures/foreach.js' ); -var map1N = require( './fixtures/map1n.js' ); -var fill = require( './fixtures/fill.js' ); -var sum = require( './fixtures/sum.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the first argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var ybuf = new Float64Array( 10 ); - var y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( value, y ); - }; - } -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the second argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var xbuf = new Float64Array( 10 ); - var x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( x, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided insufficient arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var f; - var x; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [], - [ x ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided too many arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var ybuf; - var f; - var x; - var y; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [ x, y, y ], - [ x, y, y, y ], - [ x, y, y, y, y ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if unable to resolve a ndarray function supporting the provided array argument data types', function test( t ) { - var values; - var types; - var data; - var xbuf; - var fcn; - var x; - var i; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ abs, abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 4 ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - values = [ - new Uint8Array( 4 ), - new Int32Array( 4 ), - [ 0, 0, 0, 0 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided an array having data type: ' + dtype( values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var y = ndarray( dtype( value ), value, [ value.length ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - }; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only input arrays)', function test( t ) { - var types; - var xbuf; - var ybuf; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only output arrays)', function test( t ) { - var expected; - var types; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only input arrays)', function test( t ) { - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var ctx; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcns = [ - sum( ctx ), - sum( ctx ) - ]; - fcn = dispatch( fcns, types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only output arrays)', function test( t ) { - var expected; - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcns = [ - fill( 3.0 ), - fill( 4.0 ) - ]; - fcn = dispatch( fcns, types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - - fcn = dispatch( forEach, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - - fcn = dispatch( map1N, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - fcns = [ - forEach, - forEach - ]; - fcn = dispatch( fcns, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - fcns = [ - map1N, - map1N - ]; - fcn = dispatch( fcns, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - fcns = [ - unary, - unary - ]; - fcn = dispatch( fcns, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which returns one or more output arrays, if one or more output arrays is specified, and otherwise returns `undefined`', function test( t ) { - var types; - var data; - var xbuf; - var ybuf; - var out; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - // No output arrays... - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, void 0, 'returns expected value' ); - - // One output array... - data = [ - abs, - abs - ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - fcn = dispatch( fill( 3.0 ), types, null, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - // Two output arrays... - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.end(); -}); From 5d121d3b2b5a0f2f6234e2bc44133004b4155ba2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 06:34:12 +0000 Subject: [PATCH 062/109] Update README.md for ESM bundle v0.2.0 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e36a34e..e2cd7b1 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ limitations under the License. ## Usage ```javascript -import dispatch from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dispatch@esm/index.mjs'; +import dispatch from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dispatch@v0.2.0-esm/index.mjs'; ``` #### dispatch( fcns, types, data, nargs, nin, nout ) @@ -242,7 +242,7 @@ import unary from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-unary@esm/ import ndarray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs'; import abs from 'https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs'; import Float64Array from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-float64@esm/index.mjs'; -import dispatch from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dispatch@esm/index.mjs'; +import dispatch from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dispatch@v0.2.0-esm/index.mjs'; var types = [ 'float64', 'float64' ]; From f950b454fca599ba2a2b20fda191e71707e78e4f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 06:34:13 +0000 Subject: [PATCH 063/109] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e2cd7b1..01683ca 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,11 @@ limitations under the License. ## Usage +```javascript +import dispatch from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dispatch@esm/index.mjs'; +``` +The previous example will load the latest bundled code from the esm branch. Alternatively, you may load a specific version by loading the file from one of the [tagged bundles](https://github.com/stdlib-js/ndarray-dispatch/tags). For example, + ```javascript import dispatch from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dispatch@v0.2.0-esm/index.mjs'; ``` @@ -242,7 +247,7 @@ import unary from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-unary@esm/ import ndarray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs'; import abs from 'https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs'; import Float64Array from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-float64@esm/index.mjs'; -import dispatch from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dispatch@v0.2.0-esm/index.mjs'; +import dispatch from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dispatch@esm/index.mjs'; var types = [ 'float64', 'float64' ]; From bb9888f2bace7ad930fc3430b33b28dfcdd00fb1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 19:56:51 +0000 Subject: [PATCH 064/109] Transform error messages --- lib/main.js | 34 +++++++++++++++++----------------- package.json | 2 +- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/main.js b/lib/main.js index 5f4bb5d..4648598 100644 --- a/lib/main.js +++ b/lib/main.js @@ -27,7 +27,7 @@ var isFunctionArray = require( '@stdlib/assert-is-function-array' ); var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var getDType = require( '@stdlib/ndarray-dtype' ); var resolveEnum = require( '@stdlib/ndarray-base-dtype-resolve-enum' ); var indexOfTypes = require( './index_of_types.js' ); @@ -112,43 +112,43 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { if ( isFunction( fcns ) ) { fcn = fcns; } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) ); + throw new TypeError( format( '0jr5d', fcns ) ); } if ( !isCollection( types ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) ); + throw new TypeError( format( '0jr2y', types ) ); } if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); + throw new TypeError( format( '0jr5e', data ) ); } if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) ); + throw new TypeError( format( '0jr5f', nargs ) ); } if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) ); + throw new TypeError( format( '0jr5X', nin ) ); } if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) ); + throw new TypeError( format( '0jr5g', nout ) ); } narrays = nin + nout; if ( narrays === 0 ) { - throw new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' ); + throw new Error( format('0jr0h') ); } if ( nargs !== narrays ) { - throw new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' ); + throw new Error( format('0jr0i') ); } if ( fcn ) { nfcns = types.length / narrays; if ( !isInteger( nfcns ) ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format('0jr0j') ); } } else { nfcns = fcns.length; if ( types.length !== nfcns*narrays ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format('0jr0j') ); } } if ( data && data.length !== nfcns ) { - throw new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' ); + throw new Error( format('0jr0k') ); } types = types2enums( types ); return dispatcher; @@ -178,9 +178,9 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { argc = arguments.length; if ( argc !== nargs ) { if ( argc < nargs ) { - throw new Error( 'invalid invocation. Insufficient arguments.' ); + throw new Error( format('0jr0l') ); } - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('0jr0m') ); } arrays = []; dtypes = []; @@ -188,9 +188,9 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { v = arguments[ i ]; if ( !isndarrayLike( v ) ) { if ( i < nin ) { - throw new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) ); + throw new TypeError( format( '0jr5h', v ) ); } else { - throw new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) ); + throw new TypeError( format( '0jr5i', v ) ); } } arrays.push( v ); @@ -201,7 +201,7 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { // Check whether we were able to successfully resolve an ndarray function: if ( idx < 0 ) { - throw new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' ); + throw new TypeError( format('0jr0n') ); } // Retrieve the ndarray function: if ( fcn ) { diff --git a/package.json b/package.json index e7a75cb..118edae 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/assert-is-positive-integer": "^0.2.1", "@stdlib/ndarray-base-dtype-resolve-enum": "^0.2.1", "@stdlib/ndarray-dtype": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, From 5557cb5bc9faf414f9b468a93fa764de966c12bc Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 21:19:37 +0000 Subject: [PATCH 065/109] Remove files --- index.d.ts | 334 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6516 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index c49a4e4..0000000 --- a/index.d.ts +++ /dev/null @@ -1,334 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* ndarray function. -* -* @param arrays - array containing input and output ndarrays -* @param data - ndarray function data (e.g., a callback) -* -* @example -* var numel = require( '@stdlib/ndarray-base-numel' ); -* var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -* -* function ndarrayFcn( arrays, fcn ) { -* var xord; -* var yord; -* var opts; -* var sub; -* var sh; -* var N; -* var x; -* var y; -* var v; -* var i; -* -* x = arrays[ 0 ]; -* y = arrays[ 1 ]; -* sh = x.shape; -* N = numel( sh ); -* if ( N <= 0 ) { -* return; -* } -* xord = x.order; -* yord = y.order; -* opts = {}; -* opts.order = xord; -* for ( i = 0; i < N; i++ ) { -* // Convert a linear index to subscripts: -* opts.order = xord; -* sub = ind2sub( sh, i, opts ); -* -* // Retrieve an element from `x`: -* v = x.get.apply( x, sub ); -* -* // Convert a linear index to subscripts: -* opts.order = yord; -* sub = ind2sub( sh, i, opts ); -* -* // Append the result of applying the callback: -* sub.push( fcn( v ) ); -* -* // Assign the result to an element in `y`: -* y.set.apply( y, sub ); -* } -* } -*/ -type ndarrayFcn = ( arrays: Array, data?: any ) => void; - -/** -* Interface describing an ndarray function dispatcher. -*/ -interface Dispatcher { - /** - * Invokes an ndarray function based on the provided array data type(s). - * - * @param x - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array - * - * @example - * var nullary = require( '@stdlib/ndarray-base-nullary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function value() { - * return 3.14; - * } - * - * var types = [ 'float64' ]; - * var data = [ value ]; - * - * var fcn = dispatch( nullary, types, data, 1, 0, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( 5 ); - * var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x ); - * // xbuf => [ 3.14, 3.14, 3.14, 3.14, 3.14 ] - */ - ( x: ndarray ): ndarray | void; - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var unary = require( '@stdlib/ndarray-base-unary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * var abs = require( '@stdlib/math-base-special-abs' ); - * - * var types = [ 'float64', 'float64' ]; - * var data = [ abs ]; - * - * var fcn = dispatch( unary, types, data, 2, 1, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - * var ybuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y ); - * // ybuf => [ 1.0, 2.0, 3.0 ] - */ - ( x: ndarray, y: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var ternary = require( '@stdlib/ndarray-base-ternary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function add2( x, y ) { - * return x + y; - * } - * - * var types = [ 'float64', 'float64', 'float64' ]; - * var data = [ add2 ]; - * - * var fcn = dispatch( ternary, types, data, 3, 2, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z ); - * // zbuf => [ 2.0, 4.0, 6.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quaternary = require( '@stdlib/ndarray-base-quaternary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function add3( x, y, z ) { - * return x + y + z; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add3 ]; - * - * var fcn = dispatch( quaternary, types, data, 4, 3, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w ); - * // wbuf => [ 3.0, 6.0, 9.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @param args - ndarray arguments - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quinary = require( '@stdlib/ndarray-base-quinary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function add4( x, y, z, w ) { - * return x + y + z + w; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add4 ]; - * - * var fcn = dispatch( quinary, types, data, 5, 4, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ubuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var u = ndarray( 'float64', ubuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w, u ); - * // ubuf => [ 4.0, 8.0, 12.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray, ...args: Array ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures -} - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param fcns - list of ndarray functions -* @param types - one-dimensional list of ndarray argument data types -* @param data - ndarray function data (e.g., callbacks) -* @param nargs - total number of ndarray function interface arguments -* @param nin - number of input ndarrays -* @param nout - number of output ndarrays -* @throws first argument must be either a function or an array of functions -* @throws second argument must be an array-like object -* @throws third argument must be an array-like object or `null` -* @throws third and first arguments must have the same number of elements -* @throws fourth argument must be a positive integer -* @throws fifth argument must be a nonnegative integer -* @throws sixth argument must be a nonnegative integer -* @throws fourth argument must equal the specified number of input and output arrays -* @throws number of types must match the number of functions times the total number of array arguments for each function -* @throws interface must accept at least one input and/or output ndarray -* @returns ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var fcn = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* fcn( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function dispatch( fcns: ndarrayFcn | ArrayLike, types: ArrayLike, data: ArrayLike | null, nargs: number, nin: number, nout: number ): Dispatcher; - - -// EXPORTS // - -export = dispatch; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index fa1e0f5..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import{isPrimitive as e}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.0-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@v0.2.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@v0.2.0-esm/index.mjs";function m(e,r,t,n,i,a,s,o,u){var d,m,l,f;for(d=a,l=0;l [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( 'invalid invocation. Insufficient arguments.' );\n\t\t\t}\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n"],"names":["indexOfTypes","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","i","j","dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","out","push","resolveEnum","types2enums","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","getDType","slice"],"mappings":";;i+BA6EA,SAASA,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,KAAgBE,EAAGI,GADdE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,CACN,CACD,OAAQ,CACT,CCMA,SAASU,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,oGAAqGZ,IAEnI,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,+EAAgFX,IAE9G,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,sFAAuFV,IAErH,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,6EAA8ET,IAE5G,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,+EAAgFR,IAE9G,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,+EAAgFP,IAG9G,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAO,8IAElB,GAAKb,IAAUG,EACd,MAAM,IAAIU,MAAO,8FAElB,GAAKR,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAO,qJAIlB,GADAT,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAO,gJAGnB,GAAKd,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAO,qGAGlB,OADAf,EA5GD,SAAsBA,GACrB,IAAIkB,EACAtB,EAGJ,IADAsB,EAAM,GACAtB,EAAI,EAAGA,EAAII,EAAMgB,OAAQpB,IAC9BsB,EAAIC,KAAMC,EAAapB,EAAOJ,KAE/B,OAAOsB,CACR,CAmGSG,CAAarB,GAgBrB,WACC,IAAIsB,EACAC,EACAC,EACAC,EACAC,EACAC,EACA/B,EAGJ,IADA4B,EAAOI,UAAUZ,UACHd,EAAQ,CACrB,GAAKsB,EAAOtB,EACX,MAAM,IAAIa,MAAO,+CAElB,MAAM,IAAIA,MAAO,0CACjB,CAGD,IAFAO,EAAS,GACTC,EAAS,GACH3B,EAAI,EAAGA,EAAIM,EAAON,IAAM,CAE7B,IAAMiC,EADNH,EAAIE,UAAWhC,IAEd,MAAKA,EAAIO,EACF,IAAIO,UAAWC,EAAQ,6EAA8Ee,IAErG,IAAIhB,UAAWC,EAAQ,8EAA+Ee,IAG9GJ,EAAOH,KAAMO,GACbH,EAAOJ,KAAMC,EAAaU,EAAUJ,IACpC,CAKD,IAHAD,EAAMzC,EAAcsB,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGkB,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAIb,UAAW,+GAIrBiB,EADIpB,GAGAR,EAAM0B,GAGNxB,EACJ0B,EAAGL,EAAQrB,EAAMwB,IAEjBE,EAAGL,GAEJ,GAAc,IAATlB,EACJ,OAAOkB,EAAQjB,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOkB,EAAOS,MAAO5B,EACrB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index c2411e2..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 3617c218c810e34217f41e01431d2a9c8e82002a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 21:19:59 +0000 Subject: [PATCH 066/109] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 61 +- SECURITY.md | 5 - benchmark/benchmark.dispatch_size.js | 156 - benchmark/benchmark.js | 81 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 87 - docs/types/test.ts | 641 --- examples/add.js | 121 - examples/sin.js | 142 - examples/unary.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/index_of_types.js | 106 - lib/main.js | 231 - package.json | 79 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/binary.js | 38 - test/fixtures/fill.js | 76 - test/fixtures/foreach.js | 72 - test/fixtures/map1n.js | 74 - test/fixtures/nullary.js | 36 - test/fixtures/quaternary.js | 40 - test/fixtures/quinary.js | 41 - test/fixtures/sum.js | 98 - test/fixtures/ternary.js | 39 - test/test.js | 363 -- test/test.two_arrays.js | 814 ---- 56 files changed, 4876 insertions(+), 6746 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.dispatch_size.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/add.js delete mode 100644 examples/sin.js delete mode 100644 examples/unary.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/index_of_types.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/fixtures/binary.js delete mode 100644 test/fixtures/fill.js delete mode 100644 test/fixtures/foreach.js delete mode 100644 test/fixtures/map1n.js delete mode 100644 test/fixtures/nullary.js delete mode 100644 test/fixtures/quaternary.js delete mode 100644 test/fixtures/quinary.js delete mode 100644 test/fixtures/sum.js delete mode 100644 test/fixtures/ternary.js delete mode 100644 test/test.js delete mode 100644 test/test.two_arrays.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ac0b7cd..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 5e92c3e..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2b4fac7..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '43 7 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -304,7 +295,7 @@ console.log( ybuf ); ## 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. +This package is part of [stdlib][stdlib], a standard library 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]. @@ -367,11 +358,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-dispatch/main/LICENSE -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.dispatch_size.js b/benchmark/benchmark.dispatch_size.js deleted file mode 100644 index 15805ba..0000000 --- a/benchmark/benchmark.dispatch_size.js +++ /dev/null @@ -1,156 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib/main.js' ); - - -// FUNCTIONS // - -/** -* Evaluates the identity function. -* -* @private -* @param {*} v - value -* @returns {*} input value -*/ -function identity( v ) { - return v; -} - -/** -* Dummy function which throws an error. -* -* @private -* @throws {Error} unexpected error -*/ -function throwError() { - throw new Error( 'unexpected error' ); -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} size - dispatch size -* @returns {Function} benchmark function -*/ -function createBenchmark( size ) { - var types; - var data; - var fcn; - var x; - var y; - var t; - var i; - - types = []; - - // Create dummy types... - for ( i = 0; i < (size-1)*2; i += 2 ) { - t = 'foo' + i; - types.push( t ); - types.push( t ); - } - // Append test types: - types.push( 'float64' ); - types.push( 'float64' ); - - // Define a list of callbacks: - data = []; - for ( i = 0; i < size-1; i++ ) { - data.push( throwError ); - } - // Append a test callback: - data.push( identity ); - - // Create the dispatcher: - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - // Create sample arrays: - x = new Float64Array( 1 ); - y = new Float64Array( x.length ); - - x = ndarray( 'float64', x, [ 1 ], [ 1 ], 0, 'row-major' ); - y = ndarray( 'float64', y, [ 1 ], [ 1 ], 0, 'row-major' ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var z; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x.data[ 0 ] = i; - z = fcn( x, y ); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var size; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - size = pow( 2, i ); - f = createBenchmark( size ); - bench( pkg+':size='+size, f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 3c6f450..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::fcns_array', function benchmark( b ) { - var types; - var fcns; - var data; - var out; - var i; - - fcns = [ unary ]; - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( fcns, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::fcn_arg', function benchmark( b ) { - var types; - var data; - var out; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( unary, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0aae4af..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch" -%% click B href "https://github.com/stdlib-js/ndarray-dispatch/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-dispatch/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-dispatch/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-dispatch/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-dispatch/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch -[production-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 1295a44..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import dispatch from '../docs/types/index'; -export = dispatch; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7fb29cb..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var y=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var b=y(function(D,w){ -function k(i,r,e,u,f,m,n,o,l){var h,t,s,a;for(h=m,s=0;s [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( 'invalid invocation. Insufficient arguments.' );\n\t\t\t}\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = dispatch;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an ndarray function interface which performs multiple dispatch.\n*\n* @module @stdlib/ndarray-dispatch\n*\n* @example\n* var dispatch = require( '@stdlib/ndarray-dispatch' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var unary = require( '@stdlib/ndarray-base-unary' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var types = [\n* 'float64', 'float64'\n* ];\n*\n* var data = [\n* abs\n* ];\n*\n* var absolute = dispatch( unary, types, data, 2, 1, 1 );\n*\n* // ...\n*\n* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] );\n* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] );\n*\n* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' );\n* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' );\n*\n* absolute( x, y );\n* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA6EA,SAASC,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,EAAU,CAClF,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,CAAU,IAAME,EAAGI,CAAG,EADjBE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,CACP,CACA,MAAO,EACR,CAKAL,EAAO,QAAUC,ICzGjB,IAAAc,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAoB,QAAS,oCAAqC,EAClEC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAkB,QAAS,kCAAmC,EAC9DC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAc,QAAS,yCAA0C,EACjEC,EAAe,IAYnB,SAASC,EAAaC,EAAQ,CAC7B,IAAIC,EACAC,EAGJ,IADAD,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIF,EAAM,OAAQE,IAC9BD,EAAI,KAAMJ,EAAaG,EAAOE,CAAE,CAAE,CAAE,EAErC,OAAOD,CACR,CAqDA,SAASE,EAAUC,EAAMJ,EAAOK,EAAMC,EAAOC,EAAKC,EAAO,CACxD,IAAIC,EACAC,EACAC,EAEJ,GAAKnB,EAAYY,CAAK,EACrBO,EAAMP,UACK,CAACb,EAAiBa,CAAK,EAClC,MAAM,IAAI,UAAWT,EAAQ,oGAAqGS,CAAK,CAAE,EAE1I,GAAK,CAACX,EAAcO,CAAM,EACzB,MAAM,IAAI,UAAWL,EAAQ,+EAAgFK,CAAM,CAAE,EAEtH,GAAK,CAACP,EAAcY,CAAK,GAAKA,IAAS,KACtC,MAAM,IAAI,UAAWV,EAAQ,sFAAuFU,CAAK,CAAE,EAE5H,GAAK,CAAChB,EAAmBiB,CAAM,EAC9B,MAAM,IAAI,UAAWX,EAAQ,6EAA8EW,CAAM,CAAE,EAEpH,GAAK,CAAClB,EAAsBmB,CAAI,EAC/B,MAAM,IAAI,UAAWZ,EAAQ,+EAAgFY,CAAI,CAAE,EAEpH,GAAK,CAACnB,EAAsBoB,CAAK,EAChC,MAAM,IAAI,UAAWb,EAAQ,+EAAgFa,CAAK,CAAE,EAGrH,GADAC,EAAUF,EAAMC,EACXC,IAAY,EAChB,MAAM,IAAI,MAAO,4IAA6I,EAE/J,GAAKH,IAAUG,EACd,MAAM,IAAI,MAAO,4FAA6F,EAE/G,GAAKE,GAEJ,GADAD,EAAQV,EAAM,OAASS,EAClB,CAACnB,EAAWoB,CAAM,EACtB,MAAM,IAAI,MAAO,8IAA+I,UAGjKA,EAAQN,EAAK,OACRJ,EAAM,SAAWU,EAAMD,EAC3B,MAAM,IAAI,MAAO,8IAA+I,EAGlK,GAAKJ,GAAQA,EAAK,SAAWK,EAC5B,MAAM,IAAI,MAAO,mGAAoG,EAEtH,OAAAV,EAAQD,EAAaC,CAAM,EACpBY,EAeP,SAASA,GAAa,CACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EAGJ,GADAa,EAAO,UAAU,OACZA,IAAST,EACb,MAAKS,EAAOT,EACL,IAAI,MAAO,6CAA8C,EAE1D,IAAI,MAAO,yCAA0C,EAI5D,IAFAO,EAAS,CAAC,EACVC,EAAS,CAAC,EACJZ,EAAI,EAAGA,EAAII,EAAOJ,IAAM,CAE7B,GADAe,EAAI,UAAWf,CAAE,EACZ,CAACR,EAAeuB,CAAE,EACtB,MAAKf,EAAIK,EACF,IAAI,UAAWZ,EAAQ,6EAA8EsB,CAAE,CAAE,EAEzG,IAAI,UAAWtB,EAAQ,8EAA+EsB,CAAE,CAAE,EAGlHJ,EAAO,KAAMI,CAAE,EACfH,EAAO,KAAMjB,EAAaD,EAAUqB,CAAE,CAAE,CAAE,CAC3C,CAKA,GAHAD,EAAMlB,EAAcY,EAAOD,EAAST,EAAOS,EAAS,EAAG,EAAGK,EAAQ,EAAG,CAAE,EAGlEE,EAAM,EACV,MAAM,IAAI,UAAW,6GAA8G,EAcpI,GAXKL,EACJO,EAAIP,EAEJO,EAAId,EAAMY,CAAI,EAGVX,EACJa,EAAGL,EAAQR,EAAMW,CAAI,CAAE,EAEvBE,EAAGL,CAAO,EAENL,IAAS,EACb,OAAOK,EAAQJ,EAAQ,CAAE,EAE1B,GAAKD,IAAS,EAGd,OAAOK,EAAO,MAAON,CAAI,CAC1B,CACD,CAKApB,EAAO,QAAUgB,IC9KjB,IAAIgB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_index_of_types", "__commonJSMin", "exports", "module", "indexOfTypes", "N", "M", "x", "strideX1", "strideX2", "offsetX", "y", "strideY", "offsetY", "ix", "iy", "i", "j", "require_main", "__commonJSMin", "exports", "module", "isNonNegativeInteger", "isPositiveInteger", "isInteger", "isFunctionArray", "isFunction", "isCollection", "isndarrayLike", "format", "getDType", "resolveEnum", "indexOfTypes", "types2enums", "types", "out", "i", "dispatch", "fcns", "data", "nargs", "nin", "nout", "narrays", "nfcns", "fcn", "dispatcher", "arrays", "dtypes", "argc", "idx", "v", "f", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 02fe150..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,87 +0,0 @@ - -{{alias}}( fcns, types, data, nargs, nin, nout ) - Returns an ndarray function interface which performs multiple dispatch. - - An ndarray function interface has the following signature: - - f( x, y, ... ) - - where - - - x: ndarray. - - y: ndarray. - - ...: additional ndarrays. - - The number of parameters is derived from `nargs`, the number of input - ndarrays is derived from `nin`, and the number of output ndarrays is derived - from `nout`. - - Parameters - ---------- - fcns: Function|ArrayLikeObject - List of ndarray functions. An ndarray function should have the following - signature: - - f( arrays, data ) - - where - - - arrays: array containing input and output ndarrays. - - data: ndarray function data (e.g., a callback). - - For convenience, a single ndarray function may be provided which will be - invoked whenever the ndarray argument data types match a sequence of - types in `types`. Providing a single ndarray function is particularly - convenient for the case where, regardless of array data types, - traversing arrays remains the same, but the ndarray function `data` - differs (e.g., callbacks which differ based on the array data types). - - types: ArrayLikeObject - One-dimensional list of ndarray argument data types. - - data: ArrayLikeObject|null - ndarray function data (e.g., callbacks). If `null`, a returned ndarray - function interface does **not** provide a `data` argument to an invoked - ndarray function. - - nargs: integer - Total number of ndarray function interface arguments. - - nin: integer - Number of input ndarrays. - - nout: integer - Number of output ndarrays. - - Returns - ------- - fcn: Function - ndarray function interface. - - Examples - -------- - // Define ndarray argument data types: - > var t = [ 'float64', 'float64', 'float32', 'float32' ]; - - // Define a list of ndarray function data (callbacks): - > var d = [ {{alias:@stdlib/math/base/special/abs}}, {{alias:@stdlib/math/base/special/absf}} ]; - - // Create an ndarray function interface for applying unary callbacks: - > var f = {{alias}}( {{alias:@stdlib/ndarray/base/unary}}, t, d, 2, 1, 1 ); - - // Create an input ndarray: - > var xbuf = new {{alias:@stdlib/array/float64}}( [ -1.0, -2.0, -3.0, -4.0 ] ); - > var x = {{alias:@stdlib/ndarray/ctor}}( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Create an output ndarray: - > var ybuf = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 0.0, 0.0 ] ); - > var y = {{alias:@stdlib/ndarray/ctor}}( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Compute the element-wise absolute value: - > f( x, y ); - > ybuf - [ 1.0, 2.0, 3.0, 4.0 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 3cba031..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,641 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable max-lines */ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import dispatch = require( './index' ); - - -// FUNCTIONS // - -/** -* Nullary callback. -* -* @return input value -*/ -function nullary(): any { - return 5.0; -} - -/** -* Unary callback. -* -* @param x - input value -* @return input value -*/ -function unary( x: any ): any { - return x; -} - -/** -* Binary callback. -* -* @param x - input value -* @param y - input value -* @return output value -*/ -function binary( x: number, y: number ): number { - return x + y; -} - -/** -* Ternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @return output value -*/ -function ternary( x: number, y: number, z: number ): number { - return x + y + z; -} - -/** -* Quaternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @param w - input value -* @return output value -*/ -function quaternary( x: number, y: number, z: number, w: number ): number { - return x + y + z + w; -} - -/** -* Mock `ind2sub` function. -* -* @param shape - dimensions -* @param idx - linear index -* @param opts - options -* @return subscripts -*/ -function ind2sub( shape: ArrayLike, idx: number, opts?: any ): Array { - let out; - let i; - - out = []; - if ( typeof opts === 'object' && opts !== null && opts.order === 'row-major' ) { no-unsafe-any - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } else { - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } - return out; -} - -/** -* Mock ndarray function. -* -* @param arrays - ndarrays -* @param fcn - callback -*/ -function ndarrayFcn( arrays: Array, fcn: ( x: any ) => any ): void { - let xord; - let yord; - let opts; - let sub; - let sh; - let N; - let x; - let y; - let v; - let i; - - x = arrays[ 0 ]; - y = arrays[ 1 ]; - sh = x.shape; - if ( sh.length === 0 ) { - return; - } - N = 1; - for ( i = 0; i < sh.length; i += 1 ) { - N *= sh[ i ]; - } - xord = x.order; - yord = y.order; - opts = { - 'order': '' - }; - opts.order = xord; - for ( i = 0; i < N; i += 1 ) { - // Convert a linear index to subscripts: - opts.order = xord; - sub = ind2sub( sh, i, opts ); - - // Retrieve an element from `x`: - v = x.get.apply( x, sub ); - - // Convert a linear index to subscripts: - opts.order = yord; - sub = ind2sub( sh, i, opts ); - - // Append the result of applying the callback: - sub[ sub.length ] = fcn( v ) as number; - - // Assign the result to an element in `y`: - y.set.apply( y, sub ); - } -} - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a dispatch function... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, 1 ); // $ExpectType Dispatcher - dispatch( [ ndarrayFcn ], types, data, 2, 1, 1 ); // $ExpectType Dispatcher -} - -// The compiler throws an error if the function is provided a first argument which is not either an ndarray function or an array-like object containing ndarray functions... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( '10', types, data, 2, 1, 1 ); // $ExpectError - dispatch( 10, types, data, 2, 1, 1 ); // $ExpectError - dispatch( true, types, data, 2, 1, 1 ); // $ExpectError - dispatch( false, types, data, 2, 1, 1 ); // $ExpectError - dispatch( null, types, data, 2, 1, 1 ); // $ExpectError - dispatch( undefined, types, data, 2, 1, 1 ); // $ExpectError - dispatch( [ '1' ], types, data, 2, 1, 1 ); // $ExpectError - dispatch( {}, types, data, 2, 1, 1 ); // $ExpectError - dispatch( ( x: number ): number => x, types, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object... -{ - const data = [ unary ]; - - dispatch( ndarrayFcn, 10, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, true, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, false, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, null, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, undefined, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, {}, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object or null... -{ - const types = [ 'float64', 'float64' ]; - - dispatch( ndarrayFcn, types, 10, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, true, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, false, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, undefined, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, {}, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, '10', 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, true, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, false, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, null, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, undefined, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, [ '1' ], 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, {}, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, ( x: number ): number => x, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, '10', 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, true, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, false, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, null, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, undefined, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, [ '1' ], 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, {}, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, ( x: number ): number => x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, '10' ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, true ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, false ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, null ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, undefined ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, [ '1' ] ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, {} ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch(); // $ExpectError - dispatch( ndarrayFcn ); // $ExpectError - dispatch( ndarrayFcn, types ); // $ExpectError - dispatch( ndarrayFcn, types, data ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, 1, 0 ); // $ExpectError -} - -// The function returns a dispatch function... -{ - const x = array(); - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const t1 = [ 'float64' ]; - const d1 = [ nullary ]; - const f1 = dispatch( ndarrayFcn, t1, d1, 1, 1, 0 ); - f1( x ); // $ExpectType void | ndarray - - const t2 = [ 'float64', 'float64' ]; - const d2 = [ unary ]; - const f2 = dispatch( ndarrayFcn, t2, d2, 2, 1, 1 ); - f2( x, y ); // $ExpectType void | ndarray - - const t3 = [ 'float64', 'float64', 'float64' ]; - const d3 = [ binary ]; - const f3 = dispatch( ndarrayFcn, t3, d3, 3, 2, 1 ); - f3( x, y, z ); // $ExpectType void | ndarray - - const t4 = [ 'float64', 'float64', 'float64', 'float64' ]; - const d4 = [ ternary ]; - const f4 = dispatch( ndarrayFcn, t4, d4, 4, 3, 1 ); - f4( x, y, z, w ); // $ExpectType void | ndarray - - const t5 = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const d5 = [ quaternary ]; - const f5 = dispatch( ndarrayFcn, t5, d5, 5, 4, 1 ); - f5( x, y, z, w, u ); // $ExpectType void | ndarray -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (1 ndarray)... -{ - const types = [ 'float64' ]; - const data = [ nullary ]; - - const f = dispatch( ndarrayFcn, types, data, 1, 0, 1 ); - f( '10' ); // $ExpectError - f( 10 ); // $ExpectError - f( true ); // $ExpectError - f( false ); // $ExpectError - f( null ); // $ExpectError - f( undefined ); // $ExpectError - f( [ '1' ] ); // $ExpectError - f( {} ); // $ExpectError - f( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( 10, y ); // $ExpectError - f( '10', y ); // $ExpectError - f( true, y ); // $ExpectError - f( false, y ); // $ExpectError - f( null, y ); // $ExpectError - f( undefined, y ); // $ExpectError - f( [ '1' ], y ); // $ExpectError - f( {}, y ); // $ExpectError - f( ( x: number ): number => x, y ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const x = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( x, 10 ); // $ExpectError - f( x, '10' ); // $ExpectError - f( x, true ); // $ExpectError - f( x, false ); // $ExpectError - f( x, null ); // $ExpectError - f( x, undefined ); // $ExpectError - f( x, [ '1' ] ); // $ExpectError - f( x, {} ); // $ExpectError - f( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( 10, y, z ); // $ExpectError - f( '10', y, z ); // $ExpectError - f( true, y, z ); // $ExpectError - f( false, y, z ); // $ExpectError - f( null, y, z ); // $ExpectError - f( undefined, y, z ); // $ExpectError - f( [ '1' ], y, z ); // $ExpectError - f( {}, y, z ); // $ExpectError - f( ( x: number ): number => x, y, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, 10, z ); // $ExpectError - f( x, '10', z ); // $ExpectError - f( x, true, z ); // $ExpectError - f( x, false, z ); // $ExpectError - f( x, null, z ); // $ExpectError - f( x, undefined, z ); // $ExpectError - f( x, [ '1' ], z ); // $ExpectError - f( x, {}, z ); // $ExpectError - f( x, ( x: number ): number => x, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, y, '10' ); // $ExpectError - f( x, y, true ); // $ExpectError - f( x, y, false ); // $ExpectError - f( x, y, null ); // $ExpectError - f( x, y, undefined ); // $ExpectError - f( x, y, [ '1' ] ); // $ExpectError - f( x, y, {} ); // $ExpectError - f( x, y, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( 10, y, z, w ); // $ExpectError - f( '10', y, z, w ); // $ExpectError - f( true, y, z, w ); // $ExpectError - f( false, y, z, w ); // $ExpectError - f( null, y, z, w ); // $ExpectError - f( undefined, y, z, w ); // $ExpectError - f( [ '1' ], y, z, w ); // $ExpectError - f( {}, y, z, w ); // $ExpectError - f( ( x: number ): number => x, y, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, 10, z, w ); // $ExpectError - f( x, '10', z, w ); // $ExpectError - f( x, true, z, w ); // $ExpectError - f( x, false, z, w ); // $ExpectError - f( x, null, z, w ); // $ExpectError - f( x, undefined, z, w ); // $ExpectError - f( x, [ '1' ], z, w ); // $ExpectError - f( x, {}, z, w ); // $ExpectError - f( x, ( x: number ): number => x, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, 10, w ); // $ExpectError - f( x, y, '10', w ); // $ExpectError - f( x, y, true, w ); // $ExpectError - f( x, y, false, w ); // $ExpectError - f( x, y, null, w ); // $ExpectError - f( x, y, undefined, w ); // $ExpectError - f( x, y, [ '1' ], w ); // $ExpectError - f( x, y, {}, w ); // $ExpectError - f( x, y, ( x: number ): number => x, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, z, 10 ); // $ExpectError - f( x, y, z, '10' ); // $ExpectError - f( x, y, z, true ); // $ExpectError - f( x, y, z, false ); // $ExpectError - f( x, y, z, null ); // $ExpectError - f( x, y, z, undefined ); // $ExpectError - f( x, y, z, [ '1' ] ); // $ExpectError - f( x, y, z, {} ); // $ExpectError - f( x, y, z, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( 10, y, z, w, u ); // $ExpectError - f( '10', y, z, w, u ); // $ExpectError - f( true, y, z, w, u ); // $ExpectError - f( false, y, z, w, u ); // $ExpectError - f( null, y, z, w, u ); // $ExpectError - f( undefined, y, z, w, u ); // $ExpectError - f( [ '1' ], y, z, w, u ); // $ExpectError - f( {}, y, z, w, u ); // $ExpectError - f( ( x: number ): number => x, y, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, 10, z, w, u ); // $ExpectError - f( x, '10', z, w, u ); // $ExpectError - f( x, true, z, w, u ); // $ExpectError - f( x, false, z, w, u ); // $ExpectError - f( x, null, z, w, u ); // $ExpectError - f( x, undefined, z, w, u ); // $ExpectError - f( x, [ '1' ], z, w, u ); // $ExpectError - f( x, {}, z, w, u ); // $ExpectError - f( x, ( x: number ): number => x, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, 10, w, u ); // $ExpectError - f( x, y, '10', w, u ); // $ExpectError - f( x, y, true, w, u ); // $ExpectError - f( x, y, false, w, u ); // $ExpectError - f( x, y, null, w, u ); // $ExpectError - f( x, y, undefined, w, u ); // $ExpectError - f( x, y, [ '1' ], w, u ); // $ExpectError - f( x, y, {}, w, u ); // $ExpectError - f( x, y, ( x: number ): number => x, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, 10, u ); // $ExpectError - f( x, y, z, '10', u ); // $ExpectError - f( x, y, z, true, u ); // $ExpectError - f( x, y, z, false, u ); // $ExpectError - f( x, y, z, null, u ); // $ExpectError - f( x, y, z, undefined, u ); // $ExpectError - f( x, y, z, [ '1' ], u ); // $ExpectError - f( x, y, z, {}, u ); // $ExpectError - f( x, y, z, ( x: number ): number => x, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fifth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, w, 10 ); // $ExpectError - f( x, y, z, w, '10' ); // $ExpectError - f( x, y, z, w, true ); // $ExpectError - f( x, y, z, w, false ); // $ExpectError - f( x, y, z, w, null ); // $ExpectError - f( x, y, z, w, undefined ); // $ExpectError - f( x, y, z, w, [ '1' ] ); // $ExpectError - f( x, y, z, w, {} ); // $ExpectError - f( x, y, z, w, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/add.js b/examples/add.js deleted file mode 100644 index 775b711..0000000 --- a/examples/add.js +++ /dev/null @@ -1,121 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var dispatch = require( './../lib' ); - -function add2( arrays ) { - var opts; - var xo; - var yo; - var zo; - var sx; - var sy; - var sz; - var sh; - var N; - var x; - var y; - var z; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - z = arrays[ 2 ]; - xo = x.order; - yo = y.order; - zo = z.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - opts.order = yo; - sy = ind2sub( sh, i, opts ); - v = x.get.apply( x, sx ) + y.get.apply( y, sy ); - - opts.order = zo; - sz = ind2sub( sh, i, opts ); - sz.push( v ); - z.set.apply( z, sz ); - } -} - -var fcns = [ - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2 -]; - -var types = [ - dtypes.float64, dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.int32, dtypes.int32, - dtypes.uint32, dtypes.uint32, dtypes.uint32, - dtypes.int16, dtypes.int16, dtypes.int16, - dtypes.uint16, dtypes.uint16, dtypes.uint16, - dtypes.int8, dtypes.int8, dtypes.int8, - dtypes.uint8, dtypes.uint8, dtypes.uint8, - dtypes.uint8c, dtypes.uint8c, dtypes.uint8c -]; - -var add = dispatch( fcns, types, null, 3, 2, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var zbuf = new Float64Array( xbuf.length ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var z = ndarray( 'float64', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); - -xbuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -ybuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -zbuf = new Int32Array( xbuf.length ); - -x = ndarray( 'int32', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'int32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -z = ndarray( 'int32', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); diff --git a/examples/sin.js b/examples/sin.js deleted file mode 100644 index 8cd4871..0000000 --- a/examples/sin.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int8Array = require( '@stdlib/array-int8' ); -var sin = require( '@stdlib/math-base-special-sin' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/strided-dtypes' ); -var dispatch = require( './../lib' ); - -function apply( arrays, fcn ) { - var opts; - var xo; - var yo; - var sx; - var sy; - var sh; - var N; - var x; - var y; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - xo = x.order; - yo = y.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - v = fcn( x.get.apply( x, sx ) ); - - opts.order = yo; - sy = ind2sub( sh, i, opts ); - sy.push( v ); - y.set.apply( y, sy ); - } -} - -var fcns = [ - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply -]; - -var types = [ - dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float64, - dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.float64, - dtypes.uint32, dtypes.float64, - dtypes.int16, dtypes.float64, - dtypes.int16, dtypes.float32, - dtypes.uint16, dtypes.float64, - dtypes.uint16, dtypes.float32, - dtypes.int8, dtypes.float64, - dtypes.int8, dtypes.float32, - dtypes.uint8, dtypes.float64, - dtypes.uint8, dtypes.float32, - dtypes.uint8c, dtypes.float64, - dtypes.uint8c, dtypes.float32 -]; - -var data = [ - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin -]; - -var sine = dispatch( fcns, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); - -xbuf = new Int8Array( [ 1, 2, 3, 4, 5 ] ); -ybuf = new Float32Array( xbuf.length ); - -x = ndarray( 'int8', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'float32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); diff --git a/examples/unary.js b/examples/unary.js deleted file mode 100644 index e9c3fb4..0000000 --- a/examples/unary.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -var unary = require( '@stdlib/ndarray-base-unary' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var dispatch = require( './../lib' ); - -var types = [ 'float64', 'float64' ]; - -var data = [ - abs -]; - -var absolute = dispatch( unary, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -absolute( x, y ); -console.log( ybuf ); -// => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 5f280a1..c49a4e4 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..0dc8b25 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@v0.2.1-esm/index.mjs";function m(m,f,l,p,w,v){var a,g,c;if(i(m))c=m;else if(!s(m))throw new TypeError(d("0jr5d",m));if(!n(f))throw new TypeError(d("0jr2y",f));if(!n(l)&&null!==l)throw new TypeError(d("0jr5e",l));if(!e(p))throw new TypeError(d("0jr5f",p));if(!r(w))throw new TypeError(d("0jr5X",w));if(!r(v))throw new TypeError(d("0jr5g",v));if(0===(a=w+v))throw new Error(d("0jr0h"));if(p!==a)throw new Error(d("0jr0i"));if(c){if(g=f.length/a,!t(g))throw new Error(d("0jr0j"))}else if(g=m.length,f.length!==g*a)throw new Error(d("0jr0j"));if(l&&l.length!==g)throw new Error(d("0jr0k"));return f=function(r){var e,t;for(e=[],t=0;t [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0jr5d', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0jr2y', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( '0jr5e', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0jr5f', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0jr5X', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0jr5g', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format('0jr0h') );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format('0jr0i') );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format('0jr0k') );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format('0jr0l') );\n\t\t\t}\n\t\t\tthrow new Error( format('0jr0m') );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( '0jr5h', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( '0jr5i', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format('0jr0n') );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found).\n*\n* ## Notes\n*\n* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types).\n* - The function assumes that `x` is stored in row-major order.\n* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`.\n* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value.\n*\n* @private\n* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension)\n* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension)\n* @param {ArrayLikeObject} x - input two-dimensional reference array\n* @param {integer} strideX1 - `x` stride length along first dimension\n* @param {integer} strideX2 - `x` stride length along second dimension\n* @param {NonNegativeInteger} offsetX - `x` starting index\n* @param {ArrayLikeObject} y - search array\n* @param {integer} strideY - `y` stride length\n* @param {NonNegativeInteger} offsetY - `y` starting index\n* @returns {integer} row index (if found) and `-1` otherwise\n*\n* @example\n* // Define a reference array to search:\n* var types = [\n* 'float64', 'float64', 'float64',\n* 'float32', 'float32', 'float32',\n* 'uint32', 'uint32', 'float64',\n* 'int32', 'int32', 'float64',\n* 'uint16', 'uint16', 'float64',\n* 'int16', 'int16', 'float64',\n* 'uint8', 'uint8', 'float64',\n* 'int8', 'int8', 'float64'\n* ];\n*\n* // Define reference array dimensions:\n* var N = 8; // rows\n* var M = 3; // columns\n*\n* // Define a search array:\n* y1 = [\n* 'float32', 'float32', 'float32',\n* ];\n*\n* // Find the list of types:\n* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 );\n* // returns 1\n*\n// Define a search array:\n* y2 = [\n* 'float32', 'float32', 'float64',\n* ];\n*\n* // Find the list of types:\n* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 );\n* // returns -1\n*/\nfunction indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len\n\tvar ix;\n\tvar iy;\n\tvar i;\n\tvar j;\n\n\t// Search for the first row which matches `y`...\n\tix = offsetX;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tiy = offsetY;\n\t\tfor ( j = 0; j < M; j++ ) {\n\t\t\tif ( x[ ix+(j*strideX2) ] !== y[ iy ] ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tiy += strideY;\n\t\t}\n\t\t// If we successfully iterated over all columns, then that means we've found a match...\n\t\tif ( j === M ) {\n\t\t\treturn i;\n\t\t}\n\t\tix += strideX1;\n\t}\n\treturn -1;\n}\n\n\n// EXPORTS //\n\nexport default indexOfTypes;\n"],"names":["dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","out","i","push","resolveEnum","types2enums","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","getDType","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","j","indexOfTypes","slice"],"mappings":";;0+BA0GA,SAASA,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAO,UAEzB,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAO,UAEzB,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAO,eAIzB,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAO,UAG1B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAO,UAGzB,OADAX,EA5GD,SAAsBA,GACrB,IAAIkB,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAInB,EAAMgB,OAAQG,IAC9BD,EAAIE,KAAMC,EAAarB,EAAOmB,KAE/B,OAAOD,CACR,CAmGSI,CAAatB,GAgBrB,WACC,IAAIuB,EACAC,EACAC,EACAC,EACAC,EACAC,EACAT,EAGJ,GADAM,EAAOI,UAAUb,OACZS,IAASvB,EAAQ,CACrB,GAAKuB,EAAOvB,EACX,MAAM,IAAIa,MAAOJ,EAAO,UAEzB,MAAM,IAAII,MAAOJ,EAAO,SACxB,CAGD,IAFAY,EAAS,GACTC,EAAS,GACHL,EAAI,EAAGA,EAAIjB,EAAOiB,IAAM,CAE7B,IAAMW,EADNH,EAAIE,UAAWV,IAEd,MAAKA,EAAIhB,EACF,IAAIO,UAAWC,EAAQ,QAASgB,IAEhC,IAAIjB,UAAWC,EAAQ,QAASgB,IAGxCJ,EAAOH,KAAMO,GACbH,EAAOJ,KAAMC,EAAaU,EAAUJ,IACpC,CAKD,IAHAD,EC1HF,SAAuBM,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAvB,EACAwB,EAIJ,IADAF,EAAKJ,EACClB,EAAI,EAAGA,EAAIa,EAAGb,IAAM,CAEzB,IADAuB,EAAKF,EACCG,EAAI,EAAGA,EAAIV,GACXC,EAAGO,EAAIE,EAAEP,KAAgBE,EAAGI,GADdC,IAInBD,GAAMH,EAGP,GAAKI,IAAMV,EACV,OAAOd,EAERsB,GAAMN,CACN,CACD,OAAQ,CACT,CDmGQS,CAActC,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGmB,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAId,UAAWC,EAAO,UAI5BiB,EADIrB,GAGAR,EAAM2B,GAGNzB,EACJ2B,EAAGL,EAAQtB,EAAMyB,IAEjBE,EAAGL,GAEJ,GAAc,IAATnB,EACJ,OAAOmB,EAAQlB,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOmB,EAAOsB,MAAO1C,EACrB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 291641d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Create an ndarray function interface which performs multiple dispatch. -* -* @module @stdlib/ndarray-dispatch -* -* @example -* var dispatch = require( '@stdlib/ndarray-dispatch' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/index_of_types.js b/lib/index_of_types.js deleted file mode 100644 index fda2297..0000000 --- a/lib/index_of_types.js +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found). -* -* ## Notes -* -* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types). -* - The function assumes that `x` is stored in row-major order. -* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`. -* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value. -* -* @private -* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension) -* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension) -* @param {ArrayLikeObject} x - input two-dimensional reference array -* @param {integer} strideX1 - `x` stride length along first dimension -* @param {integer} strideX2 - `x` stride length along second dimension -* @param {NonNegativeInteger} offsetX - `x` starting index -* @param {ArrayLikeObject} y - search array -* @param {integer} strideY - `y` stride length -* @param {NonNegativeInteger} offsetY - `y` starting index -* @returns {integer} row index (if found) and `-1` otherwise -* -* @example -* // Define a reference array to search: -* var types = [ -* 'float64', 'float64', 'float64', -* 'float32', 'float32', 'float32', -* 'uint32', 'uint32', 'float64', -* 'int32', 'int32', 'float64', -* 'uint16', 'uint16', 'float64', -* 'int16', 'int16', 'float64', -* 'uint8', 'uint8', 'float64', -* 'int8', 'int8', 'float64' -* ]; -* -* // Define reference array dimensions: -* var N = 8; // rows -* var M = 3; // columns -* -* // Define a search array: -* y1 = [ -* 'float32', 'float32', 'float32', -* ]; -* -* // Find the list of types: -* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 ); -* // returns 1 -* -// Define a search array: -* y2 = [ -* 'float32', 'float32', 'float64', -* ]; -* -* // Find the list of types: -* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 ); -* // returns -1 -*/ -function indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len - var ix; - var iy; - var i; - var j; - - // Search for the first row which matches `y`... - ix = offsetX; - for ( i = 0; i < N; i++ ) { - iy = offsetY; - for ( j = 0; j < M; j++ ) { - if ( x[ ix+(j*strideX2) ] !== y[ iy ] ) { - break; - } - iy += strideY; - } - // If we successfully iterated over all columns, then that means we've found a match... - if ( j === M ) { - return i; - } - ix += strideX1; - } - return -1; -} - - -// EXPORTS // - -module.exports = indexOfTypes; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4648598..0000000 --- a/lib/main.js +++ /dev/null @@ -1,231 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isFunctionArray = require( '@stdlib/assert-is-function-array' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var resolveEnum = require( '@stdlib/ndarray-base-dtype-resolve-enum' ); -var indexOfTypes = require( './index_of_types.js' ); - - -// FUNCTIONS // - -/** -* Returns a list of data type enumeration constants. -* -* @private -* @param {Collection} types - list of types -* @returns {IntegerArray} list of data type enumeration constants -*/ -function types2enums( types ) { - var out; - var i; - - out = []; - for ( i = 0; i < types.length; i++ ) { - out.push( resolveEnum( types[ i ] ) ); - } - return out; -} - - -// MAIN // - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param {(FunctionArray|Function)} fcns - list of ndarray functions -* @param {Collection} types - one-dimensional list of ndarray argument data types -* @param {(Collection|null)} data - ndarray function data (e.g., callbacks) -* @param {PositiveInteger} nargs - total number of ndarray function interface arguments -* @param {NonNegativeInteger} nin - number of input ndarrays -* @param {NonNegativeInteger} nout - number of output ndarrays -* @throws {TypeError} first argument must be either a function or an array of functions -* @throws {TypeError} second argument must be an array-like object -* @throws {TypeError} third argument must be an array-like object or `null` -* @throws {Error} third and first arguments must have the same number of elements -* @throws {TypeError} fourth argument must be a positive integer -* @throws {TypeError} fifth argument must be a nonnegative integer -* @throws {TypeError} sixth argument must be a nonnegative integer -* @throws {Error} fourth argument must equal the specified number of input and output arrays -* @throws {Error} number of types must match the number of functions times the total number of array arguments for each function -* @throws {Error} interface must accept at least one input and/or output ndarray -* @returns {Function} ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function dispatch( fcns, types, data, nargs, nin, nout ) { - var narrays; - var nfcns; - var fcn; - - if ( isFunction( fcns ) ) { - fcn = fcns; - } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( '0jr5d', fcns ) ); - } - if ( !isCollection( types ) ) { - throw new TypeError( format( '0jr2y', types ) ); - } - if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( '0jr5e', data ) ); - } - if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( '0jr5f', nargs ) ); - } - if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( '0jr5X', nin ) ); - } - if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( '0jr5g', nout ) ); - } - narrays = nin + nout; - if ( narrays === 0 ) { - throw new Error( format('0jr0h') ); - } - if ( nargs !== narrays ) { - throw new Error( format('0jr0i') ); - } - if ( fcn ) { - nfcns = types.length / narrays; - if ( !isInteger( nfcns ) ) { - throw new Error( format('0jr0j') ); - } - } else { - nfcns = fcns.length; - if ( types.length !== nfcns*narrays ) { - throw new Error( format('0jr0j') ); - } - } - if ( data && data.length !== nfcns ) { - throw new Error( format('0jr0k') ); - } - types = types2enums( types ); - return dispatcher; - - /** - * ndarray function interface which performs multiple dispatch. - * - * @private - * @param {ndarrayLike} x - ndarray - * @param {...ndarrayLike} args - ndarray arguments - * @throws {Error} insufficient arguments - * @throws {Error} too many arguments - * @throws {TypeError} input array arguments must be ndarray-like objects - * @throws {TypeError} output array arguments must be ndarray-like objects - * @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types - * @returns {(ndarrayLike|Array|void)} destination array(s) - */ - function dispatcher() { - var arrays; - var dtypes; - var argc; - var idx; - var v; - var f; - var i; - - argc = arguments.length; - if ( argc !== nargs ) { - if ( argc < nargs ) { - throw new Error( format('0jr0l') ); - } - throw new Error( format('0jr0m') ); - } - arrays = []; - dtypes = []; - for ( i = 0; i < nargs; i++ ) { - v = arguments[ i ]; - if ( !isndarrayLike( v ) ) { - if ( i < nin ) { - throw new TypeError( format( '0jr5h', v ) ); - } else { - throw new TypeError( format( '0jr5i', v ) ); - } - } - arrays.push( v ); - dtypes.push( resolveEnum( getDType( v ) ) ); - } - // Resolve the ndarray function satisfying the input array types: - idx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len - - // Check whether we were able to successfully resolve an ndarray function: - if ( idx < 0 ) { - throw new TypeError( format('0jr0n') ); - } - // Retrieve the ndarray function: - if ( fcn ) { - f = fcn; - } else { - f = fcns[ idx ]; - } - // Evaluate the ndarray function: - if ( data ) { - f( arrays, data[ idx ] ); - } else { - f( arrays ); - } - if ( nout === 1 ) { - return arrays[ narrays-1 ]; - } - if ( nout === 0 ) { - return; - } - return arrays.slice( nin ); - } -} - - -// EXPORTS // - -module.exports = dispatch; diff --git a/package.json b/package.json index 118edae..ffe4f55 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Create an ndarray function interface which performs multiple dispatch.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,57 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-collection": "^0.2.1", - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/assert-is-function-array": "^0.2.1", - "@stdlib/assert-is-integer": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/assert-is-nonnegative-integer": "^0.2.1", - "@stdlib/assert-is-positive-integer": "^0.2.1", - "@stdlib/ndarray-base-dtype-resolve-enum": "^0.2.1", - "@stdlib/ndarray-dtype": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.2.1", - "@stdlib/array-float64": "^0.2.1", - "@stdlib/array-int32": "^0.2.1", - "@stdlib/array-int8": "^0.2.1", - "@stdlib/array-uint8": "^0.2.1", - "@stdlib/math-base-assert-is-nan": "^0.2.1", - "@stdlib/math-base-special-abs": "^0.2.1", - "@stdlib/math-base-special-pow": "^0.2.1", - "@stdlib/math-base-special-sin": "^0.2.1", - "@stdlib/ndarray-base-buffer-dtype": "^0.2.1", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-base-unary": "^0.2.0", - "@stdlib/ndarray-ctor": "^0.2.0", - "@stdlib/ndarray-dtypes": "^0.2.1", - "@stdlib/ndarray-ind2sub": "^0.2.0", - "@stdlib/strided-dtypes": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "ndarray", @@ -100,7 +26,6 @@ "multimethod", "multimethods" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a841a66 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/fixtures/binary.js b/test/fixtures/binary.js deleted file mode 100644 index a60dfa2..0000000 --- a/test/fixtures/binary.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Binary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @returns {number} sum -*/ -function binary( x, y ) { - return x + y; -} - - -// EXPORTS // - -module.exports = binary; diff --git a/test/fixtures/fill.js b/test/fixtures/fill.js deleted file mode 100644 index 41b2958..0000000 --- a/test/fixtures/fill.js +++ /dev/null @@ -1,76 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which fills one or more ndarrays. -* -* @private -* @param {*} value - fill value -* @returns {Function} ndarray function -*/ -function fill( value ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - */ - function ndarrayFcn( arrays ) { - var opts; - var sub; - var arr; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - opts = { - 'order': '' - }; - for ( j = 0; j < M; j++ ) { - arr = arrays[ j ]; - opts.order = arrays[ j ].order; - for ( i = 0; i < N; i++ ) { - sub = ind2sub( sh, i, opts ); - sub.push( value ); - arr.set.apply( arr, sub ); - } - } - } -} - - -// EXPORTS // - -module.exports = fill; diff --git a/test/fixtures/foreach.js b/test/fixtures/foreach.js deleted file mode 100644 index a426290..0000000 --- a/test/fixtures/foreach.js +++ /dev/null @@ -1,72 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function forEach( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - fcn.apply( null, args ); - } -} - - -// EXPORTS // - -module.exports = forEach; diff --git a/test/fixtures/map1n.js b/test/fixtures/map1n.js deleted file mode 100644 index 614196b..0000000 --- a/test/fixtures/map1n.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function which maps the return value of a callback to `N` arrays. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function map1N( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var v; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - v = fcn(); - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - sub.push( v ); - arrays[ j ].set.apply( arrays[ j ], sub ); - } - } -} - - -// EXPORTS // - -module.exports = map1N; diff --git a/test/fixtures/nullary.js b/test/fixtures/nullary.js deleted file mode 100644 index 4f22126..0000000 --- a/test/fixtures/nullary.js +++ /dev/null @@ -1,36 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Nullary callback. -* -* @private -* @returns {number} value -*/ -function nullary() { - return 3.0; -} - - -// EXPORTS // - -module.exports = nullary; diff --git a/test/fixtures/quaternary.js b/test/fixtures/quaternary.js deleted file mode 100644 index 548437b..0000000 --- a/test/fixtures/quaternary.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quaternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @returns {number} sum -*/ -function quaternary( x, y, z, w ) { - return x + y + z + w; -} - - -// EXPORTS // - -module.exports = quaternary; diff --git a/test/fixtures/quinary.js b/test/fixtures/quinary.js deleted file mode 100644 index 36068de..0000000 --- a/test/fixtures/quinary.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quinary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @param {number} u - input value -* @returns {number} sum -*/ -function quinary( x, y, z, w, u ) { - return x + y + z + w + u; -} - - -// EXPORTS // - -module.exports = quinary; diff --git a/test/fixtures/sum.js b/test/fixtures/sum.js deleted file mode 100644 index efdbb1b..0000000 --- a/test/fixtures/sum.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which computes the sum across one or more ndarrays. -* -* @private -* @param {Object} ctx - context -* @param {number} ctx.sum - initial sum -* @returns {Function} ndarray function -*/ -function wrapper( ctx ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - * @param {Function} [fcn] - callback - */ - function ndarrayFcn( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var f; - var i; - var j; - - if ( arguments.length > 1 ) { - f = fcn; - } - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - if ( f ) { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - ctx.sum += f.apply( null, args ); - } - } else { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - ctx.sum += arrays[ j ].get.apply( arrays[ j ], sub ); - } - } - } - } -} - - -// EXPORTS // - -module.exports = wrapper; diff --git a/test/fixtures/ternary.js b/test/fixtures/ternary.js deleted file mode 100644 index 0595d5f..0000000 --- a/test/fixtures/ternary.js +++ /dev/null @@ -1,39 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Ternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @returns {number} sum -*/ -function ternary( x, y, z ) { - return x + y + z; -} - - -// EXPORTS // - -module.exports = ternary; diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d6c2c8e..0000000 --- a/test/test.js +++ /dev/null @@ -1,363 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var fill = require( './fixtures/fill.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either a function or an array of functions as a first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( value, types, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object as a second argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided either an array-like object or `null` as a third argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - dispatch( unary, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a positive integer for a fourth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 0, - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a fifth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, value, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a sixth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, 1, value ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function array)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var fcns = [ unary, unary, unary ]; - var data = [ abs, abs, abs ]; - dispatch( fcns, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function argument)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs, abs, abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the length of `data` argument does not match the number of ndarray functions', function test( t ) { - var values; - var i; - - values = [ - [], - [ abs, abs ], - [ abs, abs, abs ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var fcns = [ unary ]; - dispatch( fcns, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the fourth argument is incompatible with the number of input and output ndarrays', function test( t ) { - var values; - var i; - - values = [ - 0, - 1, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of specified input and output ndarrays is zero', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var types = [ 'float64' ]; - dispatch( fill( 3 ), types, null, 1, 0, 0 ); - } -}); - -tape( 'the function returns an ndarray function interface', function test( t ) { - var types; - var data; - var f; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - f = dispatch( unary, types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ unary ], types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( fill( 3 ), types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ fill( 3 ) ], types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.two_arrays.js b/test/test.two_arrays.js deleted file mode 100644 index 16eb61b..0000000 --- a/test/test.two_arrays.js +++ /dev/null @@ -1,814 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var dtype = require( '@stdlib/ndarray-base-buffer-dtype' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var forEach = require( './fixtures/foreach.js' ); -var map1N = require( './fixtures/map1n.js' ); -var fill = require( './fixtures/fill.js' ); -var sum = require( './fixtures/sum.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the first argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var ybuf = new Float64Array( 10 ); - var y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( value, y ); - }; - } -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the second argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var xbuf = new Float64Array( 10 ); - var x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( x, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided insufficient arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var f; - var x; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [], - [ x ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided too many arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var ybuf; - var f; - var x; - var y; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [ x, y, y ], - [ x, y, y, y ], - [ x, y, y, y, y ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if unable to resolve a ndarray function supporting the provided array argument data types', function test( t ) { - var values; - var types; - var data; - var xbuf; - var fcn; - var x; - var i; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ abs, abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 4 ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - values = [ - new Uint8Array( 4 ), - new Int32Array( 4 ), - [ 0, 0, 0, 0 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided an array having data type: ' + dtype( values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var y = ndarray( dtype( value ), value, [ value.length ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - }; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only input arrays)', function test( t ) { - var types; - var xbuf; - var ybuf; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only output arrays)', function test( t ) { - var expected; - var types; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only input arrays)', function test( t ) { - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var ctx; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcns = [ - sum( ctx ), - sum( ctx ) - ]; - fcn = dispatch( fcns, types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only output arrays)', function test( t ) { - var expected; - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcns = [ - fill( 3.0 ), - fill( 4.0 ) - ]; - fcn = dispatch( fcns, types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - - fcn = dispatch( forEach, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - - fcn = dispatch( map1N, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - fcns = [ - forEach, - forEach - ]; - fcn = dispatch( fcns, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - fcns = [ - map1N, - map1N - ]; - fcn = dispatch( fcns, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - fcns = [ - unary, - unary - ]; - fcn = dispatch( fcns, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which returns one or more output arrays, if one or more output arrays is specified, and otherwise returns `undefined`', function test( t ) { - var types; - var data; - var xbuf; - var ybuf; - var out; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - // No output arrays... - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, void 0, 'returns expected value' ); - - // One output array... - data = [ - abs, - abs - ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - fcn = dispatch( fill( 3.0 ), types, null, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - // Two output arrays... - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.end(); -}); From 7fe857e4ec3ba7707f0fdb3824bbfba747b44c67 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 21:59:14 +0000 Subject: [PATCH 067/109] Update README.md for ESM bundle v0.2.1 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c29713a..257d168 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ limitations under the License. ## Usage ```javascript -import dispatch from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dispatch@esm/index.mjs'; +import dispatch from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dispatch@v0.2.1-esm/index.mjs'; ``` #### dispatch( fcns, types, data, nargs, nin, nout ) @@ -242,7 +242,7 @@ import unary from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-unary@esm/ import ndarray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs'; import abs from 'https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs'; import Float64Array from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-float64@esm/index.mjs'; -import dispatch from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dispatch@esm/index.mjs'; +import dispatch from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dispatch@v0.2.1-esm/index.mjs'; var types = [ 'float64', 'float64' ]; From 0a79ec660d2ed7861c8f27d3022779380ff72255 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 21:59:14 +0000 Subject: [PATCH 068/109] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 257d168..dc5fba9 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,11 @@ limitations under the License. ## Usage +```javascript +import dispatch from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dispatch@esm/index.mjs'; +``` +The previous example will load the latest bundled code from the esm branch. Alternatively, you may load a specific version by loading the file from one of the [tagged bundles](https://github.com/stdlib-js/ndarray-dispatch/tags). For example, + ```javascript import dispatch from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dispatch@v0.2.1-esm/index.mjs'; ``` @@ -242,7 +247,7 @@ import unary from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-unary@esm/ import ndarray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs'; import abs from 'https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs'; import Float64Array from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-float64@esm/index.mjs'; -import dispatch from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dispatch@v0.2.1-esm/index.mjs'; +import dispatch from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dispatch@esm/index.mjs'; var types = [ 'float64', 'float64' ]; From 693be14c4675d22954f7881b8fc469589df69cd0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 08:21:53 +0000 Subject: [PATCH 069/109] Transform error messages --- lib/main.js | 34 +++++++++++++++++----------------- package.json | 2 +- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/main.js b/lib/main.js index 5f4bb5d..4648598 100644 --- a/lib/main.js +++ b/lib/main.js @@ -27,7 +27,7 @@ var isFunctionArray = require( '@stdlib/assert-is-function-array' ); var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var getDType = require( '@stdlib/ndarray-dtype' ); var resolveEnum = require( '@stdlib/ndarray-base-dtype-resolve-enum' ); var indexOfTypes = require( './index_of_types.js' ); @@ -112,43 +112,43 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { if ( isFunction( fcns ) ) { fcn = fcns; } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) ); + throw new TypeError( format( '0jr5d', fcns ) ); } if ( !isCollection( types ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) ); + throw new TypeError( format( '0jr2y', types ) ); } if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); + throw new TypeError( format( '0jr5e', data ) ); } if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) ); + throw new TypeError( format( '0jr5f', nargs ) ); } if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) ); + throw new TypeError( format( '0jr5X', nin ) ); } if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) ); + throw new TypeError( format( '0jr5g', nout ) ); } narrays = nin + nout; if ( narrays === 0 ) { - throw new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' ); + throw new Error( format('0jr0h') ); } if ( nargs !== narrays ) { - throw new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' ); + throw new Error( format('0jr0i') ); } if ( fcn ) { nfcns = types.length / narrays; if ( !isInteger( nfcns ) ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format('0jr0j') ); } } else { nfcns = fcns.length; if ( types.length !== nfcns*narrays ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format('0jr0j') ); } } if ( data && data.length !== nfcns ) { - throw new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' ); + throw new Error( format('0jr0k') ); } types = types2enums( types ); return dispatcher; @@ -178,9 +178,9 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { argc = arguments.length; if ( argc !== nargs ) { if ( argc < nargs ) { - throw new Error( 'invalid invocation. Insufficient arguments.' ); + throw new Error( format('0jr0l') ); } - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('0jr0m') ); } arrays = []; dtypes = []; @@ -188,9 +188,9 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { v = arguments[ i ]; if ( !isndarrayLike( v ) ) { if ( i < nin ) { - throw new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) ); + throw new TypeError( format( '0jr5h', v ) ); } else { - throw new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) ); + throw new TypeError( format( '0jr5i', v ) ); } } arrays.push( v ); @@ -201,7 +201,7 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { // Check whether we were able to successfully resolve an ndarray function: if ( idx < 0 ) { - throw new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' ); + throw new TypeError( format('0jr0n') ); } // Retrieve the ndarray function: if ( fcn ) { diff --git a/package.json b/package.json index 996faed..d66c7e4 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/assert-is-positive-integer": "^0.2.1", "@stdlib/ndarray-base-dtype-resolve-enum": "^0.2.1", "@stdlib/ndarray-dtype": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, From 057fedf69e3ab557be271772d4c03bf79ac8ac91 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 14:07:47 +0000 Subject: [PATCH 070/109] Remove files --- index.d.ts | 334 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5181 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index c49a4e4..0000000 --- a/index.d.ts +++ /dev/null @@ -1,334 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* ndarray function. -* -* @param arrays - array containing input and output ndarrays -* @param data - ndarray function data (e.g., a callback) -* -* @example -* var numel = require( '@stdlib/ndarray-base-numel' ); -* var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -* -* function ndarrayFcn( arrays, fcn ) { -* var xord; -* var yord; -* var opts; -* var sub; -* var sh; -* var N; -* var x; -* var y; -* var v; -* var i; -* -* x = arrays[ 0 ]; -* y = arrays[ 1 ]; -* sh = x.shape; -* N = numel( sh ); -* if ( N <= 0 ) { -* return; -* } -* xord = x.order; -* yord = y.order; -* opts = {}; -* opts.order = xord; -* for ( i = 0; i < N; i++ ) { -* // Convert a linear index to subscripts: -* opts.order = xord; -* sub = ind2sub( sh, i, opts ); -* -* // Retrieve an element from `x`: -* v = x.get.apply( x, sub ); -* -* // Convert a linear index to subscripts: -* opts.order = yord; -* sub = ind2sub( sh, i, opts ); -* -* // Append the result of applying the callback: -* sub.push( fcn( v ) ); -* -* // Assign the result to an element in `y`: -* y.set.apply( y, sub ); -* } -* } -*/ -type ndarrayFcn = ( arrays: Array, data?: any ) => void; - -/** -* Interface describing an ndarray function dispatcher. -*/ -interface Dispatcher { - /** - * Invokes an ndarray function based on the provided array data type(s). - * - * @param x - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array - * - * @example - * var nullary = require( '@stdlib/ndarray-base-nullary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function value() { - * return 3.14; - * } - * - * var types = [ 'float64' ]; - * var data = [ value ]; - * - * var fcn = dispatch( nullary, types, data, 1, 0, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( 5 ); - * var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x ); - * // xbuf => [ 3.14, 3.14, 3.14, 3.14, 3.14 ] - */ - ( x: ndarray ): ndarray | void; - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var unary = require( '@stdlib/ndarray-base-unary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * var abs = require( '@stdlib/math-base-special-abs' ); - * - * var types = [ 'float64', 'float64' ]; - * var data = [ abs ]; - * - * var fcn = dispatch( unary, types, data, 2, 1, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - * var ybuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y ); - * // ybuf => [ 1.0, 2.0, 3.0 ] - */ - ( x: ndarray, y: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var ternary = require( '@stdlib/ndarray-base-ternary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function add2( x, y ) { - * return x + y; - * } - * - * var types = [ 'float64', 'float64', 'float64' ]; - * var data = [ add2 ]; - * - * var fcn = dispatch( ternary, types, data, 3, 2, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z ); - * // zbuf => [ 2.0, 4.0, 6.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quaternary = require( '@stdlib/ndarray-base-quaternary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function add3( x, y, z ) { - * return x + y + z; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add3 ]; - * - * var fcn = dispatch( quaternary, types, data, 4, 3, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w ); - * // wbuf => [ 3.0, 6.0, 9.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @param args - ndarray arguments - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quinary = require( '@stdlib/ndarray-base-quinary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function add4( x, y, z, w ) { - * return x + y + z + w; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add4 ]; - * - * var fcn = dispatch( quinary, types, data, 5, 4, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ubuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var u = ndarray( 'float64', ubuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w, u ); - * // ubuf => [ 4.0, 8.0, 12.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray, ...args: Array ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures -} - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param fcns - list of ndarray functions -* @param types - one-dimensional list of ndarray argument data types -* @param data - ndarray function data (e.g., callbacks) -* @param nargs - total number of ndarray function interface arguments -* @param nin - number of input ndarrays -* @param nout - number of output ndarrays -* @throws first argument must be either a function or an array of functions -* @throws second argument must be an array-like object -* @throws third argument must be an array-like object or `null` -* @throws third and first arguments must have the same number of elements -* @throws fourth argument must be a positive integer -* @throws fifth argument must be a nonnegative integer -* @throws sixth argument must be a nonnegative integer -* @throws fourth argument must equal the specified number of input and output arrays -* @throws number of types must match the number of functions times the total number of array arguments for each function -* @throws interface must accept at least one input and/or output ndarray -* @returns ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var fcn = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* fcn( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function dispatch( fcns: ndarrayFcn | ArrayLike, types: ArrayLike, data: ArrayLike | null, nargs: number, nin: number, nout: number ): Dispatcher; - - -// EXPORTS // - -export = dispatch; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 0dc8b25..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@v0.2.1-esm/index.mjs";function m(m,f,l,p,w,v){var a,g,c;if(i(m))c=m;else if(!s(m))throw new TypeError(d("0jr5d",m));if(!n(f))throw new TypeError(d("0jr2y",f));if(!n(l)&&null!==l)throw new TypeError(d("0jr5e",l));if(!e(p))throw new TypeError(d("0jr5f",p));if(!r(w))throw new TypeError(d("0jr5X",w));if(!r(v))throw new TypeError(d("0jr5g",v));if(0===(a=w+v))throw new Error(d("0jr0h"));if(p!==a)throw new Error(d("0jr0i"));if(c){if(g=f.length/a,!t(g))throw new Error(d("0jr0j"))}else if(g=m.length,f.length!==g*a)throw new Error(d("0jr0j"));if(l&&l.length!==g)throw new Error(d("0jr0k"));return f=function(r){var e,t;for(e=[],t=0;t [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0jr5d', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0jr2y', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( '0jr5e', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0jr5f', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0jr5X', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0jr5g', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format('0jr0h') );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format('0jr0i') );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format('0jr0k') );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format('0jr0l') );\n\t\t\t}\n\t\t\tthrow new Error( format('0jr0m') );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( '0jr5h', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( '0jr5i', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format('0jr0n') );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found).\n*\n* ## Notes\n*\n* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types).\n* - The function assumes that `x` is stored in row-major order.\n* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`.\n* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value.\n*\n* @private\n* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension)\n* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension)\n* @param {ArrayLikeObject} x - input two-dimensional reference array\n* @param {integer} strideX1 - `x` stride length along first dimension\n* @param {integer} strideX2 - `x` stride length along second dimension\n* @param {NonNegativeInteger} offsetX - `x` starting index\n* @param {ArrayLikeObject} y - search array\n* @param {integer} strideY - `y` stride length\n* @param {NonNegativeInteger} offsetY - `y` starting index\n* @returns {integer} row index (if found) and `-1` otherwise\n*\n* @example\n* // Define a reference array to search:\n* var types = [\n* 'float64', 'float64', 'float64',\n* 'float32', 'float32', 'float32',\n* 'uint32', 'uint32', 'float64',\n* 'int32', 'int32', 'float64',\n* 'uint16', 'uint16', 'float64',\n* 'int16', 'int16', 'float64',\n* 'uint8', 'uint8', 'float64',\n* 'int8', 'int8', 'float64'\n* ];\n*\n* // Define reference array dimensions:\n* var N = 8; // rows\n* var M = 3; // columns\n*\n* // Define a search array:\n* y1 = [\n* 'float32', 'float32', 'float32',\n* ];\n*\n* // Find the list of types:\n* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 );\n* // returns 1\n*\n// Define a search array:\n* y2 = [\n* 'float32', 'float32', 'float64',\n* ];\n*\n* // Find the list of types:\n* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 );\n* // returns -1\n*/\nfunction indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len\n\tvar ix;\n\tvar iy;\n\tvar i;\n\tvar j;\n\n\t// Search for the first row which matches `y`...\n\tix = offsetX;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tiy = offsetY;\n\t\tfor ( j = 0; j < M; j++ ) {\n\t\t\tif ( x[ ix+(j*strideX2) ] !== y[ iy ] ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tiy += strideY;\n\t\t}\n\t\t// If we successfully iterated over all columns, then that means we've found a match...\n\t\tif ( j === M ) {\n\t\t\treturn i;\n\t\t}\n\t\tix += strideX1;\n\t}\n\treturn -1;\n}\n\n\n// EXPORTS //\n\nexport default indexOfTypes;\n"],"names":["dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","out","i","push","resolveEnum","types2enums","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","getDType","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","j","indexOfTypes","slice"],"mappings":";;0+BA0GA,SAASA,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAO,UAEzB,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAO,UAEzB,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAO,eAIzB,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAO,UAG1B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAO,UAGzB,OADAX,EA5GD,SAAsBA,GACrB,IAAIkB,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAInB,EAAMgB,OAAQG,IAC9BD,EAAIE,KAAMC,EAAarB,EAAOmB,KAE/B,OAAOD,CACR,CAmGSI,CAAatB,GAgBrB,WACC,IAAIuB,EACAC,EACAC,EACAC,EACAC,EACAC,EACAT,EAGJ,GADAM,EAAOI,UAAUb,OACZS,IAASvB,EAAQ,CACrB,GAAKuB,EAAOvB,EACX,MAAM,IAAIa,MAAOJ,EAAO,UAEzB,MAAM,IAAII,MAAOJ,EAAO,SACxB,CAGD,IAFAY,EAAS,GACTC,EAAS,GACHL,EAAI,EAAGA,EAAIjB,EAAOiB,IAAM,CAE7B,IAAMW,EADNH,EAAIE,UAAWV,IAEd,MAAKA,EAAIhB,EACF,IAAIO,UAAWC,EAAQ,QAASgB,IAEhC,IAAIjB,UAAWC,EAAQ,QAASgB,IAGxCJ,EAAOH,KAAMO,GACbH,EAAOJ,KAAMC,EAAaU,EAAUJ,IACpC,CAKD,IAHAD,EC1HF,SAAuBM,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAvB,EACAwB,EAIJ,IADAF,EAAKJ,EACClB,EAAI,EAAGA,EAAIa,EAAGb,IAAM,CAEzB,IADAuB,EAAKF,EACCG,EAAI,EAAGA,EAAIV,GACXC,EAAGO,EAAIE,EAAEP,KAAgBE,EAAGI,GADdC,IAInBD,GAAMH,EAGP,GAAKI,IAAMV,EACV,OAAOd,EAERsB,GAAMN,CACN,CACD,OAAQ,CACT,CDmGQS,CAActC,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGmB,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAId,UAAWC,EAAO,UAI5BiB,EADIrB,GAGAR,EAAM2B,GAGNzB,EACJ2B,EAAGL,EAAQtB,EAAMyB,IAEjBE,EAAGL,GAEJ,GAAc,IAATnB,EACJ,OAAOmB,EAAQlB,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOmB,EAAOsB,MAAO1C,EACrB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a841a66..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 510bd8e27a2294b105e4b6a0c93449733a41518a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 14:08:12 +0000 Subject: [PATCH 071/109] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 229 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 61 +- SECURITY.md | 5 - benchmark/benchmark.dispatch_size.js | 156 - benchmark/benchmark.js | 81 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 87 - docs/types/test.ts | 641 --- examples/add.js | 121 - examples/sin.js | 142 - examples/unary.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/index_of_types.js | 106 - lib/main.js | 231 - package.json | 79 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/binary.js | 38 - test/fixtures/fill.js | 76 - test/fixtures/foreach.js | 72 - test/fixtures/map1n.js | 74 - test/fixtures/nullary.js | 36 - test/fixtures/quaternary.js | 40 - test/fixtures/quinary.js | 41 - test/fixtures/sum.js | 98 - test/fixtures/ternary.js | 39 - test/test.js | 363 -- test/test.two_arrays.js | 814 ---- 57 files changed, 4876 insertions(+), 6748 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.dispatch_size.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/add.js delete mode 100644 examples/sin.js delete mode 100644 examples/unary.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/index_of_types.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/fixtures/binary.js delete mode 100644 test/fixtures/fill.js delete mode 100644 test/fixtures/foreach.js delete mode 100644 test/fixtures/map1n.js delete mode 100644 test/fixtures/nullary.js delete mode 100644 test/fixtures/quaternary.js delete mode 100644 test/fixtures/quinary.js delete mode 100644 test/fixtures/sum.js delete mode 100644 test/fixtures/ternary.js delete mode 100644 test/test.js delete mode 100644 test/test.two_arrays.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index bd23661..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-03-01T06:01:53.713Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ac0b7cd..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 5e92c3e..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2b4fac7..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '43 7 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -304,7 +295,7 @@ console.log( ybuf ); ## 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. +This package is part of [stdlib][stdlib], a standard library 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]. @@ -367,11 +358,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-dispatch/main/LICENSE -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.dispatch_size.js b/benchmark/benchmark.dispatch_size.js deleted file mode 100644 index 15805ba..0000000 --- a/benchmark/benchmark.dispatch_size.js +++ /dev/null @@ -1,156 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib/main.js' ); - - -// FUNCTIONS // - -/** -* Evaluates the identity function. -* -* @private -* @param {*} v - value -* @returns {*} input value -*/ -function identity( v ) { - return v; -} - -/** -* Dummy function which throws an error. -* -* @private -* @throws {Error} unexpected error -*/ -function throwError() { - throw new Error( 'unexpected error' ); -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} size - dispatch size -* @returns {Function} benchmark function -*/ -function createBenchmark( size ) { - var types; - var data; - var fcn; - var x; - var y; - var t; - var i; - - types = []; - - // Create dummy types... - for ( i = 0; i < (size-1)*2; i += 2 ) { - t = 'foo' + i; - types.push( t ); - types.push( t ); - } - // Append test types: - types.push( 'float64' ); - types.push( 'float64' ); - - // Define a list of callbacks: - data = []; - for ( i = 0; i < size-1; i++ ) { - data.push( throwError ); - } - // Append a test callback: - data.push( identity ); - - // Create the dispatcher: - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - // Create sample arrays: - x = new Float64Array( 1 ); - y = new Float64Array( x.length ); - - x = ndarray( 'float64', x, [ 1 ], [ 1 ], 0, 'row-major' ); - y = ndarray( 'float64', y, [ 1 ], [ 1 ], 0, 'row-major' ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var z; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x.data[ 0 ] = i; - z = fcn( x, y ); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var size; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - size = pow( 2, i ); - f = createBenchmark( size ); - bench( pkg+':size='+size, f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 3c6f450..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::fcns_array', function benchmark( b ) { - var types; - var fcns; - var data; - var out; - var i; - - fcns = [ unary ]; - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( fcns, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::fcn_arg', function benchmark( b ) { - var types; - var data; - var out; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( unary, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0aae4af..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch" -%% click B href "https://github.com/stdlib-js/ndarray-dispatch/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-dispatch/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-dispatch/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-dispatch/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-dispatch/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch -[production-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 1295a44..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import dispatch from '../docs/types/index'; -export = dispatch; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7fb29cb..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var y=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var b=y(function(D,w){ -function k(i,r,e,u,f,m,n,o,l){var h,t,s,a;for(h=m,s=0;s [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( 'invalid invocation. Insufficient arguments.' );\n\t\t\t}\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = dispatch;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an ndarray function interface which performs multiple dispatch.\n*\n* @module @stdlib/ndarray-dispatch\n*\n* @example\n* var dispatch = require( '@stdlib/ndarray-dispatch' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var unary = require( '@stdlib/ndarray-base-unary' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var types = [\n* 'float64', 'float64'\n* ];\n*\n* var data = [\n* abs\n* ];\n*\n* var absolute = dispatch( unary, types, data, 2, 1, 1 );\n*\n* // ...\n*\n* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] );\n* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] );\n*\n* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' );\n* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' );\n*\n* absolute( x, y );\n* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA6EA,SAASC,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,EAAU,CAClF,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,CAAU,IAAME,EAAGI,CAAG,EADjBE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,CACP,CACA,MAAO,EACR,CAKAL,EAAO,QAAUC,ICzGjB,IAAAc,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAoB,QAAS,oCAAqC,EAClEC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAkB,QAAS,kCAAmC,EAC9DC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAc,QAAS,yCAA0C,EACjEC,EAAe,IAYnB,SAASC,EAAaC,EAAQ,CAC7B,IAAIC,EACAC,EAGJ,IADAD,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIF,EAAM,OAAQE,IAC9BD,EAAI,KAAMJ,EAAaG,EAAOE,CAAE,CAAE,CAAE,EAErC,OAAOD,CACR,CAqDA,SAASE,EAAUC,EAAMJ,EAAOK,EAAMC,EAAOC,EAAKC,EAAO,CACxD,IAAIC,EACAC,EACAC,EAEJ,GAAKnB,EAAYY,CAAK,EACrBO,EAAMP,UACK,CAACb,EAAiBa,CAAK,EAClC,MAAM,IAAI,UAAWT,EAAQ,oGAAqGS,CAAK,CAAE,EAE1I,GAAK,CAACX,EAAcO,CAAM,EACzB,MAAM,IAAI,UAAWL,EAAQ,+EAAgFK,CAAM,CAAE,EAEtH,GAAK,CAACP,EAAcY,CAAK,GAAKA,IAAS,KACtC,MAAM,IAAI,UAAWV,EAAQ,sFAAuFU,CAAK,CAAE,EAE5H,GAAK,CAAChB,EAAmBiB,CAAM,EAC9B,MAAM,IAAI,UAAWX,EAAQ,6EAA8EW,CAAM,CAAE,EAEpH,GAAK,CAAClB,EAAsBmB,CAAI,EAC/B,MAAM,IAAI,UAAWZ,EAAQ,+EAAgFY,CAAI,CAAE,EAEpH,GAAK,CAACnB,EAAsBoB,CAAK,EAChC,MAAM,IAAI,UAAWb,EAAQ,+EAAgFa,CAAK,CAAE,EAGrH,GADAC,EAAUF,EAAMC,EACXC,IAAY,EAChB,MAAM,IAAI,MAAO,4IAA6I,EAE/J,GAAKH,IAAUG,EACd,MAAM,IAAI,MAAO,4FAA6F,EAE/G,GAAKE,GAEJ,GADAD,EAAQV,EAAM,OAASS,EAClB,CAACnB,EAAWoB,CAAM,EACtB,MAAM,IAAI,MAAO,8IAA+I,UAGjKA,EAAQN,EAAK,OACRJ,EAAM,SAAWU,EAAMD,EAC3B,MAAM,IAAI,MAAO,8IAA+I,EAGlK,GAAKJ,GAAQA,EAAK,SAAWK,EAC5B,MAAM,IAAI,MAAO,mGAAoG,EAEtH,OAAAV,EAAQD,EAAaC,CAAM,EACpBY,EAeP,SAASA,GAAa,CACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EAGJ,GADAa,EAAO,UAAU,OACZA,IAAST,EACb,MAAKS,EAAOT,EACL,IAAI,MAAO,6CAA8C,EAE1D,IAAI,MAAO,yCAA0C,EAI5D,IAFAO,EAAS,CAAC,EACVC,EAAS,CAAC,EACJZ,EAAI,EAAGA,EAAII,EAAOJ,IAAM,CAE7B,GADAe,EAAI,UAAWf,CAAE,EACZ,CAACR,EAAeuB,CAAE,EACtB,MAAKf,EAAIK,EACF,IAAI,UAAWZ,EAAQ,6EAA8EsB,CAAE,CAAE,EAEzG,IAAI,UAAWtB,EAAQ,8EAA+EsB,CAAE,CAAE,EAGlHJ,EAAO,KAAMI,CAAE,EACfH,EAAO,KAAMjB,EAAaD,EAAUqB,CAAE,CAAE,CAAE,CAC3C,CAKA,GAHAD,EAAMlB,EAAcY,EAAOD,EAAST,EAAOS,EAAS,EAAG,EAAGK,EAAQ,EAAG,CAAE,EAGlEE,EAAM,EACV,MAAM,IAAI,UAAW,6GAA8G,EAcpI,GAXKL,EACJO,EAAIP,EAEJO,EAAId,EAAMY,CAAI,EAGVX,EACJa,EAAGL,EAAQR,EAAMW,CAAI,CAAE,EAEvBE,EAAGL,CAAO,EAENL,IAAS,EACb,OAAOK,EAAQJ,EAAQ,CAAE,EAE1B,GAAKD,IAAS,EAGd,OAAOK,EAAO,MAAON,CAAI,CAC1B,CACD,CAKApB,EAAO,QAAUgB,IC9KjB,IAAIgB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_index_of_types", "__commonJSMin", "exports", "module", "indexOfTypes", "N", "M", "x", "strideX1", "strideX2", "offsetX", "y", "strideY", "offsetY", "ix", "iy", "i", "j", "require_main", "__commonJSMin", "exports", "module", "isNonNegativeInteger", "isPositiveInteger", "isInteger", "isFunctionArray", "isFunction", "isCollection", "isndarrayLike", "format", "getDType", "resolveEnum", "indexOfTypes", "types2enums", "types", "out", "i", "dispatch", "fcns", "data", "nargs", "nin", "nout", "narrays", "nfcns", "fcn", "dispatcher", "arrays", "dtypes", "argc", "idx", "v", "f", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 02fe150..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,87 +0,0 @@ - -{{alias}}( fcns, types, data, nargs, nin, nout ) - Returns an ndarray function interface which performs multiple dispatch. - - An ndarray function interface has the following signature: - - f( x, y, ... ) - - where - - - x: ndarray. - - y: ndarray. - - ...: additional ndarrays. - - The number of parameters is derived from `nargs`, the number of input - ndarrays is derived from `nin`, and the number of output ndarrays is derived - from `nout`. - - Parameters - ---------- - fcns: Function|ArrayLikeObject - List of ndarray functions. An ndarray function should have the following - signature: - - f( arrays, data ) - - where - - - arrays: array containing input and output ndarrays. - - data: ndarray function data (e.g., a callback). - - For convenience, a single ndarray function may be provided which will be - invoked whenever the ndarray argument data types match a sequence of - types in `types`. Providing a single ndarray function is particularly - convenient for the case where, regardless of array data types, - traversing arrays remains the same, but the ndarray function `data` - differs (e.g., callbacks which differ based on the array data types). - - types: ArrayLikeObject - One-dimensional list of ndarray argument data types. - - data: ArrayLikeObject|null - ndarray function data (e.g., callbacks). If `null`, a returned ndarray - function interface does **not** provide a `data` argument to an invoked - ndarray function. - - nargs: integer - Total number of ndarray function interface arguments. - - nin: integer - Number of input ndarrays. - - nout: integer - Number of output ndarrays. - - Returns - ------- - fcn: Function - ndarray function interface. - - Examples - -------- - // Define ndarray argument data types: - > var t = [ 'float64', 'float64', 'float32', 'float32' ]; - - // Define a list of ndarray function data (callbacks): - > var d = [ {{alias:@stdlib/math/base/special/abs}}, {{alias:@stdlib/math/base/special/absf}} ]; - - // Create an ndarray function interface for applying unary callbacks: - > var f = {{alias}}( {{alias:@stdlib/ndarray/base/unary}}, t, d, 2, 1, 1 ); - - // Create an input ndarray: - > var xbuf = new {{alias:@stdlib/array/float64}}( [ -1.0, -2.0, -3.0, -4.0 ] ); - > var x = {{alias:@stdlib/ndarray/ctor}}( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Create an output ndarray: - > var ybuf = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 0.0, 0.0 ] ); - > var y = {{alias:@stdlib/ndarray/ctor}}( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Compute the element-wise absolute value: - > f( x, y ); - > ybuf - [ 1.0, 2.0, 3.0, 4.0 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 3cba031..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,641 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable max-lines */ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import dispatch = require( './index' ); - - -// FUNCTIONS // - -/** -* Nullary callback. -* -* @return input value -*/ -function nullary(): any { - return 5.0; -} - -/** -* Unary callback. -* -* @param x - input value -* @return input value -*/ -function unary( x: any ): any { - return x; -} - -/** -* Binary callback. -* -* @param x - input value -* @param y - input value -* @return output value -*/ -function binary( x: number, y: number ): number { - return x + y; -} - -/** -* Ternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @return output value -*/ -function ternary( x: number, y: number, z: number ): number { - return x + y + z; -} - -/** -* Quaternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @param w - input value -* @return output value -*/ -function quaternary( x: number, y: number, z: number, w: number ): number { - return x + y + z + w; -} - -/** -* Mock `ind2sub` function. -* -* @param shape - dimensions -* @param idx - linear index -* @param opts - options -* @return subscripts -*/ -function ind2sub( shape: ArrayLike, idx: number, opts?: any ): Array { - let out; - let i; - - out = []; - if ( typeof opts === 'object' && opts !== null && opts.order === 'row-major' ) { no-unsafe-any - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } else { - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } - return out; -} - -/** -* Mock ndarray function. -* -* @param arrays - ndarrays -* @param fcn - callback -*/ -function ndarrayFcn( arrays: Array, fcn: ( x: any ) => any ): void { - let xord; - let yord; - let opts; - let sub; - let sh; - let N; - let x; - let y; - let v; - let i; - - x = arrays[ 0 ]; - y = arrays[ 1 ]; - sh = x.shape; - if ( sh.length === 0 ) { - return; - } - N = 1; - for ( i = 0; i < sh.length; i += 1 ) { - N *= sh[ i ]; - } - xord = x.order; - yord = y.order; - opts = { - 'order': '' - }; - opts.order = xord; - for ( i = 0; i < N; i += 1 ) { - // Convert a linear index to subscripts: - opts.order = xord; - sub = ind2sub( sh, i, opts ); - - // Retrieve an element from `x`: - v = x.get.apply( x, sub ); - - // Convert a linear index to subscripts: - opts.order = yord; - sub = ind2sub( sh, i, opts ); - - // Append the result of applying the callback: - sub[ sub.length ] = fcn( v ) as number; - - // Assign the result to an element in `y`: - y.set.apply( y, sub ); - } -} - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a dispatch function... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, 1 ); // $ExpectType Dispatcher - dispatch( [ ndarrayFcn ], types, data, 2, 1, 1 ); // $ExpectType Dispatcher -} - -// The compiler throws an error if the function is provided a first argument which is not either an ndarray function or an array-like object containing ndarray functions... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( '10', types, data, 2, 1, 1 ); // $ExpectError - dispatch( 10, types, data, 2, 1, 1 ); // $ExpectError - dispatch( true, types, data, 2, 1, 1 ); // $ExpectError - dispatch( false, types, data, 2, 1, 1 ); // $ExpectError - dispatch( null, types, data, 2, 1, 1 ); // $ExpectError - dispatch( undefined, types, data, 2, 1, 1 ); // $ExpectError - dispatch( [ '1' ], types, data, 2, 1, 1 ); // $ExpectError - dispatch( {}, types, data, 2, 1, 1 ); // $ExpectError - dispatch( ( x: number ): number => x, types, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object... -{ - const data = [ unary ]; - - dispatch( ndarrayFcn, 10, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, true, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, false, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, null, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, undefined, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, {}, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object or null... -{ - const types = [ 'float64', 'float64' ]; - - dispatch( ndarrayFcn, types, 10, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, true, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, false, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, undefined, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, {}, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, '10', 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, true, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, false, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, null, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, undefined, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, [ '1' ], 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, {}, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, ( x: number ): number => x, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, '10', 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, true, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, false, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, null, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, undefined, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, [ '1' ], 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, {}, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, ( x: number ): number => x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, '10' ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, true ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, false ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, null ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, undefined ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, [ '1' ] ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, {} ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch(); // $ExpectError - dispatch( ndarrayFcn ); // $ExpectError - dispatch( ndarrayFcn, types ); // $ExpectError - dispatch( ndarrayFcn, types, data ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, 1, 0 ); // $ExpectError -} - -// The function returns a dispatch function... -{ - const x = array(); - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const t1 = [ 'float64' ]; - const d1 = [ nullary ]; - const f1 = dispatch( ndarrayFcn, t1, d1, 1, 1, 0 ); - f1( x ); // $ExpectType void | ndarray - - const t2 = [ 'float64', 'float64' ]; - const d2 = [ unary ]; - const f2 = dispatch( ndarrayFcn, t2, d2, 2, 1, 1 ); - f2( x, y ); // $ExpectType void | ndarray - - const t3 = [ 'float64', 'float64', 'float64' ]; - const d3 = [ binary ]; - const f3 = dispatch( ndarrayFcn, t3, d3, 3, 2, 1 ); - f3( x, y, z ); // $ExpectType void | ndarray - - const t4 = [ 'float64', 'float64', 'float64', 'float64' ]; - const d4 = [ ternary ]; - const f4 = dispatch( ndarrayFcn, t4, d4, 4, 3, 1 ); - f4( x, y, z, w ); // $ExpectType void | ndarray - - const t5 = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const d5 = [ quaternary ]; - const f5 = dispatch( ndarrayFcn, t5, d5, 5, 4, 1 ); - f5( x, y, z, w, u ); // $ExpectType void | ndarray -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (1 ndarray)... -{ - const types = [ 'float64' ]; - const data = [ nullary ]; - - const f = dispatch( ndarrayFcn, types, data, 1, 0, 1 ); - f( '10' ); // $ExpectError - f( 10 ); // $ExpectError - f( true ); // $ExpectError - f( false ); // $ExpectError - f( null ); // $ExpectError - f( undefined ); // $ExpectError - f( [ '1' ] ); // $ExpectError - f( {} ); // $ExpectError - f( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( 10, y ); // $ExpectError - f( '10', y ); // $ExpectError - f( true, y ); // $ExpectError - f( false, y ); // $ExpectError - f( null, y ); // $ExpectError - f( undefined, y ); // $ExpectError - f( [ '1' ], y ); // $ExpectError - f( {}, y ); // $ExpectError - f( ( x: number ): number => x, y ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const x = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( x, 10 ); // $ExpectError - f( x, '10' ); // $ExpectError - f( x, true ); // $ExpectError - f( x, false ); // $ExpectError - f( x, null ); // $ExpectError - f( x, undefined ); // $ExpectError - f( x, [ '1' ] ); // $ExpectError - f( x, {} ); // $ExpectError - f( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( 10, y, z ); // $ExpectError - f( '10', y, z ); // $ExpectError - f( true, y, z ); // $ExpectError - f( false, y, z ); // $ExpectError - f( null, y, z ); // $ExpectError - f( undefined, y, z ); // $ExpectError - f( [ '1' ], y, z ); // $ExpectError - f( {}, y, z ); // $ExpectError - f( ( x: number ): number => x, y, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, 10, z ); // $ExpectError - f( x, '10', z ); // $ExpectError - f( x, true, z ); // $ExpectError - f( x, false, z ); // $ExpectError - f( x, null, z ); // $ExpectError - f( x, undefined, z ); // $ExpectError - f( x, [ '1' ], z ); // $ExpectError - f( x, {}, z ); // $ExpectError - f( x, ( x: number ): number => x, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, y, '10' ); // $ExpectError - f( x, y, true ); // $ExpectError - f( x, y, false ); // $ExpectError - f( x, y, null ); // $ExpectError - f( x, y, undefined ); // $ExpectError - f( x, y, [ '1' ] ); // $ExpectError - f( x, y, {} ); // $ExpectError - f( x, y, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( 10, y, z, w ); // $ExpectError - f( '10', y, z, w ); // $ExpectError - f( true, y, z, w ); // $ExpectError - f( false, y, z, w ); // $ExpectError - f( null, y, z, w ); // $ExpectError - f( undefined, y, z, w ); // $ExpectError - f( [ '1' ], y, z, w ); // $ExpectError - f( {}, y, z, w ); // $ExpectError - f( ( x: number ): number => x, y, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, 10, z, w ); // $ExpectError - f( x, '10', z, w ); // $ExpectError - f( x, true, z, w ); // $ExpectError - f( x, false, z, w ); // $ExpectError - f( x, null, z, w ); // $ExpectError - f( x, undefined, z, w ); // $ExpectError - f( x, [ '1' ], z, w ); // $ExpectError - f( x, {}, z, w ); // $ExpectError - f( x, ( x: number ): number => x, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, 10, w ); // $ExpectError - f( x, y, '10', w ); // $ExpectError - f( x, y, true, w ); // $ExpectError - f( x, y, false, w ); // $ExpectError - f( x, y, null, w ); // $ExpectError - f( x, y, undefined, w ); // $ExpectError - f( x, y, [ '1' ], w ); // $ExpectError - f( x, y, {}, w ); // $ExpectError - f( x, y, ( x: number ): number => x, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, z, 10 ); // $ExpectError - f( x, y, z, '10' ); // $ExpectError - f( x, y, z, true ); // $ExpectError - f( x, y, z, false ); // $ExpectError - f( x, y, z, null ); // $ExpectError - f( x, y, z, undefined ); // $ExpectError - f( x, y, z, [ '1' ] ); // $ExpectError - f( x, y, z, {} ); // $ExpectError - f( x, y, z, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( 10, y, z, w, u ); // $ExpectError - f( '10', y, z, w, u ); // $ExpectError - f( true, y, z, w, u ); // $ExpectError - f( false, y, z, w, u ); // $ExpectError - f( null, y, z, w, u ); // $ExpectError - f( undefined, y, z, w, u ); // $ExpectError - f( [ '1' ], y, z, w, u ); // $ExpectError - f( {}, y, z, w, u ); // $ExpectError - f( ( x: number ): number => x, y, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, 10, z, w, u ); // $ExpectError - f( x, '10', z, w, u ); // $ExpectError - f( x, true, z, w, u ); // $ExpectError - f( x, false, z, w, u ); // $ExpectError - f( x, null, z, w, u ); // $ExpectError - f( x, undefined, z, w, u ); // $ExpectError - f( x, [ '1' ], z, w, u ); // $ExpectError - f( x, {}, z, w, u ); // $ExpectError - f( x, ( x: number ): number => x, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, 10, w, u ); // $ExpectError - f( x, y, '10', w, u ); // $ExpectError - f( x, y, true, w, u ); // $ExpectError - f( x, y, false, w, u ); // $ExpectError - f( x, y, null, w, u ); // $ExpectError - f( x, y, undefined, w, u ); // $ExpectError - f( x, y, [ '1' ], w, u ); // $ExpectError - f( x, y, {}, w, u ); // $ExpectError - f( x, y, ( x: number ): number => x, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, 10, u ); // $ExpectError - f( x, y, z, '10', u ); // $ExpectError - f( x, y, z, true, u ); // $ExpectError - f( x, y, z, false, u ); // $ExpectError - f( x, y, z, null, u ); // $ExpectError - f( x, y, z, undefined, u ); // $ExpectError - f( x, y, z, [ '1' ], u ); // $ExpectError - f( x, y, z, {}, u ); // $ExpectError - f( x, y, z, ( x: number ): number => x, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fifth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, w, 10 ); // $ExpectError - f( x, y, z, w, '10' ); // $ExpectError - f( x, y, z, w, true ); // $ExpectError - f( x, y, z, w, false ); // $ExpectError - f( x, y, z, w, null ); // $ExpectError - f( x, y, z, w, undefined ); // $ExpectError - f( x, y, z, w, [ '1' ] ); // $ExpectError - f( x, y, z, w, {} ); // $ExpectError - f( x, y, z, w, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/add.js b/examples/add.js deleted file mode 100644 index 775b711..0000000 --- a/examples/add.js +++ /dev/null @@ -1,121 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var dispatch = require( './../lib' ); - -function add2( arrays ) { - var opts; - var xo; - var yo; - var zo; - var sx; - var sy; - var sz; - var sh; - var N; - var x; - var y; - var z; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - z = arrays[ 2 ]; - xo = x.order; - yo = y.order; - zo = z.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - opts.order = yo; - sy = ind2sub( sh, i, opts ); - v = x.get.apply( x, sx ) + y.get.apply( y, sy ); - - opts.order = zo; - sz = ind2sub( sh, i, opts ); - sz.push( v ); - z.set.apply( z, sz ); - } -} - -var fcns = [ - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2 -]; - -var types = [ - dtypes.float64, dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.int32, dtypes.int32, - dtypes.uint32, dtypes.uint32, dtypes.uint32, - dtypes.int16, dtypes.int16, dtypes.int16, - dtypes.uint16, dtypes.uint16, dtypes.uint16, - dtypes.int8, dtypes.int8, dtypes.int8, - dtypes.uint8, dtypes.uint8, dtypes.uint8, - dtypes.uint8c, dtypes.uint8c, dtypes.uint8c -]; - -var add = dispatch( fcns, types, null, 3, 2, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var zbuf = new Float64Array( xbuf.length ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var z = ndarray( 'float64', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); - -xbuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -ybuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -zbuf = new Int32Array( xbuf.length ); - -x = ndarray( 'int32', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'int32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -z = ndarray( 'int32', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); diff --git a/examples/sin.js b/examples/sin.js deleted file mode 100644 index 8cd4871..0000000 --- a/examples/sin.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int8Array = require( '@stdlib/array-int8' ); -var sin = require( '@stdlib/math-base-special-sin' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/strided-dtypes' ); -var dispatch = require( './../lib' ); - -function apply( arrays, fcn ) { - var opts; - var xo; - var yo; - var sx; - var sy; - var sh; - var N; - var x; - var y; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - xo = x.order; - yo = y.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - v = fcn( x.get.apply( x, sx ) ); - - opts.order = yo; - sy = ind2sub( sh, i, opts ); - sy.push( v ); - y.set.apply( y, sy ); - } -} - -var fcns = [ - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply -]; - -var types = [ - dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float64, - dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.float64, - dtypes.uint32, dtypes.float64, - dtypes.int16, dtypes.float64, - dtypes.int16, dtypes.float32, - dtypes.uint16, dtypes.float64, - dtypes.uint16, dtypes.float32, - dtypes.int8, dtypes.float64, - dtypes.int8, dtypes.float32, - dtypes.uint8, dtypes.float64, - dtypes.uint8, dtypes.float32, - dtypes.uint8c, dtypes.float64, - dtypes.uint8c, dtypes.float32 -]; - -var data = [ - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin -]; - -var sine = dispatch( fcns, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); - -xbuf = new Int8Array( [ 1, 2, 3, 4, 5 ] ); -ybuf = new Float32Array( xbuf.length ); - -x = ndarray( 'int8', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'float32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); diff --git a/examples/unary.js b/examples/unary.js deleted file mode 100644 index e9c3fb4..0000000 --- a/examples/unary.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -var unary = require( '@stdlib/ndarray-base-unary' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var dispatch = require( './../lib' ); - -var types = [ 'float64', 'float64' ]; - -var data = [ - abs -]; - -var absolute = dispatch( unary, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -absolute( x, y ); -console.log( ybuf ); -// => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 5f280a1..c49a4e4 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..ad38c4f --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@v0.2.1-esm/index.mjs";function m(m,f,l,p,w,v){var a,g,c;if(i(m))c=m;else if(!s(m))throw new TypeError(d("0jr5d",m));if(!n(f))throw new TypeError(d("0jr2y",f));if(!n(l)&&null!==l)throw new TypeError(d("0jr5e",l));if(!e(p))throw new TypeError(d("0jr5f",p));if(!r(w))throw new TypeError(d("0jr5X",w));if(!r(v))throw new TypeError(d("0jr5g",v));if(0===(a=w+v))throw new Error(d("0jr0h"));if(p!==a)throw new Error(d("0jr0i"));if(c){if(g=f.length/a,!t(g))throw new Error(d("0jr0j"))}else if(g=m.length,f.length!==g*a)throw new Error(d("0jr0j"));if(l&&l.length!==g)throw new Error(d("0jr0k"));return f=function(r){var e,t;for(e=[],t=0;t [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0jr5d', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0jr2y', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( '0jr5e', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0jr5f', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0jr5X', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0jr5g', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format('0jr0h') );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format('0jr0i') );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format('0jr0k') );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format('0jr0l') );\n\t\t\t}\n\t\t\tthrow new Error( format('0jr0m') );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( '0jr5h', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( '0jr5i', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format('0jr0n') );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found).\n*\n* ## Notes\n*\n* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types).\n* - The function assumes that `x` is stored in row-major order.\n* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`.\n* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value.\n*\n* @private\n* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension)\n* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension)\n* @param {ArrayLikeObject} x - input two-dimensional reference array\n* @param {integer} strideX1 - `x` stride length along first dimension\n* @param {integer} strideX2 - `x` stride length along second dimension\n* @param {NonNegativeInteger} offsetX - `x` starting index\n* @param {ArrayLikeObject} y - search array\n* @param {integer} strideY - `y` stride length\n* @param {NonNegativeInteger} offsetY - `y` starting index\n* @returns {integer} row index (if found) and `-1` otherwise\n*\n* @example\n* // Define a reference array to search:\n* var types = [\n* 'float64', 'float64', 'float64',\n* 'float32', 'float32', 'float32',\n* 'uint32', 'uint32', 'float64',\n* 'int32', 'int32', 'float64',\n* 'uint16', 'uint16', 'float64',\n* 'int16', 'int16', 'float64',\n* 'uint8', 'uint8', 'float64',\n* 'int8', 'int8', 'float64'\n* ];\n*\n* // Define reference array dimensions:\n* var N = 8; // rows\n* var M = 3; // columns\n*\n* // Define a search array:\n* y1 = [\n* 'float32', 'float32', 'float32',\n* ];\n*\n* // Find the list of types:\n* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 );\n* // returns 1\n*\n// Define a search array:\n* y2 = [\n* 'float32', 'float32', 'float64',\n* ];\n*\n* // Find the list of types:\n* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 );\n* // returns -1\n*/\nfunction indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len\n\tvar ix;\n\tvar iy;\n\tvar i;\n\tvar j;\n\n\t// Search for the first row which matches `y`...\n\tix = offsetX;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tiy = offsetY;\n\t\tfor ( j = 0; j < M; j++ ) {\n\t\t\tif ( x[ ix+(j*strideX2) ] !== y[ iy ] ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tiy += strideY;\n\t\t}\n\t\t// If we successfully iterated over all columns, then that means we've found a match...\n\t\tif ( j === M ) {\n\t\t\treturn i;\n\t\t}\n\t\tix += strideX1;\n\t}\n\treturn -1;\n}\n\n\n// EXPORTS //\n\nexport default indexOfTypes;\n"],"names":["dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","out","i","push","resolveEnum","types2enums","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","getDType","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","j","indexOfTypes","slice"],"mappings":";;0+BA0GA,SAASA,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAO,UAEzB,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAO,UAEzB,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAO,eAIzB,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAO,UAG1B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAO,UAGzB,OADAX,EA5GD,SAAsBA,GACrB,IAAIkB,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAInB,EAAMgB,OAAQG,IAC9BD,EAAIE,KAAMC,EAAarB,EAAOmB,KAE/B,OAAOD,CACR,CAmGSI,CAAatB,GAgBrB,WACC,IAAIuB,EACAC,EACAC,EACAC,EACAC,EACAC,EACAT,EAGJ,GADAM,EAAOI,UAAUb,OACZS,IAASvB,EAAQ,CACrB,GAAKuB,EAAOvB,EACX,MAAM,IAAIa,MAAOJ,EAAO,UAEzB,MAAM,IAAII,MAAOJ,EAAO,SACxB,CAGD,IAFAY,EAAS,GACTC,EAAS,GACHL,EAAI,EAAGA,EAAIjB,EAAOiB,IAAM,CAE7B,IAAMW,EADNH,EAAIE,UAAWV,IAEd,MAAKA,EAAIhB,EACF,IAAIO,UAAWC,EAAQ,QAASgB,IAEhC,IAAIjB,UAAWC,EAAQ,QAASgB,IAGxCJ,EAAOH,KAAMO,GACbH,EAAOJ,KAAMC,EAAaU,EAAUJ,IACpC,CAKD,IAHAD,EC1HF,SAAuBM,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAvB,EACAwB,EAIJ,IADAF,EAAKJ,EACClB,EAAI,EAAGA,EAAIa,EAAGb,IAAM,CAEzB,IADAuB,EAAKF,EACCG,EAAI,EAAGA,EAAIV,GACXC,EAAGO,EAAIE,EAAEP,KAAgBE,EAAGI,GADdC,IAInBD,GAAMH,EAGP,GAAKI,IAAMV,EACV,OAAOd,EAERsB,GAAMN,CACN,CACD,OAAQ,CACT,CDmGQS,CAActC,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGmB,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAId,UAAWC,EAAO,UAI5BiB,EADIrB,GAGAR,EAAM2B,GAGNzB,EACJ2B,EAAGL,EAAQtB,EAAMyB,IAEjBE,EAAGL,GAEJ,GAAc,IAATnB,EACJ,OAAOmB,EAAQlB,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOmB,EAAOsB,MAAO1C,EACrB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 291641d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Create an ndarray function interface which performs multiple dispatch. -* -* @module @stdlib/ndarray-dispatch -* -* @example -* var dispatch = require( '@stdlib/ndarray-dispatch' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/index_of_types.js b/lib/index_of_types.js deleted file mode 100644 index fda2297..0000000 --- a/lib/index_of_types.js +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found). -* -* ## Notes -* -* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types). -* - The function assumes that `x` is stored in row-major order. -* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`. -* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value. -* -* @private -* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension) -* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension) -* @param {ArrayLikeObject} x - input two-dimensional reference array -* @param {integer} strideX1 - `x` stride length along first dimension -* @param {integer} strideX2 - `x` stride length along second dimension -* @param {NonNegativeInteger} offsetX - `x` starting index -* @param {ArrayLikeObject} y - search array -* @param {integer} strideY - `y` stride length -* @param {NonNegativeInteger} offsetY - `y` starting index -* @returns {integer} row index (if found) and `-1` otherwise -* -* @example -* // Define a reference array to search: -* var types = [ -* 'float64', 'float64', 'float64', -* 'float32', 'float32', 'float32', -* 'uint32', 'uint32', 'float64', -* 'int32', 'int32', 'float64', -* 'uint16', 'uint16', 'float64', -* 'int16', 'int16', 'float64', -* 'uint8', 'uint8', 'float64', -* 'int8', 'int8', 'float64' -* ]; -* -* // Define reference array dimensions: -* var N = 8; // rows -* var M = 3; // columns -* -* // Define a search array: -* y1 = [ -* 'float32', 'float32', 'float32', -* ]; -* -* // Find the list of types: -* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 ); -* // returns 1 -* -// Define a search array: -* y2 = [ -* 'float32', 'float32', 'float64', -* ]; -* -* // Find the list of types: -* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 ); -* // returns -1 -*/ -function indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len - var ix; - var iy; - var i; - var j; - - // Search for the first row which matches `y`... - ix = offsetX; - for ( i = 0; i < N; i++ ) { - iy = offsetY; - for ( j = 0; j < M; j++ ) { - if ( x[ ix+(j*strideX2) ] !== y[ iy ] ) { - break; - } - iy += strideY; - } - // If we successfully iterated over all columns, then that means we've found a match... - if ( j === M ) { - return i; - } - ix += strideX1; - } - return -1; -} - - -// EXPORTS // - -module.exports = indexOfTypes; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4648598..0000000 --- a/lib/main.js +++ /dev/null @@ -1,231 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isFunctionArray = require( '@stdlib/assert-is-function-array' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var resolveEnum = require( '@stdlib/ndarray-base-dtype-resolve-enum' ); -var indexOfTypes = require( './index_of_types.js' ); - - -// FUNCTIONS // - -/** -* Returns a list of data type enumeration constants. -* -* @private -* @param {Collection} types - list of types -* @returns {IntegerArray} list of data type enumeration constants -*/ -function types2enums( types ) { - var out; - var i; - - out = []; - for ( i = 0; i < types.length; i++ ) { - out.push( resolveEnum( types[ i ] ) ); - } - return out; -} - - -// MAIN // - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param {(FunctionArray|Function)} fcns - list of ndarray functions -* @param {Collection} types - one-dimensional list of ndarray argument data types -* @param {(Collection|null)} data - ndarray function data (e.g., callbacks) -* @param {PositiveInteger} nargs - total number of ndarray function interface arguments -* @param {NonNegativeInteger} nin - number of input ndarrays -* @param {NonNegativeInteger} nout - number of output ndarrays -* @throws {TypeError} first argument must be either a function or an array of functions -* @throws {TypeError} second argument must be an array-like object -* @throws {TypeError} third argument must be an array-like object or `null` -* @throws {Error} third and first arguments must have the same number of elements -* @throws {TypeError} fourth argument must be a positive integer -* @throws {TypeError} fifth argument must be a nonnegative integer -* @throws {TypeError} sixth argument must be a nonnegative integer -* @throws {Error} fourth argument must equal the specified number of input and output arrays -* @throws {Error} number of types must match the number of functions times the total number of array arguments for each function -* @throws {Error} interface must accept at least one input and/or output ndarray -* @returns {Function} ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function dispatch( fcns, types, data, nargs, nin, nout ) { - var narrays; - var nfcns; - var fcn; - - if ( isFunction( fcns ) ) { - fcn = fcns; - } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( '0jr5d', fcns ) ); - } - if ( !isCollection( types ) ) { - throw new TypeError( format( '0jr2y', types ) ); - } - if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( '0jr5e', data ) ); - } - if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( '0jr5f', nargs ) ); - } - if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( '0jr5X', nin ) ); - } - if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( '0jr5g', nout ) ); - } - narrays = nin + nout; - if ( narrays === 0 ) { - throw new Error( format('0jr0h') ); - } - if ( nargs !== narrays ) { - throw new Error( format('0jr0i') ); - } - if ( fcn ) { - nfcns = types.length / narrays; - if ( !isInteger( nfcns ) ) { - throw new Error( format('0jr0j') ); - } - } else { - nfcns = fcns.length; - if ( types.length !== nfcns*narrays ) { - throw new Error( format('0jr0j') ); - } - } - if ( data && data.length !== nfcns ) { - throw new Error( format('0jr0k') ); - } - types = types2enums( types ); - return dispatcher; - - /** - * ndarray function interface which performs multiple dispatch. - * - * @private - * @param {ndarrayLike} x - ndarray - * @param {...ndarrayLike} args - ndarray arguments - * @throws {Error} insufficient arguments - * @throws {Error} too many arguments - * @throws {TypeError} input array arguments must be ndarray-like objects - * @throws {TypeError} output array arguments must be ndarray-like objects - * @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types - * @returns {(ndarrayLike|Array|void)} destination array(s) - */ - function dispatcher() { - var arrays; - var dtypes; - var argc; - var idx; - var v; - var f; - var i; - - argc = arguments.length; - if ( argc !== nargs ) { - if ( argc < nargs ) { - throw new Error( format('0jr0l') ); - } - throw new Error( format('0jr0m') ); - } - arrays = []; - dtypes = []; - for ( i = 0; i < nargs; i++ ) { - v = arguments[ i ]; - if ( !isndarrayLike( v ) ) { - if ( i < nin ) { - throw new TypeError( format( '0jr5h', v ) ); - } else { - throw new TypeError( format( '0jr5i', v ) ); - } - } - arrays.push( v ); - dtypes.push( resolveEnum( getDType( v ) ) ); - } - // Resolve the ndarray function satisfying the input array types: - idx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len - - // Check whether we were able to successfully resolve an ndarray function: - if ( idx < 0 ) { - throw new TypeError( format('0jr0n') ); - } - // Retrieve the ndarray function: - if ( fcn ) { - f = fcn; - } else { - f = fcns[ idx ]; - } - // Evaluate the ndarray function: - if ( data ) { - f( arrays, data[ idx ] ); - } else { - f( arrays ); - } - if ( nout === 1 ) { - return arrays[ narrays-1 ]; - } - if ( nout === 0 ) { - return; - } - return arrays.slice( nin ); - } -} - - -// EXPORTS // - -module.exports = dispatch; diff --git a/package.json b/package.json index d66c7e4..ffe4f55 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Create an ndarray function interface which performs multiple dispatch.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,57 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-collection": "^0.2.1", - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/assert-is-function-array": "^0.2.1", - "@stdlib/assert-is-integer": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/assert-is-nonnegative-integer": "^0.2.1", - "@stdlib/assert-is-positive-integer": "^0.2.1", - "@stdlib/ndarray-base-dtype-resolve-enum": "^0.2.1", - "@stdlib/ndarray-dtype": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.2.1", - "@stdlib/array-float64": "^0.2.1", - "@stdlib/array-int32": "^0.2.1", - "@stdlib/array-int8": "^0.2.1", - "@stdlib/array-uint8": "^0.2.1", - "@stdlib/math-base-assert-is-nan": "^0.2.1", - "@stdlib/math-base-special-abs": "^0.2.1", - "@stdlib/math-base-special-pow": "^0.2.1", - "@stdlib/math-base-special-sin": "^0.2.1", - "@stdlib/ndarray-base-buffer-dtype": "^0.2.1", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-base-unary": "^0.2.1", - "@stdlib/ndarray-ctor": "^0.2.1", - "@stdlib/ndarray-dtypes": "^0.2.1", - "@stdlib/ndarray-ind2sub": "^0.2.1", - "@stdlib/strided-dtypes": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "ndarray", @@ -100,7 +26,6 @@ "multimethod", "multimethods" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..f1e9034 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/fixtures/binary.js b/test/fixtures/binary.js deleted file mode 100644 index a60dfa2..0000000 --- a/test/fixtures/binary.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Binary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @returns {number} sum -*/ -function binary( x, y ) { - return x + y; -} - - -// EXPORTS // - -module.exports = binary; diff --git a/test/fixtures/fill.js b/test/fixtures/fill.js deleted file mode 100644 index 41b2958..0000000 --- a/test/fixtures/fill.js +++ /dev/null @@ -1,76 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which fills one or more ndarrays. -* -* @private -* @param {*} value - fill value -* @returns {Function} ndarray function -*/ -function fill( value ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - */ - function ndarrayFcn( arrays ) { - var opts; - var sub; - var arr; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - opts = { - 'order': '' - }; - for ( j = 0; j < M; j++ ) { - arr = arrays[ j ]; - opts.order = arrays[ j ].order; - for ( i = 0; i < N; i++ ) { - sub = ind2sub( sh, i, opts ); - sub.push( value ); - arr.set.apply( arr, sub ); - } - } - } -} - - -// EXPORTS // - -module.exports = fill; diff --git a/test/fixtures/foreach.js b/test/fixtures/foreach.js deleted file mode 100644 index a426290..0000000 --- a/test/fixtures/foreach.js +++ /dev/null @@ -1,72 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function forEach( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - fcn.apply( null, args ); - } -} - - -// EXPORTS // - -module.exports = forEach; diff --git a/test/fixtures/map1n.js b/test/fixtures/map1n.js deleted file mode 100644 index 614196b..0000000 --- a/test/fixtures/map1n.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function which maps the return value of a callback to `N` arrays. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function map1N( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var v; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - v = fcn(); - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - sub.push( v ); - arrays[ j ].set.apply( arrays[ j ], sub ); - } - } -} - - -// EXPORTS // - -module.exports = map1N; diff --git a/test/fixtures/nullary.js b/test/fixtures/nullary.js deleted file mode 100644 index 4f22126..0000000 --- a/test/fixtures/nullary.js +++ /dev/null @@ -1,36 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Nullary callback. -* -* @private -* @returns {number} value -*/ -function nullary() { - return 3.0; -} - - -// EXPORTS // - -module.exports = nullary; diff --git a/test/fixtures/quaternary.js b/test/fixtures/quaternary.js deleted file mode 100644 index 548437b..0000000 --- a/test/fixtures/quaternary.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quaternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @returns {number} sum -*/ -function quaternary( x, y, z, w ) { - return x + y + z + w; -} - - -// EXPORTS // - -module.exports = quaternary; diff --git a/test/fixtures/quinary.js b/test/fixtures/quinary.js deleted file mode 100644 index 36068de..0000000 --- a/test/fixtures/quinary.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quinary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @param {number} u - input value -* @returns {number} sum -*/ -function quinary( x, y, z, w, u ) { - return x + y + z + w + u; -} - - -// EXPORTS // - -module.exports = quinary; diff --git a/test/fixtures/sum.js b/test/fixtures/sum.js deleted file mode 100644 index efdbb1b..0000000 --- a/test/fixtures/sum.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which computes the sum across one or more ndarrays. -* -* @private -* @param {Object} ctx - context -* @param {number} ctx.sum - initial sum -* @returns {Function} ndarray function -*/ -function wrapper( ctx ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - * @param {Function} [fcn] - callback - */ - function ndarrayFcn( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var f; - var i; - var j; - - if ( arguments.length > 1 ) { - f = fcn; - } - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - if ( f ) { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - ctx.sum += f.apply( null, args ); - } - } else { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - ctx.sum += arrays[ j ].get.apply( arrays[ j ], sub ); - } - } - } - } -} - - -// EXPORTS // - -module.exports = wrapper; diff --git a/test/fixtures/ternary.js b/test/fixtures/ternary.js deleted file mode 100644 index 0595d5f..0000000 --- a/test/fixtures/ternary.js +++ /dev/null @@ -1,39 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Ternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @returns {number} sum -*/ -function ternary( x, y, z ) { - return x + y + z; -} - - -// EXPORTS // - -module.exports = ternary; diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d6c2c8e..0000000 --- a/test/test.js +++ /dev/null @@ -1,363 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var fill = require( './fixtures/fill.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either a function or an array of functions as a first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( value, types, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object as a second argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided either an array-like object or `null` as a third argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - dispatch( unary, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a positive integer for a fourth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 0, - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a fifth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, value, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a sixth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, 1, value ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function array)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var fcns = [ unary, unary, unary ]; - var data = [ abs, abs, abs ]; - dispatch( fcns, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function argument)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs, abs, abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the length of `data` argument does not match the number of ndarray functions', function test( t ) { - var values; - var i; - - values = [ - [], - [ abs, abs ], - [ abs, abs, abs ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var fcns = [ unary ]; - dispatch( fcns, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the fourth argument is incompatible with the number of input and output ndarrays', function test( t ) { - var values; - var i; - - values = [ - 0, - 1, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of specified input and output ndarrays is zero', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var types = [ 'float64' ]; - dispatch( fill( 3 ), types, null, 1, 0, 0 ); - } -}); - -tape( 'the function returns an ndarray function interface', function test( t ) { - var types; - var data; - var f; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - f = dispatch( unary, types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ unary ], types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( fill( 3 ), types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ fill( 3 ) ], types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.two_arrays.js b/test/test.two_arrays.js deleted file mode 100644 index 16eb61b..0000000 --- a/test/test.two_arrays.js +++ /dev/null @@ -1,814 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var dtype = require( '@stdlib/ndarray-base-buffer-dtype' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var forEach = require( './fixtures/foreach.js' ); -var map1N = require( './fixtures/map1n.js' ); -var fill = require( './fixtures/fill.js' ); -var sum = require( './fixtures/sum.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the first argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var ybuf = new Float64Array( 10 ); - var y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( value, y ); - }; - } -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the second argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var xbuf = new Float64Array( 10 ); - var x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( x, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided insufficient arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var f; - var x; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [], - [ x ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided too many arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var ybuf; - var f; - var x; - var y; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [ x, y, y ], - [ x, y, y, y ], - [ x, y, y, y, y ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if unable to resolve a ndarray function supporting the provided array argument data types', function test( t ) { - var values; - var types; - var data; - var xbuf; - var fcn; - var x; - var i; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ abs, abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 4 ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - values = [ - new Uint8Array( 4 ), - new Int32Array( 4 ), - [ 0, 0, 0, 0 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided an array having data type: ' + dtype( values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var y = ndarray( dtype( value ), value, [ value.length ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - }; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only input arrays)', function test( t ) { - var types; - var xbuf; - var ybuf; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only output arrays)', function test( t ) { - var expected; - var types; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only input arrays)', function test( t ) { - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var ctx; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcns = [ - sum( ctx ), - sum( ctx ) - ]; - fcn = dispatch( fcns, types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only output arrays)', function test( t ) { - var expected; - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcns = [ - fill( 3.0 ), - fill( 4.0 ) - ]; - fcn = dispatch( fcns, types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - - fcn = dispatch( forEach, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - - fcn = dispatch( map1N, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - fcns = [ - forEach, - forEach - ]; - fcn = dispatch( fcns, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - fcns = [ - map1N, - map1N - ]; - fcn = dispatch( fcns, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - fcns = [ - unary, - unary - ]; - fcn = dispatch( fcns, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which returns one or more output arrays, if one or more output arrays is specified, and otherwise returns `undefined`', function test( t ) { - var types; - var data; - var xbuf; - var ybuf; - var out; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - // No output arrays... - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, void 0, 'returns expected value' ); - - // One output array... - data = [ - abs, - abs - ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - fcn = dispatch( fill( 3.0 ), types, null, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - // Two output arrays... - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.end(); -}); From 898783c19c4b77a2d1fb5ade4d43914297679066 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 07:37:56 +0000 Subject: [PATCH 072/109] Transform error messages --- lib/main.js | 34 +++++++++++++++++----------------- package.json | 2 +- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/main.js b/lib/main.js index 5f4bb5d..4648598 100644 --- a/lib/main.js +++ b/lib/main.js @@ -27,7 +27,7 @@ var isFunctionArray = require( '@stdlib/assert-is-function-array' ); var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var getDType = require( '@stdlib/ndarray-dtype' ); var resolveEnum = require( '@stdlib/ndarray-base-dtype-resolve-enum' ); var indexOfTypes = require( './index_of_types.js' ); @@ -112,43 +112,43 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { if ( isFunction( fcns ) ) { fcn = fcns; } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) ); + throw new TypeError( format( '0jr5d', fcns ) ); } if ( !isCollection( types ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) ); + throw new TypeError( format( '0jr2y', types ) ); } if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); + throw new TypeError( format( '0jr5e', data ) ); } if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) ); + throw new TypeError( format( '0jr5f', nargs ) ); } if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) ); + throw new TypeError( format( '0jr5X', nin ) ); } if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) ); + throw new TypeError( format( '0jr5g', nout ) ); } narrays = nin + nout; if ( narrays === 0 ) { - throw new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' ); + throw new Error( format('0jr0h') ); } if ( nargs !== narrays ) { - throw new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' ); + throw new Error( format('0jr0i') ); } if ( fcn ) { nfcns = types.length / narrays; if ( !isInteger( nfcns ) ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format('0jr0j') ); } } else { nfcns = fcns.length; if ( types.length !== nfcns*narrays ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format('0jr0j') ); } } if ( data && data.length !== nfcns ) { - throw new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' ); + throw new Error( format('0jr0k') ); } types = types2enums( types ); return dispatcher; @@ -178,9 +178,9 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { argc = arguments.length; if ( argc !== nargs ) { if ( argc < nargs ) { - throw new Error( 'invalid invocation. Insufficient arguments.' ); + throw new Error( format('0jr0l') ); } - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('0jr0m') ); } arrays = []; dtypes = []; @@ -188,9 +188,9 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { v = arguments[ i ]; if ( !isndarrayLike( v ) ) { if ( i < nin ) { - throw new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) ); + throw new TypeError( format( '0jr5h', v ) ); } else { - throw new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) ); + throw new TypeError( format( '0jr5i', v ) ); } } arrays.push( v ); @@ -201,7 +201,7 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { // Check whether we were able to successfully resolve an ndarray function: if ( idx < 0 ) { - throw new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' ); + throw new TypeError( format('0jr0n') ); } // Retrieve the ndarray function: if ( fcn ) { diff --git a/package.json b/package.json index 996faed..d66c7e4 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/assert-is-positive-integer": "^0.2.1", "@stdlib/ndarray-base-dtype-resolve-enum": "^0.2.1", "@stdlib/ndarray-dtype": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, From 5dabab763ea610c71e9734550726d70a11a0c1ed Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 13:06:53 +0000 Subject: [PATCH 073/109] Remove files --- index.d.ts | 334 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5181 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index c49a4e4..0000000 --- a/index.d.ts +++ /dev/null @@ -1,334 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* ndarray function. -* -* @param arrays - array containing input and output ndarrays -* @param data - ndarray function data (e.g., a callback) -* -* @example -* var numel = require( '@stdlib/ndarray-base-numel' ); -* var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -* -* function ndarrayFcn( arrays, fcn ) { -* var xord; -* var yord; -* var opts; -* var sub; -* var sh; -* var N; -* var x; -* var y; -* var v; -* var i; -* -* x = arrays[ 0 ]; -* y = arrays[ 1 ]; -* sh = x.shape; -* N = numel( sh ); -* if ( N <= 0 ) { -* return; -* } -* xord = x.order; -* yord = y.order; -* opts = {}; -* opts.order = xord; -* for ( i = 0; i < N; i++ ) { -* // Convert a linear index to subscripts: -* opts.order = xord; -* sub = ind2sub( sh, i, opts ); -* -* // Retrieve an element from `x`: -* v = x.get.apply( x, sub ); -* -* // Convert a linear index to subscripts: -* opts.order = yord; -* sub = ind2sub( sh, i, opts ); -* -* // Append the result of applying the callback: -* sub.push( fcn( v ) ); -* -* // Assign the result to an element in `y`: -* y.set.apply( y, sub ); -* } -* } -*/ -type ndarrayFcn = ( arrays: Array, data?: any ) => void; - -/** -* Interface describing an ndarray function dispatcher. -*/ -interface Dispatcher { - /** - * Invokes an ndarray function based on the provided array data type(s). - * - * @param x - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array - * - * @example - * var nullary = require( '@stdlib/ndarray-base-nullary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function value() { - * return 3.14; - * } - * - * var types = [ 'float64' ]; - * var data = [ value ]; - * - * var fcn = dispatch( nullary, types, data, 1, 0, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( 5 ); - * var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x ); - * // xbuf => [ 3.14, 3.14, 3.14, 3.14, 3.14 ] - */ - ( x: ndarray ): ndarray | void; - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var unary = require( '@stdlib/ndarray-base-unary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * var abs = require( '@stdlib/math-base-special-abs' ); - * - * var types = [ 'float64', 'float64' ]; - * var data = [ abs ]; - * - * var fcn = dispatch( unary, types, data, 2, 1, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - * var ybuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y ); - * // ybuf => [ 1.0, 2.0, 3.0 ] - */ - ( x: ndarray, y: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var ternary = require( '@stdlib/ndarray-base-ternary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function add2( x, y ) { - * return x + y; - * } - * - * var types = [ 'float64', 'float64', 'float64' ]; - * var data = [ add2 ]; - * - * var fcn = dispatch( ternary, types, data, 3, 2, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z ); - * // zbuf => [ 2.0, 4.0, 6.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quaternary = require( '@stdlib/ndarray-base-quaternary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function add3( x, y, z ) { - * return x + y + z; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add3 ]; - * - * var fcn = dispatch( quaternary, types, data, 4, 3, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w ); - * // wbuf => [ 3.0, 6.0, 9.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @param args - ndarray arguments - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quinary = require( '@stdlib/ndarray-base-quinary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function add4( x, y, z, w ) { - * return x + y + z + w; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add4 ]; - * - * var fcn = dispatch( quinary, types, data, 5, 4, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ubuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var u = ndarray( 'float64', ubuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w, u ); - * // ubuf => [ 4.0, 8.0, 12.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray, ...args: Array ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures -} - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param fcns - list of ndarray functions -* @param types - one-dimensional list of ndarray argument data types -* @param data - ndarray function data (e.g., callbacks) -* @param nargs - total number of ndarray function interface arguments -* @param nin - number of input ndarrays -* @param nout - number of output ndarrays -* @throws first argument must be either a function or an array of functions -* @throws second argument must be an array-like object -* @throws third argument must be an array-like object or `null` -* @throws third and first arguments must have the same number of elements -* @throws fourth argument must be a positive integer -* @throws fifth argument must be a nonnegative integer -* @throws sixth argument must be a nonnegative integer -* @throws fourth argument must equal the specified number of input and output arrays -* @throws number of types must match the number of functions times the total number of array arguments for each function -* @throws interface must accept at least one input and/or output ndarray -* @returns ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var fcn = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* fcn( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function dispatch( fcns: ndarrayFcn | ArrayLike, types: ArrayLike, data: ArrayLike | null, nargs: number, nin: number, nout: number ): Dispatcher; - - -// EXPORTS // - -export = dispatch; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index ad38c4f..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@v0.2.1-esm/index.mjs";function m(m,f,l,p,w,v){var a,g,c;if(i(m))c=m;else if(!s(m))throw new TypeError(d("0jr5d",m));if(!n(f))throw new TypeError(d("0jr2y",f));if(!n(l)&&null!==l)throw new TypeError(d("0jr5e",l));if(!e(p))throw new TypeError(d("0jr5f",p));if(!r(w))throw new TypeError(d("0jr5X",w));if(!r(v))throw new TypeError(d("0jr5g",v));if(0===(a=w+v))throw new Error(d("0jr0h"));if(p!==a)throw new Error(d("0jr0i"));if(c){if(g=f.length/a,!t(g))throw new Error(d("0jr0j"))}else if(g=m.length,f.length!==g*a)throw new Error(d("0jr0j"));if(l&&l.length!==g)throw new Error(d("0jr0k"));return f=function(r){var e,t;for(e=[],t=0;t [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0jr5d', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0jr2y', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( '0jr5e', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0jr5f', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0jr5X', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0jr5g', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format('0jr0h') );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format('0jr0i') );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format('0jr0k') );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format('0jr0l') );\n\t\t\t}\n\t\t\tthrow new Error( format('0jr0m') );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( '0jr5h', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( '0jr5i', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format('0jr0n') );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found).\n*\n* ## Notes\n*\n* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types).\n* - The function assumes that `x` is stored in row-major order.\n* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`.\n* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value.\n*\n* @private\n* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension)\n* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension)\n* @param {ArrayLikeObject} x - input two-dimensional reference array\n* @param {integer} strideX1 - `x` stride length along first dimension\n* @param {integer} strideX2 - `x` stride length along second dimension\n* @param {NonNegativeInteger} offsetX - `x` starting index\n* @param {ArrayLikeObject} y - search array\n* @param {integer} strideY - `y` stride length\n* @param {NonNegativeInteger} offsetY - `y` starting index\n* @returns {integer} row index (if found) and `-1` otherwise\n*\n* @example\n* // Define a reference array to search:\n* var types = [\n* 'float64', 'float64', 'float64',\n* 'float32', 'float32', 'float32',\n* 'uint32', 'uint32', 'float64',\n* 'int32', 'int32', 'float64',\n* 'uint16', 'uint16', 'float64',\n* 'int16', 'int16', 'float64',\n* 'uint8', 'uint8', 'float64',\n* 'int8', 'int8', 'float64'\n* ];\n*\n* // Define reference array dimensions:\n* var N = 8; // rows\n* var M = 3; // columns\n*\n* // Define a search array:\n* y1 = [\n* 'float32', 'float32', 'float32',\n* ];\n*\n* // Find the list of types:\n* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 );\n* // returns 1\n*\n// Define a search array:\n* y2 = [\n* 'float32', 'float32', 'float64',\n* ];\n*\n* // Find the list of types:\n* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 );\n* // returns -1\n*/\nfunction indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len\n\tvar ix;\n\tvar iy;\n\tvar i;\n\tvar j;\n\n\t// Search for the first row which matches `y`...\n\tix = offsetX;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tiy = offsetY;\n\t\tfor ( j = 0; j < M; j++ ) {\n\t\t\tif ( x[ ix+(j*strideX2) ] !== y[ iy ] ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tiy += strideY;\n\t\t}\n\t\t// If we successfully iterated over all columns, then that means we've found a match...\n\t\tif ( j === M ) {\n\t\t\treturn i;\n\t\t}\n\t\tix += strideX1;\n\t}\n\treturn -1;\n}\n\n\n// EXPORTS //\n\nexport default indexOfTypes;\n"],"names":["dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","out","i","push","resolveEnum","types2enums","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","getDType","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","j","indexOfTypes","slice"],"mappings":";;0+BA0GA,SAASA,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAO,UAEzB,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAO,UAEzB,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAO,eAIzB,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAO,UAG1B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAO,UAGzB,OADAX,EA5GD,SAAsBA,GACrB,IAAIkB,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAInB,EAAMgB,OAAQG,IAC9BD,EAAIE,KAAMC,EAAarB,EAAOmB,KAE/B,OAAOD,CACR,CAmGSI,CAAatB,GAgBrB,WACC,IAAIuB,EACAC,EACAC,EACAC,EACAC,EACAC,EACAT,EAGJ,GADAM,EAAOI,UAAUb,OACZS,IAASvB,EAAQ,CACrB,GAAKuB,EAAOvB,EACX,MAAM,IAAIa,MAAOJ,EAAO,UAEzB,MAAM,IAAII,MAAOJ,EAAO,SACxB,CAGD,IAFAY,EAAS,GACTC,EAAS,GACHL,EAAI,EAAGA,EAAIjB,EAAOiB,IAAM,CAE7B,IAAMW,EADNH,EAAIE,UAAWV,IAEd,MAAKA,EAAIhB,EACF,IAAIO,UAAWC,EAAQ,QAASgB,IAEhC,IAAIjB,UAAWC,EAAQ,QAASgB,IAGxCJ,EAAOH,KAAMO,GACbH,EAAOJ,KAAMC,EAAaU,EAAUJ,IACpC,CAKD,IAHAD,EC1HF,SAAuBM,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAvB,EACAwB,EAIJ,IADAF,EAAKJ,EACClB,EAAI,EAAGA,EAAIa,EAAGb,IAAM,CAEzB,IADAuB,EAAKF,EACCG,EAAI,EAAGA,EAAIV,GACXC,EAAGO,EAAIE,EAAEP,KAAgBE,EAAGI,GADdC,IAInBD,GAAMH,EAGP,GAAKI,IAAMV,EACV,OAAOd,EAERsB,GAAMN,CACN,CACD,OAAQ,CACT,CDmGQS,CAActC,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGmB,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAId,UAAWC,EAAO,UAI5BiB,EADIrB,GAGAR,EAAM2B,GAGNzB,EACJ2B,EAAGL,EAAQtB,EAAMyB,IAEjBE,EAAGL,GAEJ,GAAc,IAATnB,EACJ,OAAOmB,EAAQlB,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOmB,EAAOsB,MAAO1C,EACrB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index f1e9034..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 6f7fa8a8ecdb307f8bb8c8bd0de23b392fe7df92 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 13:07:15 +0000 Subject: [PATCH 074/109] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 61 +- SECURITY.md | 5 - benchmark/benchmark.dispatch_size.js | 156 - benchmark/benchmark.js | 81 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 87 - docs/types/test.ts | 641 --- examples/add.js | 121 - examples/sin.js | 142 - examples/unary.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/index_of_types.js | 106 - lib/main.js | 231 - package.json | 79 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/binary.js | 38 - test/fixtures/fill.js | 76 - test/fixtures/foreach.js | 72 - test/fixtures/map1n.js | 74 - test/fixtures/nullary.js | 36 - test/fixtures/quaternary.js | 40 - test/fixtures/quinary.js | 41 - test/fixtures/sum.js | 98 - test/fixtures/ternary.js | 39 - test/test.js | 363 -- test/test.two_arrays.js | 814 ---- 57 files changed, 4876 insertions(+), 6751 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.dispatch_size.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/add.js delete mode 100644 examples/sin.js delete mode 100644 examples/unary.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/index_of_types.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/fixtures/binary.js delete mode 100644 test/fixtures/fill.js delete mode 100644 test/fixtures/foreach.js delete mode 100644 test/fixtures/map1n.js delete mode 100644 test/fixtures/nullary.js delete mode 100644 test/fixtures/quaternary.js delete mode 100644 test/fixtures/quinary.js delete mode 100644 test/fixtures/sum.js delete mode 100644 test/fixtures/ternary.js delete mode 100644 test/test.js delete mode 100644 test/test.two_arrays.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index c0323c0..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-04-01T05:17:47.277Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ac0b7cd..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 5e92c3e..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2b4fac7..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '43 7 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index ec90164..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -304,7 +295,7 @@ console.log( ybuf ); ## 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. +This package is part of [stdlib][stdlib], a standard library 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]. @@ -367,11 +358,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-dispatch/main/LICENSE -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.dispatch_size.js b/benchmark/benchmark.dispatch_size.js deleted file mode 100644 index 15805ba..0000000 --- a/benchmark/benchmark.dispatch_size.js +++ /dev/null @@ -1,156 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib/main.js' ); - - -// FUNCTIONS // - -/** -* Evaluates the identity function. -* -* @private -* @param {*} v - value -* @returns {*} input value -*/ -function identity( v ) { - return v; -} - -/** -* Dummy function which throws an error. -* -* @private -* @throws {Error} unexpected error -*/ -function throwError() { - throw new Error( 'unexpected error' ); -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} size - dispatch size -* @returns {Function} benchmark function -*/ -function createBenchmark( size ) { - var types; - var data; - var fcn; - var x; - var y; - var t; - var i; - - types = []; - - // Create dummy types... - for ( i = 0; i < (size-1)*2; i += 2 ) { - t = 'foo' + i; - types.push( t ); - types.push( t ); - } - // Append test types: - types.push( 'float64' ); - types.push( 'float64' ); - - // Define a list of callbacks: - data = []; - for ( i = 0; i < size-1; i++ ) { - data.push( throwError ); - } - // Append a test callback: - data.push( identity ); - - // Create the dispatcher: - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - // Create sample arrays: - x = new Float64Array( 1 ); - y = new Float64Array( x.length ); - - x = ndarray( 'float64', x, [ 1 ], [ 1 ], 0, 'row-major' ); - y = ndarray( 'float64', y, [ 1 ], [ 1 ], 0, 'row-major' ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var z; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x.data[ 0 ] = i; - z = fcn( x, y ); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var size; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - size = pow( 2, i ); - f = createBenchmark( size ); - bench( pkg+':size='+size, f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 3c6f450..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::fcns_array', function benchmark( b ) { - var types; - var fcns; - var data; - var out; - var i; - - fcns = [ unary ]; - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( fcns, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::fcn_arg', function benchmark( b ) { - var types; - var data; - var out; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( unary, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0aae4af..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch" -%% click B href "https://github.com/stdlib-js/ndarray-dispatch/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-dispatch/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-dispatch/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-dispatch/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-dispatch/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch -[production-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 1295a44..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import dispatch from '../docs/types/index'; -export = dispatch; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7fb29cb..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var y=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var b=y(function(D,w){ -function k(i,r,e,u,f,m,n,o,l){var h,t,s,a;for(h=m,s=0;s [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( 'invalid invocation. Insufficient arguments.' );\n\t\t\t}\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = dispatch;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an ndarray function interface which performs multiple dispatch.\n*\n* @module @stdlib/ndarray-dispatch\n*\n* @example\n* var dispatch = require( '@stdlib/ndarray-dispatch' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var unary = require( '@stdlib/ndarray-base-unary' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var types = [\n* 'float64', 'float64'\n* ];\n*\n* var data = [\n* abs\n* ];\n*\n* var absolute = dispatch( unary, types, data, 2, 1, 1 );\n*\n* // ...\n*\n* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] );\n* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] );\n*\n* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' );\n* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' );\n*\n* absolute( x, y );\n* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA6EA,SAASC,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,EAAU,CAClF,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,CAAU,IAAME,EAAGI,CAAG,EADjBE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,CACP,CACA,MAAO,EACR,CAKAL,EAAO,QAAUC,ICzGjB,IAAAc,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAoB,QAAS,oCAAqC,EAClEC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAkB,QAAS,kCAAmC,EAC9DC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAc,QAAS,yCAA0C,EACjEC,EAAe,IAYnB,SAASC,EAAaC,EAAQ,CAC7B,IAAIC,EACAC,EAGJ,IADAD,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIF,EAAM,OAAQE,IAC9BD,EAAI,KAAMJ,EAAaG,EAAOE,CAAE,CAAE,CAAE,EAErC,OAAOD,CACR,CAqDA,SAASE,EAAUC,EAAMJ,EAAOK,EAAMC,EAAOC,EAAKC,EAAO,CACxD,IAAIC,EACAC,EACAC,EAEJ,GAAKnB,EAAYY,CAAK,EACrBO,EAAMP,UACK,CAACb,EAAiBa,CAAK,EAClC,MAAM,IAAI,UAAWT,EAAQ,oGAAqGS,CAAK,CAAE,EAE1I,GAAK,CAACX,EAAcO,CAAM,EACzB,MAAM,IAAI,UAAWL,EAAQ,+EAAgFK,CAAM,CAAE,EAEtH,GAAK,CAACP,EAAcY,CAAK,GAAKA,IAAS,KACtC,MAAM,IAAI,UAAWV,EAAQ,sFAAuFU,CAAK,CAAE,EAE5H,GAAK,CAAChB,EAAmBiB,CAAM,EAC9B,MAAM,IAAI,UAAWX,EAAQ,6EAA8EW,CAAM,CAAE,EAEpH,GAAK,CAAClB,EAAsBmB,CAAI,EAC/B,MAAM,IAAI,UAAWZ,EAAQ,+EAAgFY,CAAI,CAAE,EAEpH,GAAK,CAACnB,EAAsBoB,CAAK,EAChC,MAAM,IAAI,UAAWb,EAAQ,+EAAgFa,CAAK,CAAE,EAGrH,GADAC,EAAUF,EAAMC,EACXC,IAAY,EAChB,MAAM,IAAI,MAAO,4IAA6I,EAE/J,GAAKH,IAAUG,EACd,MAAM,IAAI,MAAO,4FAA6F,EAE/G,GAAKE,GAEJ,GADAD,EAAQV,EAAM,OAASS,EAClB,CAACnB,EAAWoB,CAAM,EACtB,MAAM,IAAI,MAAO,8IAA+I,UAGjKA,EAAQN,EAAK,OACRJ,EAAM,SAAWU,EAAMD,EAC3B,MAAM,IAAI,MAAO,8IAA+I,EAGlK,GAAKJ,GAAQA,EAAK,SAAWK,EAC5B,MAAM,IAAI,MAAO,mGAAoG,EAEtH,OAAAV,EAAQD,EAAaC,CAAM,EACpBY,EAeP,SAASA,GAAa,CACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EAGJ,GADAa,EAAO,UAAU,OACZA,IAAST,EACb,MAAKS,EAAOT,EACL,IAAI,MAAO,6CAA8C,EAE1D,IAAI,MAAO,yCAA0C,EAI5D,IAFAO,EAAS,CAAC,EACVC,EAAS,CAAC,EACJZ,EAAI,EAAGA,EAAII,EAAOJ,IAAM,CAE7B,GADAe,EAAI,UAAWf,CAAE,EACZ,CAACR,EAAeuB,CAAE,EACtB,MAAKf,EAAIK,EACF,IAAI,UAAWZ,EAAQ,6EAA8EsB,CAAE,CAAE,EAEzG,IAAI,UAAWtB,EAAQ,8EAA+EsB,CAAE,CAAE,EAGlHJ,EAAO,KAAMI,CAAE,EACfH,EAAO,KAAMjB,EAAaD,EAAUqB,CAAE,CAAE,CAAE,CAC3C,CAKA,GAHAD,EAAMlB,EAAcY,EAAOD,EAAST,EAAOS,EAAS,EAAG,EAAGK,EAAQ,EAAG,CAAE,EAGlEE,EAAM,EACV,MAAM,IAAI,UAAW,6GAA8G,EAcpI,GAXKL,EACJO,EAAIP,EAEJO,EAAId,EAAMY,CAAI,EAGVX,EACJa,EAAGL,EAAQR,EAAMW,CAAI,CAAE,EAEvBE,EAAGL,CAAO,EAENL,IAAS,EACb,OAAOK,EAAQJ,EAAQ,CAAE,EAE1B,GAAKD,IAAS,EAGd,OAAOK,EAAO,MAAON,CAAI,CAC1B,CACD,CAKApB,EAAO,QAAUgB,IC9KjB,IAAIgB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_index_of_types", "__commonJSMin", "exports", "module", "indexOfTypes", "N", "M", "x", "strideX1", "strideX2", "offsetX", "y", "strideY", "offsetY", "ix", "iy", "i", "j", "require_main", "__commonJSMin", "exports", "module", "isNonNegativeInteger", "isPositiveInteger", "isInteger", "isFunctionArray", "isFunction", "isCollection", "isndarrayLike", "format", "getDType", "resolveEnum", "indexOfTypes", "types2enums", "types", "out", "i", "dispatch", "fcns", "data", "nargs", "nin", "nout", "narrays", "nfcns", "fcn", "dispatcher", "arrays", "dtypes", "argc", "idx", "v", "f", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 02fe150..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,87 +0,0 @@ - -{{alias}}( fcns, types, data, nargs, nin, nout ) - Returns an ndarray function interface which performs multiple dispatch. - - An ndarray function interface has the following signature: - - f( x, y, ... ) - - where - - - x: ndarray. - - y: ndarray. - - ...: additional ndarrays. - - The number of parameters is derived from `nargs`, the number of input - ndarrays is derived from `nin`, and the number of output ndarrays is derived - from `nout`. - - Parameters - ---------- - fcns: Function|ArrayLikeObject - List of ndarray functions. An ndarray function should have the following - signature: - - f( arrays, data ) - - where - - - arrays: array containing input and output ndarrays. - - data: ndarray function data (e.g., a callback). - - For convenience, a single ndarray function may be provided which will be - invoked whenever the ndarray argument data types match a sequence of - types in `types`. Providing a single ndarray function is particularly - convenient for the case where, regardless of array data types, - traversing arrays remains the same, but the ndarray function `data` - differs (e.g., callbacks which differ based on the array data types). - - types: ArrayLikeObject - One-dimensional list of ndarray argument data types. - - data: ArrayLikeObject|null - ndarray function data (e.g., callbacks). If `null`, a returned ndarray - function interface does **not** provide a `data` argument to an invoked - ndarray function. - - nargs: integer - Total number of ndarray function interface arguments. - - nin: integer - Number of input ndarrays. - - nout: integer - Number of output ndarrays. - - Returns - ------- - fcn: Function - ndarray function interface. - - Examples - -------- - // Define ndarray argument data types: - > var t = [ 'float64', 'float64', 'float32', 'float32' ]; - - // Define a list of ndarray function data (callbacks): - > var d = [ {{alias:@stdlib/math/base/special/abs}}, {{alias:@stdlib/math/base/special/absf}} ]; - - // Create an ndarray function interface for applying unary callbacks: - > var f = {{alias}}( {{alias:@stdlib/ndarray/base/unary}}, t, d, 2, 1, 1 ); - - // Create an input ndarray: - > var xbuf = new {{alias:@stdlib/array/float64}}( [ -1.0, -2.0, -3.0, -4.0 ] ); - > var x = {{alias:@stdlib/ndarray/ctor}}( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Create an output ndarray: - > var ybuf = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 0.0, 0.0 ] ); - > var y = {{alias:@stdlib/ndarray/ctor}}( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Compute the element-wise absolute value: - > f( x, y ); - > ybuf - [ 1.0, 2.0, 3.0, 4.0 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 3cba031..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,641 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable max-lines */ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import dispatch = require( './index' ); - - -// FUNCTIONS // - -/** -* Nullary callback. -* -* @return input value -*/ -function nullary(): any { - return 5.0; -} - -/** -* Unary callback. -* -* @param x - input value -* @return input value -*/ -function unary( x: any ): any { - return x; -} - -/** -* Binary callback. -* -* @param x - input value -* @param y - input value -* @return output value -*/ -function binary( x: number, y: number ): number { - return x + y; -} - -/** -* Ternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @return output value -*/ -function ternary( x: number, y: number, z: number ): number { - return x + y + z; -} - -/** -* Quaternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @param w - input value -* @return output value -*/ -function quaternary( x: number, y: number, z: number, w: number ): number { - return x + y + z + w; -} - -/** -* Mock `ind2sub` function. -* -* @param shape - dimensions -* @param idx - linear index -* @param opts - options -* @return subscripts -*/ -function ind2sub( shape: ArrayLike, idx: number, opts?: any ): Array { - let out; - let i; - - out = []; - if ( typeof opts === 'object' && opts !== null && opts.order === 'row-major' ) { no-unsafe-any - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } else { - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } - return out; -} - -/** -* Mock ndarray function. -* -* @param arrays - ndarrays -* @param fcn - callback -*/ -function ndarrayFcn( arrays: Array, fcn: ( x: any ) => any ): void { - let xord; - let yord; - let opts; - let sub; - let sh; - let N; - let x; - let y; - let v; - let i; - - x = arrays[ 0 ]; - y = arrays[ 1 ]; - sh = x.shape; - if ( sh.length === 0 ) { - return; - } - N = 1; - for ( i = 0; i < sh.length; i += 1 ) { - N *= sh[ i ]; - } - xord = x.order; - yord = y.order; - opts = { - 'order': '' - }; - opts.order = xord; - for ( i = 0; i < N; i += 1 ) { - // Convert a linear index to subscripts: - opts.order = xord; - sub = ind2sub( sh, i, opts ); - - // Retrieve an element from `x`: - v = x.get.apply( x, sub ); - - // Convert a linear index to subscripts: - opts.order = yord; - sub = ind2sub( sh, i, opts ); - - // Append the result of applying the callback: - sub[ sub.length ] = fcn( v ) as number; - - // Assign the result to an element in `y`: - y.set.apply( y, sub ); - } -} - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a dispatch function... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, 1 ); // $ExpectType Dispatcher - dispatch( [ ndarrayFcn ], types, data, 2, 1, 1 ); // $ExpectType Dispatcher -} - -// The compiler throws an error if the function is provided a first argument which is not either an ndarray function or an array-like object containing ndarray functions... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( '10', types, data, 2, 1, 1 ); // $ExpectError - dispatch( 10, types, data, 2, 1, 1 ); // $ExpectError - dispatch( true, types, data, 2, 1, 1 ); // $ExpectError - dispatch( false, types, data, 2, 1, 1 ); // $ExpectError - dispatch( null, types, data, 2, 1, 1 ); // $ExpectError - dispatch( undefined, types, data, 2, 1, 1 ); // $ExpectError - dispatch( [ '1' ], types, data, 2, 1, 1 ); // $ExpectError - dispatch( {}, types, data, 2, 1, 1 ); // $ExpectError - dispatch( ( x: number ): number => x, types, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object... -{ - const data = [ unary ]; - - dispatch( ndarrayFcn, 10, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, true, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, false, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, null, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, undefined, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, {}, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object or null... -{ - const types = [ 'float64', 'float64' ]; - - dispatch( ndarrayFcn, types, 10, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, true, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, false, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, undefined, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, {}, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, '10', 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, true, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, false, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, null, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, undefined, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, [ '1' ], 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, {}, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, ( x: number ): number => x, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, '10', 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, true, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, false, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, null, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, undefined, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, [ '1' ], 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, {}, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, ( x: number ): number => x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, '10' ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, true ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, false ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, null ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, undefined ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, [ '1' ] ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, {} ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch(); // $ExpectError - dispatch( ndarrayFcn ); // $ExpectError - dispatch( ndarrayFcn, types ); // $ExpectError - dispatch( ndarrayFcn, types, data ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, 1, 0 ); // $ExpectError -} - -// The function returns a dispatch function... -{ - const x = array(); - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const t1 = [ 'float64' ]; - const d1 = [ nullary ]; - const f1 = dispatch( ndarrayFcn, t1, d1, 1, 1, 0 ); - f1( x ); // $ExpectType void | ndarray - - const t2 = [ 'float64', 'float64' ]; - const d2 = [ unary ]; - const f2 = dispatch( ndarrayFcn, t2, d2, 2, 1, 1 ); - f2( x, y ); // $ExpectType void | ndarray - - const t3 = [ 'float64', 'float64', 'float64' ]; - const d3 = [ binary ]; - const f3 = dispatch( ndarrayFcn, t3, d3, 3, 2, 1 ); - f3( x, y, z ); // $ExpectType void | ndarray - - const t4 = [ 'float64', 'float64', 'float64', 'float64' ]; - const d4 = [ ternary ]; - const f4 = dispatch( ndarrayFcn, t4, d4, 4, 3, 1 ); - f4( x, y, z, w ); // $ExpectType void | ndarray - - const t5 = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const d5 = [ quaternary ]; - const f5 = dispatch( ndarrayFcn, t5, d5, 5, 4, 1 ); - f5( x, y, z, w, u ); // $ExpectType void | ndarray -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (1 ndarray)... -{ - const types = [ 'float64' ]; - const data = [ nullary ]; - - const f = dispatch( ndarrayFcn, types, data, 1, 0, 1 ); - f( '10' ); // $ExpectError - f( 10 ); // $ExpectError - f( true ); // $ExpectError - f( false ); // $ExpectError - f( null ); // $ExpectError - f( undefined ); // $ExpectError - f( [ '1' ] ); // $ExpectError - f( {} ); // $ExpectError - f( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( 10, y ); // $ExpectError - f( '10', y ); // $ExpectError - f( true, y ); // $ExpectError - f( false, y ); // $ExpectError - f( null, y ); // $ExpectError - f( undefined, y ); // $ExpectError - f( [ '1' ], y ); // $ExpectError - f( {}, y ); // $ExpectError - f( ( x: number ): number => x, y ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const x = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( x, 10 ); // $ExpectError - f( x, '10' ); // $ExpectError - f( x, true ); // $ExpectError - f( x, false ); // $ExpectError - f( x, null ); // $ExpectError - f( x, undefined ); // $ExpectError - f( x, [ '1' ] ); // $ExpectError - f( x, {} ); // $ExpectError - f( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( 10, y, z ); // $ExpectError - f( '10', y, z ); // $ExpectError - f( true, y, z ); // $ExpectError - f( false, y, z ); // $ExpectError - f( null, y, z ); // $ExpectError - f( undefined, y, z ); // $ExpectError - f( [ '1' ], y, z ); // $ExpectError - f( {}, y, z ); // $ExpectError - f( ( x: number ): number => x, y, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, 10, z ); // $ExpectError - f( x, '10', z ); // $ExpectError - f( x, true, z ); // $ExpectError - f( x, false, z ); // $ExpectError - f( x, null, z ); // $ExpectError - f( x, undefined, z ); // $ExpectError - f( x, [ '1' ], z ); // $ExpectError - f( x, {}, z ); // $ExpectError - f( x, ( x: number ): number => x, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, y, '10' ); // $ExpectError - f( x, y, true ); // $ExpectError - f( x, y, false ); // $ExpectError - f( x, y, null ); // $ExpectError - f( x, y, undefined ); // $ExpectError - f( x, y, [ '1' ] ); // $ExpectError - f( x, y, {} ); // $ExpectError - f( x, y, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( 10, y, z, w ); // $ExpectError - f( '10', y, z, w ); // $ExpectError - f( true, y, z, w ); // $ExpectError - f( false, y, z, w ); // $ExpectError - f( null, y, z, w ); // $ExpectError - f( undefined, y, z, w ); // $ExpectError - f( [ '1' ], y, z, w ); // $ExpectError - f( {}, y, z, w ); // $ExpectError - f( ( x: number ): number => x, y, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, 10, z, w ); // $ExpectError - f( x, '10', z, w ); // $ExpectError - f( x, true, z, w ); // $ExpectError - f( x, false, z, w ); // $ExpectError - f( x, null, z, w ); // $ExpectError - f( x, undefined, z, w ); // $ExpectError - f( x, [ '1' ], z, w ); // $ExpectError - f( x, {}, z, w ); // $ExpectError - f( x, ( x: number ): number => x, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, 10, w ); // $ExpectError - f( x, y, '10', w ); // $ExpectError - f( x, y, true, w ); // $ExpectError - f( x, y, false, w ); // $ExpectError - f( x, y, null, w ); // $ExpectError - f( x, y, undefined, w ); // $ExpectError - f( x, y, [ '1' ], w ); // $ExpectError - f( x, y, {}, w ); // $ExpectError - f( x, y, ( x: number ): number => x, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, z, 10 ); // $ExpectError - f( x, y, z, '10' ); // $ExpectError - f( x, y, z, true ); // $ExpectError - f( x, y, z, false ); // $ExpectError - f( x, y, z, null ); // $ExpectError - f( x, y, z, undefined ); // $ExpectError - f( x, y, z, [ '1' ] ); // $ExpectError - f( x, y, z, {} ); // $ExpectError - f( x, y, z, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( 10, y, z, w, u ); // $ExpectError - f( '10', y, z, w, u ); // $ExpectError - f( true, y, z, w, u ); // $ExpectError - f( false, y, z, w, u ); // $ExpectError - f( null, y, z, w, u ); // $ExpectError - f( undefined, y, z, w, u ); // $ExpectError - f( [ '1' ], y, z, w, u ); // $ExpectError - f( {}, y, z, w, u ); // $ExpectError - f( ( x: number ): number => x, y, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, 10, z, w, u ); // $ExpectError - f( x, '10', z, w, u ); // $ExpectError - f( x, true, z, w, u ); // $ExpectError - f( x, false, z, w, u ); // $ExpectError - f( x, null, z, w, u ); // $ExpectError - f( x, undefined, z, w, u ); // $ExpectError - f( x, [ '1' ], z, w, u ); // $ExpectError - f( x, {}, z, w, u ); // $ExpectError - f( x, ( x: number ): number => x, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, 10, w, u ); // $ExpectError - f( x, y, '10', w, u ); // $ExpectError - f( x, y, true, w, u ); // $ExpectError - f( x, y, false, w, u ); // $ExpectError - f( x, y, null, w, u ); // $ExpectError - f( x, y, undefined, w, u ); // $ExpectError - f( x, y, [ '1' ], w, u ); // $ExpectError - f( x, y, {}, w, u ); // $ExpectError - f( x, y, ( x: number ): number => x, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, 10, u ); // $ExpectError - f( x, y, z, '10', u ); // $ExpectError - f( x, y, z, true, u ); // $ExpectError - f( x, y, z, false, u ); // $ExpectError - f( x, y, z, null, u ); // $ExpectError - f( x, y, z, undefined, u ); // $ExpectError - f( x, y, z, [ '1' ], u ); // $ExpectError - f( x, y, z, {}, u ); // $ExpectError - f( x, y, z, ( x: number ): number => x, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fifth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, w, 10 ); // $ExpectError - f( x, y, z, w, '10' ); // $ExpectError - f( x, y, z, w, true ); // $ExpectError - f( x, y, z, w, false ); // $ExpectError - f( x, y, z, w, null ); // $ExpectError - f( x, y, z, w, undefined ); // $ExpectError - f( x, y, z, w, [ '1' ] ); // $ExpectError - f( x, y, z, w, {} ); // $ExpectError - f( x, y, z, w, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/add.js b/examples/add.js deleted file mode 100644 index 775b711..0000000 --- a/examples/add.js +++ /dev/null @@ -1,121 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var dispatch = require( './../lib' ); - -function add2( arrays ) { - var opts; - var xo; - var yo; - var zo; - var sx; - var sy; - var sz; - var sh; - var N; - var x; - var y; - var z; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - z = arrays[ 2 ]; - xo = x.order; - yo = y.order; - zo = z.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - opts.order = yo; - sy = ind2sub( sh, i, opts ); - v = x.get.apply( x, sx ) + y.get.apply( y, sy ); - - opts.order = zo; - sz = ind2sub( sh, i, opts ); - sz.push( v ); - z.set.apply( z, sz ); - } -} - -var fcns = [ - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2 -]; - -var types = [ - dtypes.float64, dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.int32, dtypes.int32, - dtypes.uint32, dtypes.uint32, dtypes.uint32, - dtypes.int16, dtypes.int16, dtypes.int16, - dtypes.uint16, dtypes.uint16, dtypes.uint16, - dtypes.int8, dtypes.int8, dtypes.int8, - dtypes.uint8, dtypes.uint8, dtypes.uint8, - dtypes.uint8c, dtypes.uint8c, dtypes.uint8c -]; - -var add = dispatch( fcns, types, null, 3, 2, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var zbuf = new Float64Array( xbuf.length ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var z = ndarray( 'float64', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); - -xbuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -ybuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -zbuf = new Int32Array( xbuf.length ); - -x = ndarray( 'int32', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'int32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -z = ndarray( 'int32', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); diff --git a/examples/sin.js b/examples/sin.js deleted file mode 100644 index 8cd4871..0000000 --- a/examples/sin.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int8Array = require( '@stdlib/array-int8' ); -var sin = require( '@stdlib/math-base-special-sin' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/strided-dtypes' ); -var dispatch = require( './../lib' ); - -function apply( arrays, fcn ) { - var opts; - var xo; - var yo; - var sx; - var sy; - var sh; - var N; - var x; - var y; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - xo = x.order; - yo = y.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - v = fcn( x.get.apply( x, sx ) ); - - opts.order = yo; - sy = ind2sub( sh, i, opts ); - sy.push( v ); - y.set.apply( y, sy ); - } -} - -var fcns = [ - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply -]; - -var types = [ - dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float64, - dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.float64, - dtypes.uint32, dtypes.float64, - dtypes.int16, dtypes.float64, - dtypes.int16, dtypes.float32, - dtypes.uint16, dtypes.float64, - dtypes.uint16, dtypes.float32, - dtypes.int8, dtypes.float64, - dtypes.int8, dtypes.float32, - dtypes.uint8, dtypes.float64, - dtypes.uint8, dtypes.float32, - dtypes.uint8c, dtypes.float64, - dtypes.uint8c, dtypes.float32 -]; - -var data = [ - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin -]; - -var sine = dispatch( fcns, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); - -xbuf = new Int8Array( [ 1, 2, 3, 4, 5 ] ); -ybuf = new Float32Array( xbuf.length ); - -x = ndarray( 'int8', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'float32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); diff --git a/examples/unary.js b/examples/unary.js deleted file mode 100644 index e9c3fb4..0000000 --- a/examples/unary.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -var unary = require( '@stdlib/ndarray-base-unary' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var dispatch = require( './../lib' ); - -var types = [ 'float64', 'float64' ]; - -var data = [ - abs -]; - -var absolute = dispatch( unary, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -absolute( x, y ); -console.log( ybuf ); -// => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 5f280a1..c49a4e4 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..ad38c4f --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@v0.2.1-esm/index.mjs";function m(m,f,l,p,w,v){var a,g,c;if(i(m))c=m;else if(!s(m))throw new TypeError(d("0jr5d",m));if(!n(f))throw new TypeError(d("0jr2y",f));if(!n(l)&&null!==l)throw new TypeError(d("0jr5e",l));if(!e(p))throw new TypeError(d("0jr5f",p));if(!r(w))throw new TypeError(d("0jr5X",w));if(!r(v))throw new TypeError(d("0jr5g",v));if(0===(a=w+v))throw new Error(d("0jr0h"));if(p!==a)throw new Error(d("0jr0i"));if(c){if(g=f.length/a,!t(g))throw new Error(d("0jr0j"))}else if(g=m.length,f.length!==g*a)throw new Error(d("0jr0j"));if(l&&l.length!==g)throw new Error(d("0jr0k"));return f=function(r){var e,t;for(e=[],t=0;t [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0jr5d', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0jr2y', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( '0jr5e', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0jr5f', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0jr5X', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0jr5g', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format('0jr0h') );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format('0jr0i') );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format('0jr0k') );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format('0jr0l') );\n\t\t\t}\n\t\t\tthrow new Error( format('0jr0m') );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( '0jr5h', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( '0jr5i', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format('0jr0n') );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found).\n*\n* ## Notes\n*\n* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types).\n* - The function assumes that `x` is stored in row-major order.\n* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`.\n* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value.\n*\n* @private\n* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension)\n* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension)\n* @param {ArrayLikeObject} x - input two-dimensional reference array\n* @param {integer} strideX1 - `x` stride length along first dimension\n* @param {integer} strideX2 - `x` stride length along second dimension\n* @param {NonNegativeInteger} offsetX - `x` starting index\n* @param {ArrayLikeObject} y - search array\n* @param {integer} strideY - `y` stride length\n* @param {NonNegativeInteger} offsetY - `y` starting index\n* @returns {integer} row index (if found) and `-1` otherwise\n*\n* @example\n* // Define a reference array to search:\n* var types = [\n* 'float64', 'float64', 'float64',\n* 'float32', 'float32', 'float32',\n* 'uint32', 'uint32', 'float64',\n* 'int32', 'int32', 'float64',\n* 'uint16', 'uint16', 'float64',\n* 'int16', 'int16', 'float64',\n* 'uint8', 'uint8', 'float64',\n* 'int8', 'int8', 'float64'\n* ];\n*\n* // Define reference array dimensions:\n* var N = 8; // rows\n* var M = 3; // columns\n*\n* // Define a search array:\n* y1 = [\n* 'float32', 'float32', 'float32',\n* ];\n*\n* // Find the list of types:\n* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 );\n* // returns 1\n*\n// Define a search array:\n* y2 = [\n* 'float32', 'float32', 'float64',\n* ];\n*\n* // Find the list of types:\n* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 );\n* // returns -1\n*/\nfunction indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len\n\tvar ix;\n\tvar iy;\n\tvar i;\n\tvar j;\n\n\t// Search for the first row which matches `y`...\n\tix = offsetX;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tiy = offsetY;\n\t\tfor ( j = 0; j < M; j++ ) {\n\t\t\tif ( x[ ix+(j*strideX2) ] !== y[ iy ] ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tiy += strideY;\n\t\t}\n\t\t// If we successfully iterated over all columns, then that means we've found a match...\n\t\tif ( j === M ) {\n\t\t\treturn i;\n\t\t}\n\t\tix += strideX1;\n\t}\n\treturn -1;\n}\n\n\n// EXPORTS //\n\nexport default indexOfTypes;\n"],"names":["dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","out","i","push","resolveEnum","types2enums","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","getDType","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","j","indexOfTypes","slice"],"mappings":";;0+BA0GA,SAASA,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAO,UAEzB,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAO,UAEzB,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAO,eAIzB,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAO,UAG1B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAO,UAGzB,OADAX,EA5GD,SAAsBA,GACrB,IAAIkB,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAInB,EAAMgB,OAAQG,IAC9BD,EAAIE,KAAMC,EAAarB,EAAOmB,KAE/B,OAAOD,CACR,CAmGSI,CAAatB,GAgBrB,WACC,IAAIuB,EACAC,EACAC,EACAC,EACAC,EACAC,EACAT,EAGJ,GADAM,EAAOI,UAAUb,OACZS,IAASvB,EAAQ,CACrB,GAAKuB,EAAOvB,EACX,MAAM,IAAIa,MAAOJ,EAAO,UAEzB,MAAM,IAAII,MAAOJ,EAAO,SACxB,CAGD,IAFAY,EAAS,GACTC,EAAS,GACHL,EAAI,EAAGA,EAAIjB,EAAOiB,IAAM,CAE7B,IAAMW,EADNH,EAAIE,UAAWV,IAEd,MAAKA,EAAIhB,EACF,IAAIO,UAAWC,EAAQ,QAASgB,IAEhC,IAAIjB,UAAWC,EAAQ,QAASgB,IAGxCJ,EAAOH,KAAMO,GACbH,EAAOJ,KAAMC,EAAaU,EAAUJ,IACpC,CAKD,IAHAD,EC1HF,SAAuBM,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAvB,EACAwB,EAIJ,IADAF,EAAKJ,EACClB,EAAI,EAAGA,EAAIa,EAAGb,IAAM,CAEzB,IADAuB,EAAKF,EACCG,EAAI,EAAGA,EAAIV,GACXC,EAAGO,EAAIE,EAAEP,KAAgBE,EAAGI,GADdC,IAInBD,GAAMH,EAGP,GAAKI,IAAMV,EACV,OAAOd,EAERsB,GAAMN,CACN,CACD,OAAQ,CACT,CDmGQS,CAActC,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGmB,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAId,UAAWC,EAAO,UAI5BiB,EADIrB,GAGAR,EAAM2B,GAGNzB,EACJ2B,EAAGL,EAAQtB,EAAMyB,IAEjBE,EAAGL,GAEJ,GAAc,IAATnB,EACJ,OAAOmB,EAAQlB,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOmB,EAAOsB,MAAO1C,EACrB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 291641d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Create an ndarray function interface which performs multiple dispatch. -* -* @module @stdlib/ndarray-dispatch -* -* @example -* var dispatch = require( '@stdlib/ndarray-dispatch' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/index_of_types.js b/lib/index_of_types.js deleted file mode 100644 index fda2297..0000000 --- a/lib/index_of_types.js +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found). -* -* ## Notes -* -* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types). -* - The function assumes that `x` is stored in row-major order. -* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`. -* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value. -* -* @private -* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension) -* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension) -* @param {ArrayLikeObject} x - input two-dimensional reference array -* @param {integer} strideX1 - `x` stride length along first dimension -* @param {integer} strideX2 - `x` stride length along second dimension -* @param {NonNegativeInteger} offsetX - `x` starting index -* @param {ArrayLikeObject} y - search array -* @param {integer} strideY - `y` stride length -* @param {NonNegativeInteger} offsetY - `y` starting index -* @returns {integer} row index (if found) and `-1` otherwise -* -* @example -* // Define a reference array to search: -* var types = [ -* 'float64', 'float64', 'float64', -* 'float32', 'float32', 'float32', -* 'uint32', 'uint32', 'float64', -* 'int32', 'int32', 'float64', -* 'uint16', 'uint16', 'float64', -* 'int16', 'int16', 'float64', -* 'uint8', 'uint8', 'float64', -* 'int8', 'int8', 'float64' -* ]; -* -* // Define reference array dimensions: -* var N = 8; // rows -* var M = 3; // columns -* -* // Define a search array: -* y1 = [ -* 'float32', 'float32', 'float32', -* ]; -* -* // Find the list of types: -* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 ); -* // returns 1 -* -// Define a search array: -* y2 = [ -* 'float32', 'float32', 'float64', -* ]; -* -* // Find the list of types: -* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 ); -* // returns -1 -*/ -function indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len - var ix; - var iy; - var i; - var j; - - // Search for the first row which matches `y`... - ix = offsetX; - for ( i = 0; i < N; i++ ) { - iy = offsetY; - for ( j = 0; j < M; j++ ) { - if ( x[ ix+(j*strideX2) ] !== y[ iy ] ) { - break; - } - iy += strideY; - } - // If we successfully iterated over all columns, then that means we've found a match... - if ( j === M ) { - return i; - } - ix += strideX1; - } - return -1; -} - - -// EXPORTS // - -module.exports = indexOfTypes; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4648598..0000000 --- a/lib/main.js +++ /dev/null @@ -1,231 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isFunctionArray = require( '@stdlib/assert-is-function-array' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var resolveEnum = require( '@stdlib/ndarray-base-dtype-resolve-enum' ); -var indexOfTypes = require( './index_of_types.js' ); - - -// FUNCTIONS // - -/** -* Returns a list of data type enumeration constants. -* -* @private -* @param {Collection} types - list of types -* @returns {IntegerArray} list of data type enumeration constants -*/ -function types2enums( types ) { - var out; - var i; - - out = []; - for ( i = 0; i < types.length; i++ ) { - out.push( resolveEnum( types[ i ] ) ); - } - return out; -} - - -// MAIN // - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param {(FunctionArray|Function)} fcns - list of ndarray functions -* @param {Collection} types - one-dimensional list of ndarray argument data types -* @param {(Collection|null)} data - ndarray function data (e.g., callbacks) -* @param {PositiveInteger} nargs - total number of ndarray function interface arguments -* @param {NonNegativeInteger} nin - number of input ndarrays -* @param {NonNegativeInteger} nout - number of output ndarrays -* @throws {TypeError} first argument must be either a function or an array of functions -* @throws {TypeError} second argument must be an array-like object -* @throws {TypeError} third argument must be an array-like object or `null` -* @throws {Error} third and first arguments must have the same number of elements -* @throws {TypeError} fourth argument must be a positive integer -* @throws {TypeError} fifth argument must be a nonnegative integer -* @throws {TypeError} sixth argument must be a nonnegative integer -* @throws {Error} fourth argument must equal the specified number of input and output arrays -* @throws {Error} number of types must match the number of functions times the total number of array arguments for each function -* @throws {Error} interface must accept at least one input and/or output ndarray -* @returns {Function} ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function dispatch( fcns, types, data, nargs, nin, nout ) { - var narrays; - var nfcns; - var fcn; - - if ( isFunction( fcns ) ) { - fcn = fcns; - } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( '0jr5d', fcns ) ); - } - if ( !isCollection( types ) ) { - throw new TypeError( format( '0jr2y', types ) ); - } - if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( '0jr5e', data ) ); - } - if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( '0jr5f', nargs ) ); - } - if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( '0jr5X', nin ) ); - } - if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( '0jr5g', nout ) ); - } - narrays = nin + nout; - if ( narrays === 0 ) { - throw new Error( format('0jr0h') ); - } - if ( nargs !== narrays ) { - throw new Error( format('0jr0i') ); - } - if ( fcn ) { - nfcns = types.length / narrays; - if ( !isInteger( nfcns ) ) { - throw new Error( format('0jr0j') ); - } - } else { - nfcns = fcns.length; - if ( types.length !== nfcns*narrays ) { - throw new Error( format('0jr0j') ); - } - } - if ( data && data.length !== nfcns ) { - throw new Error( format('0jr0k') ); - } - types = types2enums( types ); - return dispatcher; - - /** - * ndarray function interface which performs multiple dispatch. - * - * @private - * @param {ndarrayLike} x - ndarray - * @param {...ndarrayLike} args - ndarray arguments - * @throws {Error} insufficient arguments - * @throws {Error} too many arguments - * @throws {TypeError} input array arguments must be ndarray-like objects - * @throws {TypeError} output array arguments must be ndarray-like objects - * @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types - * @returns {(ndarrayLike|Array|void)} destination array(s) - */ - function dispatcher() { - var arrays; - var dtypes; - var argc; - var idx; - var v; - var f; - var i; - - argc = arguments.length; - if ( argc !== nargs ) { - if ( argc < nargs ) { - throw new Error( format('0jr0l') ); - } - throw new Error( format('0jr0m') ); - } - arrays = []; - dtypes = []; - for ( i = 0; i < nargs; i++ ) { - v = arguments[ i ]; - if ( !isndarrayLike( v ) ) { - if ( i < nin ) { - throw new TypeError( format( '0jr5h', v ) ); - } else { - throw new TypeError( format( '0jr5i', v ) ); - } - } - arrays.push( v ); - dtypes.push( resolveEnum( getDType( v ) ) ); - } - // Resolve the ndarray function satisfying the input array types: - idx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len - - // Check whether we were able to successfully resolve an ndarray function: - if ( idx < 0 ) { - throw new TypeError( format('0jr0n') ); - } - // Retrieve the ndarray function: - if ( fcn ) { - f = fcn; - } else { - f = fcns[ idx ]; - } - // Evaluate the ndarray function: - if ( data ) { - f( arrays, data[ idx ] ); - } else { - f( arrays ); - } - if ( nout === 1 ) { - return arrays[ narrays-1 ]; - } - if ( nout === 0 ) { - return; - } - return arrays.slice( nin ); - } -} - - -// EXPORTS // - -module.exports = dispatch; diff --git a/package.json b/package.json index d66c7e4..ffe4f55 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Create an ndarray function interface which performs multiple dispatch.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,57 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-collection": "^0.2.1", - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/assert-is-function-array": "^0.2.1", - "@stdlib/assert-is-integer": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/assert-is-nonnegative-integer": "^0.2.1", - "@stdlib/assert-is-positive-integer": "^0.2.1", - "@stdlib/ndarray-base-dtype-resolve-enum": "^0.2.1", - "@stdlib/ndarray-dtype": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.2.1", - "@stdlib/array-float64": "^0.2.1", - "@stdlib/array-int32": "^0.2.1", - "@stdlib/array-int8": "^0.2.1", - "@stdlib/array-uint8": "^0.2.1", - "@stdlib/math-base-assert-is-nan": "^0.2.1", - "@stdlib/math-base-special-abs": "^0.2.1", - "@stdlib/math-base-special-pow": "^0.2.1", - "@stdlib/math-base-special-sin": "^0.2.1", - "@stdlib/ndarray-base-buffer-dtype": "^0.2.1", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-base-unary": "^0.2.1", - "@stdlib/ndarray-ctor": "^0.2.1", - "@stdlib/ndarray-dtypes": "^0.2.1", - "@stdlib/ndarray-ind2sub": "^0.2.1", - "@stdlib/strided-dtypes": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "ndarray", @@ -100,7 +26,6 @@ "multimethod", "multimethods" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..f1e9034 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/fixtures/binary.js b/test/fixtures/binary.js deleted file mode 100644 index a60dfa2..0000000 --- a/test/fixtures/binary.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Binary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @returns {number} sum -*/ -function binary( x, y ) { - return x + y; -} - - -// EXPORTS // - -module.exports = binary; diff --git a/test/fixtures/fill.js b/test/fixtures/fill.js deleted file mode 100644 index 41b2958..0000000 --- a/test/fixtures/fill.js +++ /dev/null @@ -1,76 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which fills one or more ndarrays. -* -* @private -* @param {*} value - fill value -* @returns {Function} ndarray function -*/ -function fill( value ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - */ - function ndarrayFcn( arrays ) { - var opts; - var sub; - var arr; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - opts = { - 'order': '' - }; - for ( j = 0; j < M; j++ ) { - arr = arrays[ j ]; - opts.order = arrays[ j ].order; - for ( i = 0; i < N; i++ ) { - sub = ind2sub( sh, i, opts ); - sub.push( value ); - arr.set.apply( arr, sub ); - } - } - } -} - - -// EXPORTS // - -module.exports = fill; diff --git a/test/fixtures/foreach.js b/test/fixtures/foreach.js deleted file mode 100644 index a426290..0000000 --- a/test/fixtures/foreach.js +++ /dev/null @@ -1,72 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function forEach( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - fcn.apply( null, args ); - } -} - - -// EXPORTS // - -module.exports = forEach; diff --git a/test/fixtures/map1n.js b/test/fixtures/map1n.js deleted file mode 100644 index 614196b..0000000 --- a/test/fixtures/map1n.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function which maps the return value of a callback to `N` arrays. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function map1N( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var v; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - v = fcn(); - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - sub.push( v ); - arrays[ j ].set.apply( arrays[ j ], sub ); - } - } -} - - -// EXPORTS // - -module.exports = map1N; diff --git a/test/fixtures/nullary.js b/test/fixtures/nullary.js deleted file mode 100644 index 4f22126..0000000 --- a/test/fixtures/nullary.js +++ /dev/null @@ -1,36 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Nullary callback. -* -* @private -* @returns {number} value -*/ -function nullary() { - return 3.0; -} - - -// EXPORTS // - -module.exports = nullary; diff --git a/test/fixtures/quaternary.js b/test/fixtures/quaternary.js deleted file mode 100644 index 548437b..0000000 --- a/test/fixtures/quaternary.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quaternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @returns {number} sum -*/ -function quaternary( x, y, z, w ) { - return x + y + z + w; -} - - -// EXPORTS // - -module.exports = quaternary; diff --git a/test/fixtures/quinary.js b/test/fixtures/quinary.js deleted file mode 100644 index 36068de..0000000 --- a/test/fixtures/quinary.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quinary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @param {number} u - input value -* @returns {number} sum -*/ -function quinary( x, y, z, w, u ) { - return x + y + z + w + u; -} - - -// EXPORTS // - -module.exports = quinary; diff --git a/test/fixtures/sum.js b/test/fixtures/sum.js deleted file mode 100644 index efdbb1b..0000000 --- a/test/fixtures/sum.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which computes the sum across one or more ndarrays. -* -* @private -* @param {Object} ctx - context -* @param {number} ctx.sum - initial sum -* @returns {Function} ndarray function -*/ -function wrapper( ctx ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - * @param {Function} [fcn] - callback - */ - function ndarrayFcn( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var f; - var i; - var j; - - if ( arguments.length > 1 ) { - f = fcn; - } - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - if ( f ) { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - ctx.sum += f.apply( null, args ); - } - } else { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - ctx.sum += arrays[ j ].get.apply( arrays[ j ], sub ); - } - } - } - } -} - - -// EXPORTS // - -module.exports = wrapper; diff --git a/test/fixtures/ternary.js b/test/fixtures/ternary.js deleted file mode 100644 index 0595d5f..0000000 --- a/test/fixtures/ternary.js +++ /dev/null @@ -1,39 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Ternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @returns {number} sum -*/ -function ternary( x, y, z ) { - return x + y + z; -} - - -// EXPORTS // - -module.exports = ternary; diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d6c2c8e..0000000 --- a/test/test.js +++ /dev/null @@ -1,363 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var fill = require( './fixtures/fill.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either a function or an array of functions as a first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( value, types, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object as a second argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided either an array-like object or `null` as a third argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - dispatch( unary, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a positive integer for a fourth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 0, - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a fifth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, value, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a sixth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, 1, value ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function array)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var fcns = [ unary, unary, unary ]; - var data = [ abs, abs, abs ]; - dispatch( fcns, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function argument)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs, abs, abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the length of `data` argument does not match the number of ndarray functions', function test( t ) { - var values; - var i; - - values = [ - [], - [ abs, abs ], - [ abs, abs, abs ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var fcns = [ unary ]; - dispatch( fcns, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the fourth argument is incompatible with the number of input and output ndarrays', function test( t ) { - var values; - var i; - - values = [ - 0, - 1, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of specified input and output ndarrays is zero', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var types = [ 'float64' ]; - dispatch( fill( 3 ), types, null, 1, 0, 0 ); - } -}); - -tape( 'the function returns an ndarray function interface', function test( t ) { - var types; - var data; - var f; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - f = dispatch( unary, types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ unary ], types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( fill( 3 ), types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ fill( 3 ) ], types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.two_arrays.js b/test/test.two_arrays.js deleted file mode 100644 index 16eb61b..0000000 --- a/test/test.two_arrays.js +++ /dev/null @@ -1,814 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var dtype = require( '@stdlib/ndarray-base-buffer-dtype' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var forEach = require( './fixtures/foreach.js' ); -var map1N = require( './fixtures/map1n.js' ); -var fill = require( './fixtures/fill.js' ); -var sum = require( './fixtures/sum.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the first argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var ybuf = new Float64Array( 10 ); - var y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( value, y ); - }; - } -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the second argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var xbuf = new Float64Array( 10 ); - var x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( x, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided insufficient arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var f; - var x; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [], - [ x ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided too many arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var ybuf; - var f; - var x; - var y; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [ x, y, y ], - [ x, y, y, y ], - [ x, y, y, y, y ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if unable to resolve a ndarray function supporting the provided array argument data types', function test( t ) { - var values; - var types; - var data; - var xbuf; - var fcn; - var x; - var i; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ abs, abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 4 ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - values = [ - new Uint8Array( 4 ), - new Int32Array( 4 ), - [ 0, 0, 0, 0 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided an array having data type: ' + dtype( values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var y = ndarray( dtype( value ), value, [ value.length ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - }; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only input arrays)', function test( t ) { - var types; - var xbuf; - var ybuf; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only output arrays)', function test( t ) { - var expected; - var types; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only input arrays)', function test( t ) { - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var ctx; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcns = [ - sum( ctx ), - sum( ctx ) - ]; - fcn = dispatch( fcns, types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only output arrays)', function test( t ) { - var expected; - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcns = [ - fill( 3.0 ), - fill( 4.0 ) - ]; - fcn = dispatch( fcns, types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - - fcn = dispatch( forEach, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - - fcn = dispatch( map1N, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - fcns = [ - forEach, - forEach - ]; - fcn = dispatch( fcns, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - fcns = [ - map1N, - map1N - ]; - fcn = dispatch( fcns, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - fcns = [ - unary, - unary - ]; - fcn = dispatch( fcns, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which returns one or more output arrays, if one or more output arrays is specified, and otherwise returns `undefined`', function test( t ) { - var types; - var data; - var xbuf; - var ybuf; - var out; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - // No output arrays... - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, void 0, 'returns expected value' ); - - // One output array... - data = [ - abs, - abs - ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - fcn = dispatch( fill( 3.0 ), types, null, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - // Two output arrays... - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.end(); -}); From f53eb7cee7b30b7bd95f8e1b501efff0d81518f6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 03:52:12 +0000 Subject: [PATCH 075/109] Transform error messages --- lib/main.js | 34 +++++++++++++++++----------------- package.json | 2 +- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/main.js b/lib/main.js index 5f4bb5d..4648598 100644 --- a/lib/main.js +++ b/lib/main.js @@ -27,7 +27,7 @@ var isFunctionArray = require( '@stdlib/assert-is-function-array' ); var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var getDType = require( '@stdlib/ndarray-dtype' ); var resolveEnum = require( '@stdlib/ndarray-base-dtype-resolve-enum' ); var indexOfTypes = require( './index_of_types.js' ); @@ -112,43 +112,43 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { if ( isFunction( fcns ) ) { fcn = fcns; } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) ); + throw new TypeError( format( '0jr5d', fcns ) ); } if ( !isCollection( types ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) ); + throw new TypeError( format( '0jr2y', types ) ); } if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); + throw new TypeError( format( '0jr5e', data ) ); } if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) ); + throw new TypeError( format( '0jr5f', nargs ) ); } if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) ); + throw new TypeError( format( '0jr5X', nin ) ); } if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) ); + throw new TypeError( format( '0jr5g', nout ) ); } narrays = nin + nout; if ( narrays === 0 ) { - throw new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' ); + throw new Error( format('0jr0h') ); } if ( nargs !== narrays ) { - throw new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' ); + throw new Error( format('0jr0i') ); } if ( fcn ) { nfcns = types.length / narrays; if ( !isInteger( nfcns ) ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format('0jr0j') ); } } else { nfcns = fcns.length; if ( types.length !== nfcns*narrays ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format('0jr0j') ); } } if ( data && data.length !== nfcns ) { - throw new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' ); + throw new Error( format('0jr0k') ); } types = types2enums( types ); return dispatcher; @@ -178,9 +178,9 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { argc = arguments.length; if ( argc !== nargs ) { if ( argc < nargs ) { - throw new Error( 'invalid invocation. Insufficient arguments.' ); + throw new Error( format('0jr0l') ); } - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('0jr0m') ); } arrays = []; dtypes = []; @@ -188,9 +188,9 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { v = arguments[ i ]; if ( !isndarrayLike( v ) ) { if ( i < nin ) { - throw new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) ); + throw new TypeError( format( '0jr5h', v ) ); } else { - throw new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) ); + throw new TypeError( format( '0jr5i', v ) ); } } arrays.push( v ); @@ -201,7 +201,7 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { // Check whether we were able to successfully resolve an ndarray function: if ( idx < 0 ) { - throw new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' ); + throw new TypeError( format('0jr0n') ); } // Retrieve the ndarray function: if ( fcn ) { diff --git a/package.json b/package.json index 996faed..d66c7e4 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/assert-is-positive-integer": "^0.2.1", "@stdlib/ndarray-base-dtype-resolve-enum": "^0.2.1", "@stdlib/ndarray-dtype": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, From c5e11e5dea8bce8048fe7b38eaa28273c0b29a38 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 09:21:32 +0000 Subject: [PATCH 076/109] Remove files --- index.d.ts | 334 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5181 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index c49a4e4..0000000 --- a/index.d.ts +++ /dev/null @@ -1,334 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* ndarray function. -* -* @param arrays - array containing input and output ndarrays -* @param data - ndarray function data (e.g., a callback) -* -* @example -* var numel = require( '@stdlib/ndarray-base-numel' ); -* var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -* -* function ndarrayFcn( arrays, fcn ) { -* var xord; -* var yord; -* var opts; -* var sub; -* var sh; -* var N; -* var x; -* var y; -* var v; -* var i; -* -* x = arrays[ 0 ]; -* y = arrays[ 1 ]; -* sh = x.shape; -* N = numel( sh ); -* if ( N <= 0 ) { -* return; -* } -* xord = x.order; -* yord = y.order; -* opts = {}; -* opts.order = xord; -* for ( i = 0; i < N; i++ ) { -* // Convert a linear index to subscripts: -* opts.order = xord; -* sub = ind2sub( sh, i, opts ); -* -* // Retrieve an element from `x`: -* v = x.get.apply( x, sub ); -* -* // Convert a linear index to subscripts: -* opts.order = yord; -* sub = ind2sub( sh, i, opts ); -* -* // Append the result of applying the callback: -* sub.push( fcn( v ) ); -* -* // Assign the result to an element in `y`: -* y.set.apply( y, sub ); -* } -* } -*/ -type ndarrayFcn = ( arrays: Array, data?: any ) => void; - -/** -* Interface describing an ndarray function dispatcher. -*/ -interface Dispatcher { - /** - * Invokes an ndarray function based on the provided array data type(s). - * - * @param x - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array - * - * @example - * var nullary = require( '@stdlib/ndarray-base-nullary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function value() { - * return 3.14; - * } - * - * var types = [ 'float64' ]; - * var data = [ value ]; - * - * var fcn = dispatch( nullary, types, data, 1, 0, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( 5 ); - * var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x ); - * // xbuf => [ 3.14, 3.14, 3.14, 3.14, 3.14 ] - */ - ( x: ndarray ): ndarray | void; - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var unary = require( '@stdlib/ndarray-base-unary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * var abs = require( '@stdlib/math-base-special-abs' ); - * - * var types = [ 'float64', 'float64' ]; - * var data = [ abs ]; - * - * var fcn = dispatch( unary, types, data, 2, 1, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - * var ybuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y ); - * // ybuf => [ 1.0, 2.0, 3.0 ] - */ - ( x: ndarray, y: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var ternary = require( '@stdlib/ndarray-base-ternary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function add2( x, y ) { - * return x + y; - * } - * - * var types = [ 'float64', 'float64', 'float64' ]; - * var data = [ add2 ]; - * - * var fcn = dispatch( ternary, types, data, 3, 2, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z ); - * // zbuf => [ 2.0, 4.0, 6.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quaternary = require( '@stdlib/ndarray-base-quaternary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function add3( x, y, z ) { - * return x + y + z; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add3 ]; - * - * var fcn = dispatch( quaternary, types, data, 4, 3, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w ); - * // wbuf => [ 3.0, 6.0, 9.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @param args - ndarray arguments - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quinary = require( '@stdlib/ndarray-base-quinary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function add4( x, y, z, w ) { - * return x + y + z + w; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add4 ]; - * - * var fcn = dispatch( quinary, types, data, 5, 4, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ubuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var u = ndarray( 'float64', ubuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w, u ); - * // ubuf => [ 4.0, 8.0, 12.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray, ...args: Array ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures -} - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param fcns - list of ndarray functions -* @param types - one-dimensional list of ndarray argument data types -* @param data - ndarray function data (e.g., callbacks) -* @param nargs - total number of ndarray function interface arguments -* @param nin - number of input ndarrays -* @param nout - number of output ndarrays -* @throws first argument must be either a function or an array of functions -* @throws second argument must be an array-like object -* @throws third argument must be an array-like object or `null` -* @throws third and first arguments must have the same number of elements -* @throws fourth argument must be a positive integer -* @throws fifth argument must be a nonnegative integer -* @throws sixth argument must be a nonnegative integer -* @throws fourth argument must equal the specified number of input and output arrays -* @throws number of types must match the number of functions times the total number of array arguments for each function -* @throws interface must accept at least one input and/or output ndarray -* @returns ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var fcn = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* fcn( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function dispatch( fcns: ndarrayFcn | ArrayLike, types: ArrayLike, data: ArrayLike | null, nargs: number, nin: number, nout: number ): Dispatcher; - - -// EXPORTS // - -export = dispatch; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index ad38c4f..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@v0.2.1-esm/index.mjs";function m(m,f,l,p,w,v){var a,g,c;if(i(m))c=m;else if(!s(m))throw new TypeError(d("0jr5d",m));if(!n(f))throw new TypeError(d("0jr2y",f));if(!n(l)&&null!==l)throw new TypeError(d("0jr5e",l));if(!e(p))throw new TypeError(d("0jr5f",p));if(!r(w))throw new TypeError(d("0jr5X",w));if(!r(v))throw new TypeError(d("0jr5g",v));if(0===(a=w+v))throw new Error(d("0jr0h"));if(p!==a)throw new Error(d("0jr0i"));if(c){if(g=f.length/a,!t(g))throw new Error(d("0jr0j"))}else if(g=m.length,f.length!==g*a)throw new Error(d("0jr0j"));if(l&&l.length!==g)throw new Error(d("0jr0k"));return f=function(r){var e,t;for(e=[],t=0;t [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0jr5d', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0jr2y', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( '0jr5e', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0jr5f', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0jr5X', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0jr5g', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format('0jr0h') );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format('0jr0i') );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format('0jr0k') );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format('0jr0l') );\n\t\t\t}\n\t\t\tthrow new Error( format('0jr0m') );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( '0jr5h', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( '0jr5i', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format('0jr0n') );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found).\n*\n* ## Notes\n*\n* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types).\n* - The function assumes that `x` is stored in row-major order.\n* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`.\n* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value.\n*\n* @private\n* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension)\n* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension)\n* @param {ArrayLikeObject} x - input two-dimensional reference array\n* @param {integer} strideX1 - `x` stride length along first dimension\n* @param {integer} strideX2 - `x` stride length along second dimension\n* @param {NonNegativeInteger} offsetX - `x` starting index\n* @param {ArrayLikeObject} y - search array\n* @param {integer} strideY - `y` stride length\n* @param {NonNegativeInteger} offsetY - `y` starting index\n* @returns {integer} row index (if found) and `-1` otherwise\n*\n* @example\n* // Define a reference array to search:\n* var types = [\n* 'float64', 'float64', 'float64',\n* 'float32', 'float32', 'float32',\n* 'uint32', 'uint32', 'float64',\n* 'int32', 'int32', 'float64',\n* 'uint16', 'uint16', 'float64',\n* 'int16', 'int16', 'float64',\n* 'uint8', 'uint8', 'float64',\n* 'int8', 'int8', 'float64'\n* ];\n*\n* // Define reference array dimensions:\n* var N = 8; // rows\n* var M = 3; // columns\n*\n* // Define a search array:\n* y1 = [\n* 'float32', 'float32', 'float32',\n* ];\n*\n* // Find the list of types:\n* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 );\n* // returns 1\n*\n// Define a search array:\n* y2 = [\n* 'float32', 'float32', 'float64',\n* ];\n*\n* // Find the list of types:\n* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 );\n* // returns -1\n*/\nfunction indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len\n\tvar ix;\n\tvar iy;\n\tvar i;\n\tvar j;\n\n\t// Search for the first row which matches `y`...\n\tix = offsetX;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tiy = offsetY;\n\t\tfor ( j = 0; j < M; j++ ) {\n\t\t\tif ( x[ ix+(j*strideX2) ] !== y[ iy ] ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tiy += strideY;\n\t\t}\n\t\t// If we successfully iterated over all columns, then that means we've found a match...\n\t\tif ( j === M ) {\n\t\t\treturn i;\n\t\t}\n\t\tix += strideX1;\n\t}\n\treturn -1;\n}\n\n\n// EXPORTS //\n\nexport default indexOfTypes;\n"],"names":["dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","out","i","push","resolveEnum","types2enums","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","getDType","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","j","indexOfTypes","slice"],"mappings":";;0+BA0GA,SAASA,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAO,UAEzB,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAO,UAEzB,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAO,eAIzB,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAO,UAG1B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAO,UAGzB,OADAX,EA5GD,SAAsBA,GACrB,IAAIkB,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAInB,EAAMgB,OAAQG,IAC9BD,EAAIE,KAAMC,EAAarB,EAAOmB,KAE/B,OAAOD,CACR,CAmGSI,CAAatB,GAgBrB,WACC,IAAIuB,EACAC,EACAC,EACAC,EACAC,EACAC,EACAT,EAGJ,GADAM,EAAOI,UAAUb,OACZS,IAASvB,EAAQ,CACrB,GAAKuB,EAAOvB,EACX,MAAM,IAAIa,MAAOJ,EAAO,UAEzB,MAAM,IAAII,MAAOJ,EAAO,SACxB,CAGD,IAFAY,EAAS,GACTC,EAAS,GACHL,EAAI,EAAGA,EAAIjB,EAAOiB,IAAM,CAE7B,IAAMW,EADNH,EAAIE,UAAWV,IAEd,MAAKA,EAAIhB,EACF,IAAIO,UAAWC,EAAQ,QAASgB,IAEhC,IAAIjB,UAAWC,EAAQ,QAASgB,IAGxCJ,EAAOH,KAAMO,GACbH,EAAOJ,KAAMC,EAAaU,EAAUJ,IACpC,CAKD,IAHAD,EC1HF,SAAuBM,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAvB,EACAwB,EAIJ,IADAF,EAAKJ,EACClB,EAAI,EAAGA,EAAIa,EAAGb,IAAM,CAEzB,IADAuB,EAAKF,EACCG,EAAI,EAAGA,EAAIV,GACXC,EAAGO,EAAIE,EAAEP,KAAgBE,EAAGI,GADdC,IAInBD,GAAMH,EAGP,GAAKI,IAAMV,EACV,OAAOd,EAERsB,GAAMN,CACN,CACD,OAAQ,CACT,CDmGQS,CAActC,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGmB,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAId,UAAWC,EAAO,UAI5BiB,EADIrB,GAGAR,EAAM2B,GAGNzB,EACJ2B,EAAGL,EAAQtB,EAAMyB,IAEjBE,EAAGL,GAEJ,GAAc,IAATnB,EACJ,OAAOmB,EAAQlB,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOmB,EAAOsB,MAAO1C,EACrB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index f1e9034..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From f4d2ee1ea309be1c658f240ad4958ef7ba2ca696 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 09:21:58 +0000 Subject: [PATCH 077/109] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 134 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 61 +- SECURITY.md | 5 - benchmark/benchmark.dispatch_size.js | 156 - benchmark/benchmark.js | 81 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 87 - docs/types/test.ts | 641 --- examples/add.js | 121 - examples/sin.js | 142 - examples/unary.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/index_of_types.js | 106 - lib/main.js | 231 - package.json | 79 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/binary.js | 38 - test/fixtures/fill.js | 76 - test/fixtures/foreach.js | 72 - test/fixtures/map1n.js | 74 - test/fixtures/nullary.js | 36 - test/fixtures/quaternary.js | 40 - test/fixtures/quinary.js | 41 - test/fixtures/sum.js | 98 - test/fixtures/ternary.js | 39 - test/test.js | 363 -- test/test.two_arrays.js | 814 ---- 56 files changed, 4876 insertions(+), 6752 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.dispatch_size.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/add.js delete mode 100644 examples/sin.js delete mode 100644 examples/unary.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/index_of_types.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/fixtures/binary.js delete mode 100644 test/fixtures/fill.js delete mode 100644 test/fixtures/foreach.js delete mode 100644 test/fixtures/map1n.js delete mode 100644 test/fixtures/nullary.js delete mode 100644 test/fixtures/quaternary.js delete mode 100644 test/fixtures/quinary.js delete mode 100644 test/fixtures/sum.js delete mode 100644 test/fixtures/ternary.js delete mode 100644 test/test.js delete mode 100644 test/test.two_arrays.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ac0b7cd..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 5e92c3e..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2b4fac7..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '43 7 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index ec90164..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -304,7 +295,7 @@ console.log( ybuf ); ## 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. +This package is part of [stdlib][stdlib], a standard library 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]. @@ -367,11 +358,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-dispatch/main/LICENSE -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.dispatch_size.js b/benchmark/benchmark.dispatch_size.js deleted file mode 100644 index 15805ba..0000000 --- a/benchmark/benchmark.dispatch_size.js +++ /dev/null @@ -1,156 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib/main.js' ); - - -// FUNCTIONS // - -/** -* Evaluates the identity function. -* -* @private -* @param {*} v - value -* @returns {*} input value -*/ -function identity( v ) { - return v; -} - -/** -* Dummy function which throws an error. -* -* @private -* @throws {Error} unexpected error -*/ -function throwError() { - throw new Error( 'unexpected error' ); -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} size - dispatch size -* @returns {Function} benchmark function -*/ -function createBenchmark( size ) { - var types; - var data; - var fcn; - var x; - var y; - var t; - var i; - - types = []; - - // Create dummy types... - for ( i = 0; i < (size-1)*2; i += 2 ) { - t = 'foo' + i; - types.push( t ); - types.push( t ); - } - // Append test types: - types.push( 'float64' ); - types.push( 'float64' ); - - // Define a list of callbacks: - data = []; - for ( i = 0; i < size-1; i++ ) { - data.push( throwError ); - } - // Append a test callback: - data.push( identity ); - - // Create the dispatcher: - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - // Create sample arrays: - x = new Float64Array( 1 ); - y = new Float64Array( x.length ); - - x = ndarray( 'float64', x, [ 1 ], [ 1 ], 0, 'row-major' ); - y = ndarray( 'float64', y, [ 1 ], [ 1 ], 0, 'row-major' ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var z; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x.data[ 0 ] = i; - z = fcn( x, y ); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var size; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - size = pow( 2, i ); - f = createBenchmark( size ); - bench( pkg+':size='+size, f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 3c6f450..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::fcns_array', function benchmark( b ) { - var types; - var fcns; - var data; - var out; - var i; - - fcns = [ unary ]; - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( fcns, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::fcn_arg', function benchmark( b ) { - var types; - var data; - var out; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( unary, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0aae4af..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch" -%% click B href "https://github.com/stdlib-js/ndarray-dispatch/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-dispatch/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-dispatch/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-dispatch/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-dispatch/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch -[production-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 1295a44..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import dispatch from '../docs/types/index'; -export = dispatch; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7fb29cb..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var y=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var b=y(function(D,w){ -function k(i,r,e,u,f,m,n,o,l){var h,t,s,a;for(h=m,s=0;s [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( 'invalid invocation. Insufficient arguments.' );\n\t\t\t}\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = dispatch;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an ndarray function interface which performs multiple dispatch.\n*\n* @module @stdlib/ndarray-dispatch\n*\n* @example\n* var dispatch = require( '@stdlib/ndarray-dispatch' );\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var unary = require( '@stdlib/ndarray-base-unary' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var Float64Array = require( '@stdlib/array-float64' );\n*\n* var types = [\n* 'float64', 'float64'\n* ];\n*\n* var data = [\n* abs\n* ];\n*\n* var absolute = dispatch( unary, types, data, 2, 1, 1 );\n*\n* // ...\n*\n* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] );\n* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] );\n*\n* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' );\n* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' );\n*\n* absolute( x, y );\n* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA6EA,SAASC,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,EAAU,CAClF,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,CAAU,IAAME,EAAGI,CAAG,EADjBE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,CACP,CACA,MAAO,EACR,CAKAL,EAAO,QAAUC,ICzGjB,IAAAc,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAoB,QAAS,oCAAqC,EAClEC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAkB,QAAS,kCAAmC,EAC9DC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAc,QAAS,yCAA0C,EACjEC,EAAe,IAYnB,SAASC,EAAaC,EAAQ,CAC7B,IAAIC,EACAC,EAGJ,IADAD,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIF,EAAM,OAAQE,IAC9BD,EAAI,KAAMJ,EAAaG,EAAOE,CAAE,CAAE,CAAE,EAErC,OAAOD,CACR,CAqDA,SAASE,EAAUC,EAAMJ,EAAOK,EAAMC,EAAOC,EAAKC,EAAO,CACxD,IAAIC,EACAC,EACAC,EAEJ,GAAKnB,EAAYY,CAAK,EACrBO,EAAMP,UACK,CAACb,EAAiBa,CAAK,EAClC,MAAM,IAAI,UAAWT,EAAQ,oGAAqGS,CAAK,CAAE,EAE1I,GAAK,CAACX,EAAcO,CAAM,EACzB,MAAM,IAAI,UAAWL,EAAQ,+EAAgFK,CAAM,CAAE,EAEtH,GAAK,CAACP,EAAcY,CAAK,GAAKA,IAAS,KACtC,MAAM,IAAI,UAAWV,EAAQ,sFAAuFU,CAAK,CAAE,EAE5H,GAAK,CAAChB,EAAmBiB,CAAM,EAC9B,MAAM,IAAI,UAAWX,EAAQ,6EAA8EW,CAAM,CAAE,EAEpH,GAAK,CAAClB,EAAsBmB,CAAI,EAC/B,MAAM,IAAI,UAAWZ,EAAQ,+EAAgFY,CAAI,CAAE,EAEpH,GAAK,CAACnB,EAAsBoB,CAAK,EAChC,MAAM,IAAI,UAAWb,EAAQ,+EAAgFa,CAAK,CAAE,EAGrH,GADAC,EAAUF,EAAMC,EACXC,IAAY,EAChB,MAAM,IAAI,MAAO,4IAA6I,EAE/J,GAAKH,IAAUG,EACd,MAAM,IAAI,MAAO,4FAA6F,EAE/G,GAAKE,GAEJ,GADAD,EAAQV,EAAM,OAASS,EAClB,CAACnB,EAAWoB,CAAM,EACtB,MAAM,IAAI,MAAO,8IAA+I,UAGjKA,EAAQN,EAAK,OACRJ,EAAM,SAAWU,EAAMD,EAC3B,MAAM,IAAI,MAAO,8IAA+I,EAGlK,GAAKJ,GAAQA,EAAK,SAAWK,EAC5B,MAAM,IAAI,MAAO,mGAAoG,EAEtH,OAAAV,EAAQD,EAAaC,CAAM,EACpBY,EAeP,SAASA,GAAa,CACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EAGJ,GADAa,EAAO,UAAU,OACZA,IAAST,EACb,MAAKS,EAAOT,EACL,IAAI,MAAO,6CAA8C,EAE1D,IAAI,MAAO,yCAA0C,EAI5D,IAFAO,EAAS,CAAC,EACVC,EAAS,CAAC,EACJZ,EAAI,EAAGA,EAAII,EAAOJ,IAAM,CAE7B,GADAe,EAAI,UAAWf,CAAE,EACZ,CAACR,EAAeuB,CAAE,EACtB,MAAKf,EAAIK,EACF,IAAI,UAAWZ,EAAQ,6EAA8EsB,CAAE,CAAE,EAEzG,IAAI,UAAWtB,EAAQ,8EAA+EsB,CAAE,CAAE,EAGlHJ,EAAO,KAAMI,CAAE,EACfH,EAAO,KAAMjB,EAAaD,EAAUqB,CAAE,CAAE,CAAE,CAC3C,CAKA,GAHAD,EAAMlB,EAAcY,EAAOD,EAAST,EAAOS,EAAS,EAAG,EAAGK,EAAQ,EAAG,CAAE,EAGlEE,EAAM,EACV,MAAM,IAAI,UAAW,6GAA8G,EAcpI,GAXKL,EACJO,EAAIP,EAEJO,EAAId,EAAMY,CAAI,EAGVX,EACJa,EAAGL,EAAQR,EAAMW,CAAI,CAAE,EAEvBE,EAAGL,CAAO,EAENL,IAAS,EACb,OAAOK,EAAQJ,EAAQ,CAAE,EAE1B,GAAKD,IAAS,EAGd,OAAOK,EAAO,MAAON,CAAI,CAC1B,CACD,CAKApB,EAAO,QAAUgB,IC9KjB,IAAIgB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_index_of_types", "__commonJSMin", "exports", "module", "indexOfTypes", "N", "M", "x", "strideX1", "strideX2", "offsetX", "y", "strideY", "offsetY", "ix", "iy", "i", "j", "require_main", "__commonJSMin", "exports", "module", "isNonNegativeInteger", "isPositiveInteger", "isInteger", "isFunctionArray", "isFunction", "isCollection", "isndarrayLike", "format", "getDType", "resolveEnum", "indexOfTypes", "types2enums", "types", "out", "i", "dispatch", "fcns", "data", "nargs", "nin", "nout", "narrays", "nfcns", "fcn", "dispatcher", "arrays", "dtypes", "argc", "idx", "v", "f", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 02fe150..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,87 +0,0 @@ - -{{alias}}( fcns, types, data, nargs, nin, nout ) - Returns an ndarray function interface which performs multiple dispatch. - - An ndarray function interface has the following signature: - - f( x, y, ... ) - - where - - - x: ndarray. - - y: ndarray. - - ...: additional ndarrays. - - The number of parameters is derived from `nargs`, the number of input - ndarrays is derived from `nin`, and the number of output ndarrays is derived - from `nout`. - - Parameters - ---------- - fcns: Function|ArrayLikeObject - List of ndarray functions. An ndarray function should have the following - signature: - - f( arrays, data ) - - where - - - arrays: array containing input and output ndarrays. - - data: ndarray function data (e.g., a callback). - - For convenience, a single ndarray function may be provided which will be - invoked whenever the ndarray argument data types match a sequence of - types in `types`. Providing a single ndarray function is particularly - convenient for the case where, regardless of array data types, - traversing arrays remains the same, but the ndarray function `data` - differs (e.g., callbacks which differ based on the array data types). - - types: ArrayLikeObject - One-dimensional list of ndarray argument data types. - - data: ArrayLikeObject|null - ndarray function data (e.g., callbacks). If `null`, a returned ndarray - function interface does **not** provide a `data` argument to an invoked - ndarray function. - - nargs: integer - Total number of ndarray function interface arguments. - - nin: integer - Number of input ndarrays. - - nout: integer - Number of output ndarrays. - - Returns - ------- - fcn: Function - ndarray function interface. - - Examples - -------- - // Define ndarray argument data types: - > var t = [ 'float64', 'float64', 'float32', 'float32' ]; - - // Define a list of ndarray function data (callbacks): - > var d = [ {{alias:@stdlib/math/base/special/abs}}, {{alias:@stdlib/math/base/special/absf}} ]; - - // Create an ndarray function interface for applying unary callbacks: - > var f = {{alias}}( {{alias:@stdlib/ndarray/base/unary}}, t, d, 2, 1, 1 ); - - // Create an input ndarray: - > var xbuf = new {{alias:@stdlib/array/float64}}( [ -1.0, -2.0, -3.0, -4.0 ] ); - > var x = {{alias:@stdlib/ndarray/ctor}}( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Create an output ndarray: - > var ybuf = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 0.0, 0.0 ] ); - > var y = {{alias:@stdlib/ndarray/ctor}}( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Compute the element-wise absolute value: - > f( x, y ); - > ybuf - [ 1.0, 2.0, 3.0, 4.0 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 3cba031..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,641 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable max-lines */ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import dispatch = require( './index' ); - - -// FUNCTIONS // - -/** -* Nullary callback. -* -* @return input value -*/ -function nullary(): any { - return 5.0; -} - -/** -* Unary callback. -* -* @param x - input value -* @return input value -*/ -function unary( x: any ): any { - return x; -} - -/** -* Binary callback. -* -* @param x - input value -* @param y - input value -* @return output value -*/ -function binary( x: number, y: number ): number { - return x + y; -} - -/** -* Ternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @return output value -*/ -function ternary( x: number, y: number, z: number ): number { - return x + y + z; -} - -/** -* Quaternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @param w - input value -* @return output value -*/ -function quaternary( x: number, y: number, z: number, w: number ): number { - return x + y + z + w; -} - -/** -* Mock `ind2sub` function. -* -* @param shape - dimensions -* @param idx - linear index -* @param opts - options -* @return subscripts -*/ -function ind2sub( shape: ArrayLike, idx: number, opts?: any ): Array { - let out; - let i; - - out = []; - if ( typeof opts === 'object' && opts !== null && opts.order === 'row-major' ) { no-unsafe-any - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } else { - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } - return out; -} - -/** -* Mock ndarray function. -* -* @param arrays - ndarrays -* @param fcn - callback -*/ -function ndarrayFcn( arrays: Array, fcn: ( x: any ) => any ): void { - let xord; - let yord; - let opts; - let sub; - let sh; - let N; - let x; - let y; - let v; - let i; - - x = arrays[ 0 ]; - y = arrays[ 1 ]; - sh = x.shape; - if ( sh.length === 0 ) { - return; - } - N = 1; - for ( i = 0; i < sh.length; i += 1 ) { - N *= sh[ i ]; - } - xord = x.order; - yord = y.order; - opts = { - 'order': '' - }; - opts.order = xord; - for ( i = 0; i < N; i += 1 ) { - // Convert a linear index to subscripts: - opts.order = xord; - sub = ind2sub( sh, i, opts ); - - // Retrieve an element from `x`: - v = x.get.apply( x, sub ); - - // Convert a linear index to subscripts: - opts.order = yord; - sub = ind2sub( sh, i, opts ); - - // Append the result of applying the callback: - sub[ sub.length ] = fcn( v ) as number; - - // Assign the result to an element in `y`: - y.set.apply( y, sub ); - } -} - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a dispatch function... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, 1 ); // $ExpectType Dispatcher - dispatch( [ ndarrayFcn ], types, data, 2, 1, 1 ); // $ExpectType Dispatcher -} - -// The compiler throws an error if the function is provided a first argument which is not either an ndarray function or an array-like object containing ndarray functions... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( '10', types, data, 2, 1, 1 ); // $ExpectError - dispatch( 10, types, data, 2, 1, 1 ); // $ExpectError - dispatch( true, types, data, 2, 1, 1 ); // $ExpectError - dispatch( false, types, data, 2, 1, 1 ); // $ExpectError - dispatch( null, types, data, 2, 1, 1 ); // $ExpectError - dispatch( undefined, types, data, 2, 1, 1 ); // $ExpectError - dispatch( [ '1' ], types, data, 2, 1, 1 ); // $ExpectError - dispatch( {}, types, data, 2, 1, 1 ); // $ExpectError - dispatch( ( x: number ): number => x, types, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object... -{ - const data = [ unary ]; - - dispatch( ndarrayFcn, 10, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, true, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, false, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, null, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, undefined, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, {}, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object or null... -{ - const types = [ 'float64', 'float64' ]; - - dispatch( ndarrayFcn, types, 10, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, true, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, false, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, undefined, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, {}, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, '10', 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, true, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, false, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, null, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, undefined, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, [ '1' ], 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, {}, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, ( x: number ): number => x, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, '10', 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, true, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, false, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, null, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, undefined, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, [ '1' ], 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, {}, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, ( x: number ): number => x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, '10' ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, true ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, false ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, null ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, undefined ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, [ '1' ] ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, {} ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch(); // $ExpectError - dispatch( ndarrayFcn ); // $ExpectError - dispatch( ndarrayFcn, types ); // $ExpectError - dispatch( ndarrayFcn, types, data ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, 1, 0 ); // $ExpectError -} - -// The function returns a dispatch function... -{ - const x = array(); - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const t1 = [ 'float64' ]; - const d1 = [ nullary ]; - const f1 = dispatch( ndarrayFcn, t1, d1, 1, 1, 0 ); - f1( x ); // $ExpectType void | ndarray - - const t2 = [ 'float64', 'float64' ]; - const d2 = [ unary ]; - const f2 = dispatch( ndarrayFcn, t2, d2, 2, 1, 1 ); - f2( x, y ); // $ExpectType void | ndarray - - const t3 = [ 'float64', 'float64', 'float64' ]; - const d3 = [ binary ]; - const f3 = dispatch( ndarrayFcn, t3, d3, 3, 2, 1 ); - f3( x, y, z ); // $ExpectType void | ndarray - - const t4 = [ 'float64', 'float64', 'float64', 'float64' ]; - const d4 = [ ternary ]; - const f4 = dispatch( ndarrayFcn, t4, d4, 4, 3, 1 ); - f4( x, y, z, w ); // $ExpectType void | ndarray - - const t5 = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const d5 = [ quaternary ]; - const f5 = dispatch( ndarrayFcn, t5, d5, 5, 4, 1 ); - f5( x, y, z, w, u ); // $ExpectType void | ndarray -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (1 ndarray)... -{ - const types = [ 'float64' ]; - const data = [ nullary ]; - - const f = dispatch( ndarrayFcn, types, data, 1, 0, 1 ); - f( '10' ); // $ExpectError - f( 10 ); // $ExpectError - f( true ); // $ExpectError - f( false ); // $ExpectError - f( null ); // $ExpectError - f( undefined ); // $ExpectError - f( [ '1' ] ); // $ExpectError - f( {} ); // $ExpectError - f( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( 10, y ); // $ExpectError - f( '10', y ); // $ExpectError - f( true, y ); // $ExpectError - f( false, y ); // $ExpectError - f( null, y ); // $ExpectError - f( undefined, y ); // $ExpectError - f( [ '1' ], y ); // $ExpectError - f( {}, y ); // $ExpectError - f( ( x: number ): number => x, y ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const x = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( x, 10 ); // $ExpectError - f( x, '10' ); // $ExpectError - f( x, true ); // $ExpectError - f( x, false ); // $ExpectError - f( x, null ); // $ExpectError - f( x, undefined ); // $ExpectError - f( x, [ '1' ] ); // $ExpectError - f( x, {} ); // $ExpectError - f( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( 10, y, z ); // $ExpectError - f( '10', y, z ); // $ExpectError - f( true, y, z ); // $ExpectError - f( false, y, z ); // $ExpectError - f( null, y, z ); // $ExpectError - f( undefined, y, z ); // $ExpectError - f( [ '1' ], y, z ); // $ExpectError - f( {}, y, z ); // $ExpectError - f( ( x: number ): number => x, y, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, 10, z ); // $ExpectError - f( x, '10', z ); // $ExpectError - f( x, true, z ); // $ExpectError - f( x, false, z ); // $ExpectError - f( x, null, z ); // $ExpectError - f( x, undefined, z ); // $ExpectError - f( x, [ '1' ], z ); // $ExpectError - f( x, {}, z ); // $ExpectError - f( x, ( x: number ): number => x, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, y, '10' ); // $ExpectError - f( x, y, true ); // $ExpectError - f( x, y, false ); // $ExpectError - f( x, y, null ); // $ExpectError - f( x, y, undefined ); // $ExpectError - f( x, y, [ '1' ] ); // $ExpectError - f( x, y, {} ); // $ExpectError - f( x, y, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( 10, y, z, w ); // $ExpectError - f( '10', y, z, w ); // $ExpectError - f( true, y, z, w ); // $ExpectError - f( false, y, z, w ); // $ExpectError - f( null, y, z, w ); // $ExpectError - f( undefined, y, z, w ); // $ExpectError - f( [ '1' ], y, z, w ); // $ExpectError - f( {}, y, z, w ); // $ExpectError - f( ( x: number ): number => x, y, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, 10, z, w ); // $ExpectError - f( x, '10', z, w ); // $ExpectError - f( x, true, z, w ); // $ExpectError - f( x, false, z, w ); // $ExpectError - f( x, null, z, w ); // $ExpectError - f( x, undefined, z, w ); // $ExpectError - f( x, [ '1' ], z, w ); // $ExpectError - f( x, {}, z, w ); // $ExpectError - f( x, ( x: number ): number => x, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, 10, w ); // $ExpectError - f( x, y, '10', w ); // $ExpectError - f( x, y, true, w ); // $ExpectError - f( x, y, false, w ); // $ExpectError - f( x, y, null, w ); // $ExpectError - f( x, y, undefined, w ); // $ExpectError - f( x, y, [ '1' ], w ); // $ExpectError - f( x, y, {}, w ); // $ExpectError - f( x, y, ( x: number ): number => x, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, z, 10 ); // $ExpectError - f( x, y, z, '10' ); // $ExpectError - f( x, y, z, true ); // $ExpectError - f( x, y, z, false ); // $ExpectError - f( x, y, z, null ); // $ExpectError - f( x, y, z, undefined ); // $ExpectError - f( x, y, z, [ '1' ] ); // $ExpectError - f( x, y, z, {} ); // $ExpectError - f( x, y, z, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( 10, y, z, w, u ); // $ExpectError - f( '10', y, z, w, u ); // $ExpectError - f( true, y, z, w, u ); // $ExpectError - f( false, y, z, w, u ); // $ExpectError - f( null, y, z, w, u ); // $ExpectError - f( undefined, y, z, w, u ); // $ExpectError - f( [ '1' ], y, z, w, u ); // $ExpectError - f( {}, y, z, w, u ); // $ExpectError - f( ( x: number ): number => x, y, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, 10, z, w, u ); // $ExpectError - f( x, '10', z, w, u ); // $ExpectError - f( x, true, z, w, u ); // $ExpectError - f( x, false, z, w, u ); // $ExpectError - f( x, null, z, w, u ); // $ExpectError - f( x, undefined, z, w, u ); // $ExpectError - f( x, [ '1' ], z, w, u ); // $ExpectError - f( x, {}, z, w, u ); // $ExpectError - f( x, ( x: number ): number => x, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, 10, w, u ); // $ExpectError - f( x, y, '10', w, u ); // $ExpectError - f( x, y, true, w, u ); // $ExpectError - f( x, y, false, w, u ); // $ExpectError - f( x, y, null, w, u ); // $ExpectError - f( x, y, undefined, w, u ); // $ExpectError - f( x, y, [ '1' ], w, u ); // $ExpectError - f( x, y, {}, w, u ); // $ExpectError - f( x, y, ( x: number ): number => x, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, 10, u ); // $ExpectError - f( x, y, z, '10', u ); // $ExpectError - f( x, y, z, true, u ); // $ExpectError - f( x, y, z, false, u ); // $ExpectError - f( x, y, z, null, u ); // $ExpectError - f( x, y, z, undefined, u ); // $ExpectError - f( x, y, z, [ '1' ], u ); // $ExpectError - f( x, y, z, {}, u ); // $ExpectError - f( x, y, z, ( x: number ): number => x, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fifth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, w, 10 ); // $ExpectError - f( x, y, z, w, '10' ); // $ExpectError - f( x, y, z, w, true ); // $ExpectError - f( x, y, z, w, false ); // $ExpectError - f( x, y, z, w, null ); // $ExpectError - f( x, y, z, w, undefined ); // $ExpectError - f( x, y, z, w, [ '1' ] ); // $ExpectError - f( x, y, z, w, {} ); // $ExpectError - f( x, y, z, w, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/add.js b/examples/add.js deleted file mode 100644 index 775b711..0000000 --- a/examples/add.js +++ /dev/null @@ -1,121 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var dispatch = require( './../lib' ); - -function add2( arrays ) { - var opts; - var xo; - var yo; - var zo; - var sx; - var sy; - var sz; - var sh; - var N; - var x; - var y; - var z; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - z = arrays[ 2 ]; - xo = x.order; - yo = y.order; - zo = z.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - opts.order = yo; - sy = ind2sub( sh, i, opts ); - v = x.get.apply( x, sx ) + y.get.apply( y, sy ); - - opts.order = zo; - sz = ind2sub( sh, i, opts ); - sz.push( v ); - z.set.apply( z, sz ); - } -} - -var fcns = [ - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2 -]; - -var types = [ - dtypes.float64, dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.int32, dtypes.int32, - dtypes.uint32, dtypes.uint32, dtypes.uint32, - dtypes.int16, dtypes.int16, dtypes.int16, - dtypes.uint16, dtypes.uint16, dtypes.uint16, - dtypes.int8, dtypes.int8, dtypes.int8, - dtypes.uint8, dtypes.uint8, dtypes.uint8, - dtypes.uint8c, dtypes.uint8c, dtypes.uint8c -]; - -var add = dispatch( fcns, types, null, 3, 2, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var zbuf = new Float64Array( xbuf.length ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var z = ndarray( 'float64', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); - -xbuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -ybuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -zbuf = new Int32Array( xbuf.length ); - -x = ndarray( 'int32', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'int32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -z = ndarray( 'int32', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); diff --git a/examples/sin.js b/examples/sin.js deleted file mode 100644 index 8cd4871..0000000 --- a/examples/sin.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int8Array = require( '@stdlib/array-int8' ); -var sin = require( '@stdlib/math-base-special-sin' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/strided-dtypes' ); -var dispatch = require( './../lib' ); - -function apply( arrays, fcn ) { - var opts; - var xo; - var yo; - var sx; - var sy; - var sh; - var N; - var x; - var y; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - xo = x.order; - yo = y.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - v = fcn( x.get.apply( x, sx ) ); - - opts.order = yo; - sy = ind2sub( sh, i, opts ); - sy.push( v ); - y.set.apply( y, sy ); - } -} - -var fcns = [ - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply -]; - -var types = [ - dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float64, - dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.float64, - dtypes.uint32, dtypes.float64, - dtypes.int16, dtypes.float64, - dtypes.int16, dtypes.float32, - dtypes.uint16, dtypes.float64, - dtypes.uint16, dtypes.float32, - dtypes.int8, dtypes.float64, - dtypes.int8, dtypes.float32, - dtypes.uint8, dtypes.float64, - dtypes.uint8, dtypes.float32, - dtypes.uint8c, dtypes.float64, - dtypes.uint8c, dtypes.float32 -]; - -var data = [ - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin -]; - -var sine = dispatch( fcns, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); - -xbuf = new Int8Array( [ 1, 2, 3, 4, 5 ] ); -ybuf = new Float32Array( xbuf.length ); - -x = ndarray( 'int8', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'float32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); diff --git a/examples/unary.js b/examples/unary.js deleted file mode 100644 index e9c3fb4..0000000 --- a/examples/unary.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -var unary = require( '@stdlib/ndarray-base-unary' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var dispatch = require( './../lib' ); - -var types = [ 'float64', 'float64' ]; - -var data = [ - abs -]; - -var absolute = dispatch( unary, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -absolute( x, y ); -console.log( ybuf ); -// => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 5f280a1..c49a4e4 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..ad38c4f --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@v0.2.1-esm/index.mjs";function m(m,f,l,p,w,v){var a,g,c;if(i(m))c=m;else if(!s(m))throw new TypeError(d("0jr5d",m));if(!n(f))throw new TypeError(d("0jr2y",f));if(!n(l)&&null!==l)throw new TypeError(d("0jr5e",l));if(!e(p))throw new TypeError(d("0jr5f",p));if(!r(w))throw new TypeError(d("0jr5X",w));if(!r(v))throw new TypeError(d("0jr5g",v));if(0===(a=w+v))throw new Error(d("0jr0h"));if(p!==a)throw new Error(d("0jr0i"));if(c){if(g=f.length/a,!t(g))throw new Error(d("0jr0j"))}else if(g=m.length,f.length!==g*a)throw new Error(d("0jr0j"));if(l&&l.length!==g)throw new Error(d("0jr0k"));return f=function(r){var e,t;for(e=[],t=0;t [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0jr5d', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0jr2y', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( '0jr5e', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0jr5f', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0jr5X', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0jr5g', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format('0jr0h') );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format('0jr0i') );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format('0jr0k') );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format('0jr0l') );\n\t\t\t}\n\t\t\tthrow new Error( format('0jr0m') );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( '0jr5h', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( '0jr5i', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format('0jr0n') );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found).\n*\n* ## Notes\n*\n* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types).\n* - The function assumes that `x` is stored in row-major order.\n* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`.\n* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value.\n*\n* @private\n* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension)\n* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension)\n* @param {ArrayLikeObject} x - input two-dimensional reference array\n* @param {integer} strideX1 - `x` stride length along first dimension\n* @param {integer} strideX2 - `x` stride length along second dimension\n* @param {NonNegativeInteger} offsetX - `x` starting index\n* @param {ArrayLikeObject} y - search array\n* @param {integer} strideY - `y` stride length\n* @param {NonNegativeInteger} offsetY - `y` starting index\n* @returns {integer} row index (if found) and `-1` otherwise\n*\n* @example\n* // Define a reference array to search:\n* var types = [\n* 'float64', 'float64', 'float64',\n* 'float32', 'float32', 'float32',\n* 'uint32', 'uint32', 'float64',\n* 'int32', 'int32', 'float64',\n* 'uint16', 'uint16', 'float64',\n* 'int16', 'int16', 'float64',\n* 'uint8', 'uint8', 'float64',\n* 'int8', 'int8', 'float64'\n* ];\n*\n* // Define reference array dimensions:\n* var N = 8; // rows\n* var M = 3; // columns\n*\n* // Define a search array:\n* y1 = [\n* 'float32', 'float32', 'float32',\n* ];\n*\n* // Find the list of types:\n* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 );\n* // returns 1\n*\n// Define a search array:\n* y2 = [\n* 'float32', 'float32', 'float64',\n* ];\n*\n* // Find the list of types:\n* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 );\n* // returns -1\n*/\nfunction indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len\n\tvar ix;\n\tvar iy;\n\tvar i;\n\tvar j;\n\n\t// Search for the first row which matches `y`...\n\tix = offsetX;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tiy = offsetY;\n\t\tfor ( j = 0; j < M; j++ ) {\n\t\t\tif ( x[ ix+(j*strideX2) ] !== y[ iy ] ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tiy += strideY;\n\t\t}\n\t\t// If we successfully iterated over all columns, then that means we've found a match...\n\t\tif ( j === M ) {\n\t\t\treturn i;\n\t\t}\n\t\tix += strideX1;\n\t}\n\treturn -1;\n}\n\n\n// EXPORTS //\n\nexport default indexOfTypes;\n"],"names":["dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","out","i","push","resolveEnum","types2enums","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","getDType","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","j","indexOfTypes","slice"],"mappings":";;0+BA0GA,SAASA,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAO,UAEzB,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAO,UAEzB,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAO,eAIzB,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAO,UAG1B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAO,UAGzB,OADAX,EA5GD,SAAsBA,GACrB,IAAIkB,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAInB,EAAMgB,OAAQG,IAC9BD,EAAIE,KAAMC,EAAarB,EAAOmB,KAE/B,OAAOD,CACR,CAmGSI,CAAatB,GAgBrB,WACC,IAAIuB,EACAC,EACAC,EACAC,EACAC,EACAC,EACAT,EAGJ,GADAM,EAAOI,UAAUb,OACZS,IAASvB,EAAQ,CACrB,GAAKuB,EAAOvB,EACX,MAAM,IAAIa,MAAOJ,EAAO,UAEzB,MAAM,IAAII,MAAOJ,EAAO,SACxB,CAGD,IAFAY,EAAS,GACTC,EAAS,GACHL,EAAI,EAAGA,EAAIjB,EAAOiB,IAAM,CAE7B,IAAMW,EADNH,EAAIE,UAAWV,IAEd,MAAKA,EAAIhB,EACF,IAAIO,UAAWC,EAAQ,QAASgB,IAEhC,IAAIjB,UAAWC,EAAQ,QAASgB,IAGxCJ,EAAOH,KAAMO,GACbH,EAAOJ,KAAMC,EAAaU,EAAUJ,IACpC,CAKD,IAHAD,EC1HF,SAAuBM,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAvB,EACAwB,EAIJ,IADAF,EAAKJ,EACClB,EAAI,EAAGA,EAAIa,EAAGb,IAAM,CAEzB,IADAuB,EAAKF,EACCG,EAAI,EAAGA,EAAIV,GACXC,EAAGO,EAAIE,EAAEP,KAAgBE,EAAGI,GADdC,IAInBD,GAAMH,EAGP,GAAKI,IAAMV,EACV,OAAOd,EAERsB,GAAMN,CACN,CACD,OAAQ,CACT,CDmGQS,CAActC,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGmB,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAId,UAAWC,EAAO,UAI5BiB,EADIrB,GAGAR,EAAM2B,GAGNzB,EACJ2B,EAAGL,EAAQtB,EAAMyB,IAEjBE,EAAGL,GAEJ,GAAc,IAATnB,EACJ,OAAOmB,EAAQlB,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOmB,EAAOsB,MAAO1C,EACrB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 291641d..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Create an ndarray function interface which performs multiple dispatch. -* -* @module @stdlib/ndarray-dispatch -* -* @example -* var dispatch = require( '@stdlib/ndarray-dispatch' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/index_of_types.js b/lib/index_of_types.js deleted file mode 100644 index fda2297..0000000 --- a/lib/index_of_types.js +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found). -* -* ## Notes -* -* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types). -* - The function assumes that `x` is stored in row-major order. -* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`. -* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value. -* -* @private -* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension) -* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension) -* @param {ArrayLikeObject} x - input two-dimensional reference array -* @param {integer} strideX1 - `x` stride length along first dimension -* @param {integer} strideX2 - `x` stride length along second dimension -* @param {NonNegativeInteger} offsetX - `x` starting index -* @param {ArrayLikeObject} y - search array -* @param {integer} strideY - `y` stride length -* @param {NonNegativeInteger} offsetY - `y` starting index -* @returns {integer} row index (if found) and `-1` otherwise -* -* @example -* // Define a reference array to search: -* var types = [ -* 'float64', 'float64', 'float64', -* 'float32', 'float32', 'float32', -* 'uint32', 'uint32', 'float64', -* 'int32', 'int32', 'float64', -* 'uint16', 'uint16', 'float64', -* 'int16', 'int16', 'float64', -* 'uint8', 'uint8', 'float64', -* 'int8', 'int8', 'float64' -* ]; -* -* // Define reference array dimensions: -* var N = 8; // rows -* var M = 3; // columns -* -* // Define a search array: -* y1 = [ -* 'float32', 'float32', 'float32', -* ]; -* -* // Find the list of types: -* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 ); -* // returns 1 -* -// Define a search array: -* y2 = [ -* 'float32', 'float32', 'float64', -* ]; -* -* // Find the list of types: -* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 ); -* // returns -1 -*/ -function indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len - var ix; - var iy; - var i; - var j; - - // Search for the first row which matches `y`... - ix = offsetX; - for ( i = 0; i < N; i++ ) { - iy = offsetY; - for ( j = 0; j < M; j++ ) { - if ( x[ ix+(j*strideX2) ] !== y[ iy ] ) { - break; - } - iy += strideY; - } - // If we successfully iterated over all columns, then that means we've found a match... - if ( j === M ) { - return i; - } - ix += strideX1; - } - return -1; -} - - -// EXPORTS // - -module.exports = indexOfTypes; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4648598..0000000 --- a/lib/main.js +++ /dev/null @@ -1,231 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isFunctionArray = require( '@stdlib/assert-is-function-array' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var resolveEnum = require( '@stdlib/ndarray-base-dtype-resolve-enum' ); -var indexOfTypes = require( './index_of_types.js' ); - - -// FUNCTIONS // - -/** -* Returns a list of data type enumeration constants. -* -* @private -* @param {Collection} types - list of types -* @returns {IntegerArray} list of data type enumeration constants -*/ -function types2enums( types ) { - var out; - var i; - - out = []; - for ( i = 0; i < types.length; i++ ) { - out.push( resolveEnum( types[ i ] ) ); - } - return out; -} - - -// MAIN // - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param {(FunctionArray|Function)} fcns - list of ndarray functions -* @param {Collection} types - one-dimensional list of ndarray argument data types -* @param {(Collection|null)} data - ndarray function data (e.g., callbacks) -* @param {PositiveInteger} nargs - total number of ndarray function interface arguments -* @param {NonNegativeInteger} nin - number of input ndarrays -* @param {NonNegativeInteger} nout - number of output ndarrays -* @throws {TypeError} first argument must be either a function or an array of functions -* @throws {TypeError} second argument must be an array-like object -* @throws {TypeError} third argument must be an array-like object or `null` -* @throws {Error} third and first arguments must have the same number of elements -* @throws {TypeError} fourth argument must be a positive integer -* @throws {TypeError} fifth argument must be a nonnegative integer -* @throws {TypeError} sixth argument must be a nonnegative integer -* @throws {Error} fourth argument must equal the specified number of input and output arrays -* @throws {Error} number of types must match the number of functions times the total number of array arguments for each function -* @throws {Error} interface must accept at least one input and/or output ndarray -* @returns {Function} ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function dispatch( fcns, types, data, nargs, nin, nout ) { - var narrays; - var nfcns; - var fcn; - - if ( isFunction( fcns ) ) { - fcn = fcns; - } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( '0jr5d', fcns ) ); - } - if ( !isCollection( types ) ) { - throw new TypeError( format( '0jr2y', types ) ); - } - if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( '0jr5e', data ) ); - } - if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( '0jr5f', nargs ) ); - } - if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( '0jr5X', nin ) ); - } - if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( '0jr5g', nout ) ); - } - narrays = nin + nout; - if ( narrays === 0 ) { - throw new Error( format('0jr0h') ); - } - if ( nargs !== narrays ) { - throw new Error( format('0jr0i') ); - } - if ( fcn ) { - nfcns = types.length / narrays; - if ( !isInteger( nfcns ) ) { - throw new Error( format('0jr0j') ); - } - } else { - nfcns = fcns.length; - if ( types.length !== nfcns*narrays ) { - throw new Error( format('0jr0j') ); - } - } - if ( data && data.length !== nfcns ) { - throw new Error( format('0jr0k') ); - } - types = types2enums( types ); - return dispatcher; - - /** - * ndarray function interface which performs multiple dispatch. - * - * @private - * @param {ndarrayLike} x - ndarray - * @param {...ndarrayLike} args - ndarray arguments - * @throws {Error} insufficient arguments - * @throws {Error} too many arguments - * @throws {TypeError} input array arguments must be ndarray-like objects - * @throws {TypeError} output array arguments must be ndarray-like objects - * @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types - * @returns {(ndarrayLike|Array|void)} destination array(s) - */ - function dispatcher() { - var arrays; - var dtypes; - var argc; - var idx; - var v; - var f; - var i; - - argc = arguments.length; - if ( argc !== nargs ) { - if ( argc < nargs ) { - throw new Error( format('0jr0l') ); - } - throw new Error( format('0jr0m') ); - } - arrays = []; - dtypes = []; - for ( i = 0; i < nargs; i++ ) { - v = arguments[ i ]; - if ( !isndarrayLike( v ) ) { - if ( i < nin ) { - throw new TypeError( format( '0jr5h', v ) ); - } else { - throw new TypeError( format( '0jr5i', v ) ); - } - } - arrays.push( v ); - dtypes.push( resolveEnum( getDType( v ) ) ); - } - // Resolve the ndarray function satisfying the input array types: - idx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len - - // Check whether we were able to successfully resolve an ndarray function: - if ( idx < 0 ) { - throw new TypeError( format('0jr0n') ); - } - // Retrieve the ndarray function: - if ( fcn ) { - f = fcn; - } else { - f = fcns[ idx ]; - } - // Evaluate the ndarray function: - if ( data ) { - f( arrays, data[ idx ] ); - } else { - f( arrays ); - } - if ( nout === 1 ) { - return arrays[ narrays-1 ]; - } - if ( nout === 0 ) { - return; - } - return arrays.slice( nin ); - } -} - - -// EXPORTS // - -module.exports = dispatch; diff --git a/package.json b/package.json index d66c7e4..ffe4f55 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Create an ndarray function interface which performs multiple dispatch.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,57 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-collection": "^0.2.1", - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/assert-is-function-array": "^0.2.1", - "@stdlib/assert-is-integer": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/assert-is-nonnegative-integer": "^0.2.1", - "@stdlib/assert-is-positive-integer": "^0.2.1", - "@stdlib/ndarray-base-dtype-resolve-enum": "^0.2.1", - "@stdlib/ndarray-dtype": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.2.1", - "@stdlib/array-float64": "^0.2.1", - "@stdlib/array-int32": "^0.2.1", - "@stdlib/array-int8": "^0.2.1", - "@stdlib/array-uint8": "^0.2.1", - "@stdlib/math-base-assert-is-nan": "^0.2.1", - "@stdlib/math-base-special-abs": "^0.2.1", - "@stdlib/math-base-special-pow": "^0.2.1", - "@stdlib/math-base-special-sin": "^0.2.1", - "@stdlib/ndarray-base-buffer-dtype": "^0.2.1", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-base-unary": "^0.2.1", - "@stdlib/ndarray-ctor": "^0.2.1", - "@stdlib/ndarray-dtypes": "^0.2.1", - "@stdlib/ndarray-ind2sub": "^0.2.1", - "@stdlib/strided-dtypes": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "ndarray", @@ -100,7 +26,6 @@ "multimethod", "multimethods" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..f1e9034 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/fixtures/binary.js b/test/fixtures/binary.js deleted file mode 100644 index a60dfa2..0000000 --- a/test/fixtures/binary.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Binary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @returns {number} sum -*/ -function binary( x, y ) { - return x + y; -} - - -// EXPORTS // - -module.exports = binary; diff --git a/test/fixtures/fill.js b/test/fixtures/fill.js deleted file mode 100644 index 41b2958..0000000 --- a/test/fixtures/fill.js +++ /dev/null @@ -1,76 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which fills one or more ndarrays. -* -* @private -* @param {*} value - fill value -* @returns {Function} ndarray function -*/ -function fill( value ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - */ - function ndarrayFcn( arrays ) { - var opts; - var sub; - var arr; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - opts = { - 'order': '' - }; - for ( j = 0; j < M; j++ ) { - arr = arrays[ j ]; - opts.order = arrays[ j ].order; - for ( i = 0; i < N; i++ ) { - sub = ind2sub( sh, i, opts ); - sub.push( value ); - arr.set.apply( arr, sub ); - } - } - } -} - - -// EXPORTS // - -module.exports = fill; diff --git a/test/fixtures/foreach.js b/test/fixtures/foreach.js deleted file mode 100644 index a426290..0000000 --- a/test/fixtures/foreach.js +++ /dev/null @@ -1,72 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function forEach( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - fcn.apply( null, args ); - } -} - - -// EXPORTS // - -module.exports = forEach; diff --git a/test/fixtures/map1n.js b/test/fixtures/map1n.js deleted file mode 100644 index 614196b..0000000 --- a/test/fixtures/map1n.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function which maps the return value of a callback to `N` arrays. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function map1N( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var v; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - v = fcn(); - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - sub.push( v ); - arrays[ j ].set.apply( arrays[ j ], sub ); - } - } -} - - -// EXPORTS // - -module.exports = map1N; diff --git a/test/fixtures/nullary.js b/test/fixtures/nullary.js deleted file mode 100644 index 4f22126..0000000 --- a/test/fixtures/nullary.js +++ /dev/null @@ -1,36 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Nullary callback. -* -* @private -* @returns {number} value -*/ -function nullary() { - return 3.0; -} - - -// EXPORTS // - -module.exports = nullary; diff --git a/test/fixtures/quaternary.js b/test/fixtures/quaternary.js deleted file mode 100644 index 548437b..0000000 --- a/test/fixtures/quaternary.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quaternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @returns {number} sum -*/ -function quaternary( x, y, z, w ) { - return x + y + z + w; -} - - -// EXPORTS // - -module.exports = quaternary; diff --git a/test/fixtures/quinary.js b/test/fixtures/quinary.js deleted file mode 100644 index 36068de..0000000 --- a/test/fixtures/quinary.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quinary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @param {number} u - input value -* @returns {number} sum -*/ -function quinary( x, y, z, w, u ) { - return x + y + z + w + u; -} - - -// EXPORTS // - -module.exports = quinary; diff --git a/test/fixtures/sum.js b/test/fixtures/sum.js deleted file mode 100644 index efdbb1b..0000000 --- a/test/fixtures/sum.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which computes the sum across one or more ndarrays. -* -* @private -* @param {Object} ctx - context -* @param {number} ctx.sum - initial sum -* @returns {Function} ndarray function -*/ -function wrapper( ctx ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - * @param {Function} [fcn] - callback - */ - function ndarrayFcn( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var f; - var i; - var j; - - if ( arguments.length > 1 ) { - f = fcn; - } - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - if ( f ) { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - ctx.sum += f.apply( null, args ); - } - } else { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - ctx.sum += arrays[ j ].get.apply( arrays[ j ], sub ); - } - } - } - } -} - - -// EXPORTS // - -module.exports = wrapper; diff --git a/test/fixtures/ternary.js b/test/fixtures/ternary.js deleted file mode 100644 index 0595d5f..0000000 --- a/test/fixtures/ternary.js +++ /dev/null @@ -1,39 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Ternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @returns {number} sum -*/ -function ternary( x, y, z ) { - return x + y + z; -} - - -// EXPORTS // - -module.exports = ternary; diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d6c2c8e..0000000 --- a/test/test.js +++ /dev/null @@ -1,363 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var fill = require( './fixtures/fill.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either a function or an array of functions as a first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( value, types, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object as a second argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided either an array-like object or `null` as a third argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - dispatch( unary, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a positive integer for a fourth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 0, - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a fifth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, value, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a sixth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, 1, value ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function array)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var fcns = [ unary, unary, unary ]; - var data = [ abs, abs, abs ]; - dispatch( fcns, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function argument)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs, abs, abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the length of `data` argument does not match the number of ndarray functions', function test( t ) { - var values; - var i; - - values = [ - [], - [ abs, abs ], - [ abs, abs, abs ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var fcns = [ unary ]; - dispatch( fcns, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the fourth argument is incompatible with the number of input and output ndarrays', function test( t ) { - var values; - var i; - - values = [ - 0, - 1, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of specified input and output ndarrays is zero', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var types = [ 'float64' ]; - dispatch( fill( 3 ), types, null, 1, 0, 0 ); - } -}); - -tape( 'the function returns an ndarray function interface', function test( t ) { - var types; - var data; - var f; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - f = dispatch( unary, types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ unary ], types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( fill( 3 ), types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ fill( 3 ) ], types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.two_arrays.js b/test/test.two_arrays.js deleted file mode 100644 index 16eb61b..0000000 --- a/test/test.two_arrays.js +++ /dev/null @@ -1,814 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var dtype = require( '@stdlib/ndarray-base-buffer-dtype' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var forEach = require( './fixtures/foreach.js' ); -var map1N = require( './fixtures/map1n.js' ); -var fill = require( './fixtures/fill.js' ); -var sum = require( './fixtures/sum.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the first argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var ybuf = new Float64Array( 10 ); - var y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( value, y ); - }; - } -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the second argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var xbuf = new Float64Array( 10 ); - var x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( x, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided insufficient arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var f; - var x; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [], - [ x ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided too many arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var ybuf; - var f; - var x; - var y; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [ x, y, y ], - [ x, y, y, y ], - [ x, y, y, y, y ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if unable to resolve a ndarray function supporting the provided array argument data types', function test( t ) { - var values; - var types; - var data; - var xbuf; - var fcn; - var x; - var i; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ abs, abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 4 ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - values = [ - new Uint8Array( 4 ), - new Int32Array( 4 ), - [ 0, 0, 0, 0 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided an array having data type: ' + dtype( values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var y = ndarray( dtype( value ), value, [ value.length ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - }; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only input arrays)', function test( t ) { - var types; - var xbuf; - var ybuf; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only output arrays)', function test( t ) { - var expected; - var types; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only input arrays)', function test( t ) { - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var ctx; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcns = [ - sum( ctx ), - sum( ctx ) - ]; - fcn = dispatch( fcns, types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only output arrays)', function test( t ) { - var expected; - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcns = [ - fill( 3.0 ), - fill( 4.0 ) - ]; - fcn = dispatch( fcns, types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - - fcn = dispatch( forEach, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - - fcn = dispatch( map1N, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - fcns = [ - forEach, - forEach - ]; - fcn = dispatch( fcns, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - fcns = [ - map1N, - map1N - ]; - fcn = dispatch( fcns, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - fcns = [ - unary, - unary - ]; - fcn = dispatch( fcns, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which returns one or more output arrays, if one or more output arrays is specified, and otherwise returns `undefined`', function test( t ) { - var types; - var data; - var xbuf; - var ybuf; - var out; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - // No output arrays... - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, void 0, 'returns expected value' ); - - // One output array... - data = [ - abs, - abs - ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - fcn = dispatch( fill( 3.0 ), types, null, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - // Two output arrays... - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.end(); -}); From ce2a3ed2aae776f0a52c7c36da56ab6df310c80b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 5 May 2024 20:55:07 +0000 Subject: [PATCH 078/109] Transform error messages --- lib/main.js | 34 +++++++++++++++++----------------- package.json | 2 +- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/main.js b/lib/main.js index 5f4bb5d..4648598 100644 --- a/lib/main.js +++ b/lib/main.js @@ -27,7 +27,7 @@ var isFunctionArray = require( '@stdlib/assert-is-function-array' ); var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var getDType = require( '@stdlib/ndarray-dtype' ); var resolveEnum = require( '@stdlib/ndarray-base-dtype-resolve-enum' ); var indexOfTypes = require( './index_of_types.js' ); @@ -112,43 +112,43 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { if ( isFunction( fcns ) ) { fcn = fcns; } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) ); + throw new TypeError( format( '0jr5d', fcns ) ); } if ( !isCollection( types ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) ); + throw new TypeError( format( '0jr2y', types ) ); } if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); + throw new TypeError( format( '0jr5e', data ) ); } if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) ); + throw new TypeError( format( '0jr5f', nargs ) ); } if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) ); + throw new TypeError( format( '0jr5X', nin ) ); } if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) ); + throw new TypeError( format( '0jr5g', nout ) ); } narrays = nin + nout; if ( narrays === 0 ) { - throw new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' ); + throw new Error( format('0jr0h') ); } if ( nargs !== narrays ) { - throw new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' ); + throw new Error( format('0jr0i') ); } if ( fcn ) { nfcns = types.length / narrays; if ( !isInteger( nfcns ) ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format('0jr0j') ); } } else { nfcns = fcns.length; if ( types.length !== nfcns*narrays ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format('0jr0j') ); } } if ( data && data.length !== nfcns ) { - throw new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' ); + throw new Error( format('0jr0k') ); } types = types2enums( types ); return dispatcher; @@ -178,9 +178,9 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { argc = arguments.length; if ( argc !== nargs ) { if ( argc < nargs ) { - throw new Error( 'invalid invocation. Insufficient arguments.' ); + throw new Error( format('0jr0l') ); } - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('0jr0m') ); } arrays = []; dtypes = []; @@ -188,9 +188,9 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { v = arguments[ i ]; if ( !isndarrayLike( v ) ) { if ( i < nin ) { - throw new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) ); + throw new TypeError( format( '0jr5h', v ) ); } else { - throw new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) ); + throw new TypeError( format( '0jr5i', v ) ); } } arrays.push( v ); @@ -201,7 +201,7 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { // Check whether we were able to successfully resolve an ndarray function: if ( idx < 0 ) { - throw new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' ); + throw new TypeError( format('0jr0n') ); } // Retrieve the ndarray function: if ( fcn ) { diff --git a/package.json b/package.json index 996faed..d66c7e4 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/assert-is-positive-integer": "^0.2.1", "@stdlib/ndarray-base-dtype-resolve-enum": "^0.2.1", "@stdlib/ndarray-dtype": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, From f98c07153bf1bdfe2162a164f360afeca4870bc3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 5 May 2024 20:55:50 +0000 Subject: [PATCH 079/109] Remove files --- index.d.ts | 334 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5181 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index c49a4e4..0000000 --- a/index.d.ts +++ /dev/null @@ -1,334 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* ndarray function. -* -* @param arrays - array containing input and output ndarrays -* @param data - ndarray function data (e.g., a callback) -* -* @example -* var numel = require( '@stdlib/ndarray-base-numel' ); -* var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -* -* function ndarrayFcn( arrays, fcn ) { -* var xord; -* var yord; -* var opts; -* var sub; -* var sh; -* var N; -* var x; -* var y; -* var v; -* var i; -* -* x = arrays[ 0 ]; -* y = arrays[ 1 ]; -* sh = x.shape; -* N = numel( sh ); -* if ( N <= 0 ) { -* return; -* } -* xord = x.order; -* yord = y.order; -* opts = {}; -* opts.order = xord; -* for ( i = 0; i < N; i++ ) { -* // Convert a linear index to subscripts: -* opts.order = xord; -* sub = ind2sub( sh, i, opts ); -* -* // Retrieve an element from `x`: -* v = x.get.apply( x, sub ); -* -* // Convert a linear index to subscripts: -* opts.order = yord; -* sub = ind2sub( sh, i, opts ); -* -* // Append the result of applying the callback: -* sub.push( fcn( v ) ); -* -* // Assign the result to an element in `y`: -* y.set.apply( y, sub ); -* } -* } -*/ -type ndarrayFcn = ( arrays: Array, data?: any ) => void; - -/** -* Interface describing an ndarray function dispatcher. -*/ -interface Dispatcher { - /** - * Invokes an ndarray function based on the provided array data type(s). - * - * @param x - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array - * - * @example - * var nullary = require( '@stdlib/ndarray-base-nullary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function value() { - * return 3.14; - * } - * - * var types = [ 'float64' ]; - * var data = [ value ]; - * - * var fcn = dispatch( nullary, types, data, 1, 0, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( 5 ); - * var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x ); - * // xbuf => [ 3.14, 3.14, 3.14, 3.14, 3.14 ] - */ - ( x: ndarray ): ndarray | void; - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var unary = require( '@stdlib/ndarray-base-unary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * var abs = require( '@stdlib/math-base-special-abs' ); - * - * var types = [ 'float64', 'float64' ]; - * var data = [ abs ]; - * - * var fcn = dispatch( unary, types, data, 2, 1, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - * var ybuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y ); - * // ybuf => [ 1.0, 2.0, 3.0 ] - */ - ( x: ndarray, y: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var ternary = require( '@stdlib/ndarray-base-ternary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function add2( x, y ) { - * return x + y; - * } - * - * var types = [ 'float64', 'float64', 'float64' ]; - * var data = [ add2 ]; - * - * var fcn = dispatch( ternary, types, data, 3, 2, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z ); - * // zbuf => [ 2.0, 4.0, 6.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quaternary = require( '@stdlib/ndarray-base-quaternary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function add3( x, y, z ) { - * return x + y + z; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add3 ]; - * - * var fcn = dispatch( quaternary, types, data, 4, 3, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w ); - * // wbuf => [ 3.0, 6.0, 9.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @param args - ndarray arguments - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quinary = require( '@stdlib/ndarray-base-quinary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function add4( x, y, z, w ) { - * return x + y + z + w; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add4 ]; - * - * var fcn = dispatch( quinary, types, data, 5, 4, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ubuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var u = ndarray( 'float64', ubuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w, u ); - * // ubuf => [ 4.0, 8.0, 12.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray, ...args: Array ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures -} - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param fcns - list of ndarray functions -* @param types - one-dimensional list of ndarray argument data types -* @param data - ndarray function data (e.g., callbacks) -* @param nargs - total number of ndarray function interface arguments -* @param nin - number of input ndarrays -* @param nout - number of output ndarrays -* @throws first argument must be either a function or an array of functions -* @throws second argument must be an array-like object -* @throws third argument must be an array-like object or `null` -* @throws third and first arguments must have the same number of elements -* @throws fourth argument must be a positive integer -* @throws fifth argument must be a nonnegative integer -* @throws sixth argument must be a nonnegative integer -* @throws fourth argument must equal the specified number of input and output arrays -* @throws number of types must match the number of functions times the total number of array arguments for each function -* @throws interface must accept at least one input and/or output ndarray -* @returns ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var fcn = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* fcn( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function dispatch( fcns: ndarrayFcn | ArrayLike, types: ArrayLike, data: ArrayLike | null, nargs: number, nin: number, nout: number ): Dispatcher; - - -// EXPORTS // - -export = dispatch; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index ad38c4f..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@v0.2.1-esm/index.mjs";function m(m,f,l,p,w,v){var a,g,c;if(i(m))c=m;else if(!s(m))throw new TypeError(d("0jr5d",m));if(!n(f))throw new TypeError(d("0jr2y",f));if(!n(l)&&null!==l)throw new TypeError(d("0jr5e",l));if(!e(p))throw new TypeError(d("0jr5f",p));if(!r(w))throw new TypeError(d("0jr5X",w));if(!r(v))throw new TypeError(d("0jr5g",v));if(0===(a=w+v))throw new Error(d("0jr0h"));if(p!==a)throw new Error(d("0jr0i"));if(c){if(g=f.length/a,!t(g))throw new Error(d("0jr0j"))}else if(g=m.length,f.length!==g*a)throw new Error(d("0jr0j"));if(l&&l.length!==g)throw new Error(d("0jr0k"));return f=function(r){var e,t;for(e=[],t=0;t [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0jr5d', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0jr2y', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( '0jr5e', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0jr5f', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0jr5X', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0jr5g', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format('0jr0h') );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format('0jr0i') );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format('0jr0k') );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format('0jr0l') );\n\t\t\t}\n\t\t\tthrow new Error( format('0jr0m') );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( '0jr5h', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( '0jr5i', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format('0jr0n') );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found).\n*\n* ## Notes\n*\n* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types).\n* - The function assumes that `x` is stored in row-major order.\n* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`.\n* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value.\n*\n* @private\n* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension)\n* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension)\n* @param {ArrayLikeObject} x - input two-dimensional reference array\n* @param {integer} strideX1 - `x` stride length along first dimension\n* @param {integer} strideX2 - `x` stride length along second dimension\n* @param {NonNegativeInteger} offsetX - `x` starting index\n* @param {ArrayLikeObject} y - search array\n* @param {integer} strideY - `y` stride length\n* @param {NonNegativeInteger} offsetY - `y` starting index\n* @returns {integer} row index (if found) and `-1` otherwise\n*\n* @example\n* // Define a reference array to search:\n* var types = [\n* 'float64', 'float64', 'float64',\n* 'float32', 'float32', 'float32',\n* 'uint32', 'uint32', 'float64',\n* 'int32', 'int32', 'float64',\n* 'uint16', 'uint16', 'float64',\n* 'int16', 'int16', 'float64',\n* 'uint8', 'uint8', 'float64',\n* 'int8', 'int8', 'float64'\n* ];\n*\n* // Define reference array dimensions:\n* var N = 8; // rows\n* var M = 3; // columns\n*\n* // Define a search array:\n* y1 = [\n* 'float32', 'float32', 'float32',\n* ];\n*\n* // Find the list of types:\n* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 );\n* // returns 1\n*\n// Define a search array:\n* y2 = [\n* 'float32', 'float32', 'float64',\n* ];\n*\n* // Find the list of types:\n* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 );\n* // returns -1\n*/\nfunction indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len\n\tvar ix;\n\tvar iy;\n\tvar i;\n\tvar j;\n\n\t// Search for the first row which matches `y`...\n\tix = offsetX;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tiy = offsetY;\n\t\tfor ( j = 0; j < M; j++ ) {\n\t\t\tif ( x[ ix+(j*strideX2) ] !== y[ iy ] ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tiy += strideY;\n\t\t}\n\t\t// If we successfully iterated over all columns, then that means we've found a match...\n\t\tif ( j === M ) {\n\t\t\treturn i;\n\t\t}\n\t\tix += strideX1;\n\t}\n\treturn -1;\n}\n\n\n// EXPORTS //\n\nexport default indexOfTypes;\n"],"names":["dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","out","i","push","resolveEnum","types2enums","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","getDType","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","j","indexOfTypes","slice"],"mappings":";;0+BA0GA,SAASA,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAO,UAEzB,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAO,UAEzB,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAO,eAIzB,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAO,UAG1B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAO,UAGzB,OADAX,EA5GD,SAAsBA,GACrB,IAAIkB,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAInB,EAAMgB,OAAQG,IAC9BD,EAAIE,KAAMC,EAAarB,EAAOmB,KAE/B,OAAOD,CACR,CAmGSI,CAAatB,GAgBrB,WACC,IAAIuB,EACAC,EACAC,EACAC,EACAC,EACAC,EACAT,EAGJ,GADAM,EAAOI,UAAUb,OACZS,IAASvB,EAAQ,CACrB,GAAKuB,EAAOvB,EACX,MAAM,IAAIa,MAAOJ,EAAO,UAEzB,MAAM,IAAII,MAAOJ,EAAO,SACxB,CAGD,IAFAY,EAAS,GACTC,EAAS,GACHL,EAAI,EAAGA,EAAIjB,EAAOiB,IAAM,CAE7B,IAAMW,EADNH,EAAIE,UAAWV,IAEd,MAAKA,EAAIhB,EACF,IAAIO,UAAWC,EAAQ,QAASgB,IAEhC,IAAIjB,UAAWC,EAAQ,QAASgB,IAGxCJ,EAAOH,KAAMO,GACbH,EAAOJ,KAAMC,EAAaU,EAAUJ,IACpC,CAKD,IAHAD,EC1HF,SAAuBM,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAvB,EACAwB,EAIJ,IADAF,EAAKJ,EACClB,EAAI,EAAGA,EAAIa,EAAGb,IAAM,CAEzB,IADAuB,EAAKF,EACCG,EAAI,EAAGA,EAAIV,GACXC,EAAGO,EAAIE,EAAEP,KAAgBE,EAAGI,GADdC,IAInBD,GAAMH,EAGP,GAAKI,IAAMV,EACV,OAAOd,EAERsB,GAAMN,CACN,CACD,OAAQ,CACT,CDmGQS,CAActC,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGmB,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAId,UAAWC,EAAO,UAI5BiB,EADIrB,GAGAR,EAAM2B,GAGNzB,EACJ2B,EAAGL,EAAQtB,EAAMyB,IAEjBE,EAAGL,GAEJ,GAAc,IAATnB,EACJ,OAAOmB,EAAQlB,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOmB,EAAOsB,MAAO1C,EACrB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index f1e9034..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From a3a25a5e2ef70a58602a691f2522f8ec78808d77 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 5 May 2024 20:56:23 +0000 Subject: [PATCH 080/109] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 248 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 61 +- SECURITY.md | 5 - benchmark/benchmark.dispatch_size.js | 156 - benchmark/benchmark.js | 81 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 7 - dist/index.js.map | 7 - docs/repl.txt | 87 - docs/types/test.ts | 641 --- examples/add.js | 121 - examples/sin.js | 142 - examples/unary.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/index_of_types.js | 106 - lib/main.js | 231 - package.json | 79 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/binary.js | 38 - test/fixtures/fill.js | 76 - test/fixtures/foreach.js | 72 - test/fixtures/map1n.js | 74 - test/fixtures/nullary.js | 36 - test/fixtures/quaternary.js | 40 - test/fixtures/quinary.js | 41 - test/fixtures/sum.js | 98 - test/fixtures/ternary.js | 39 - test/test.js | 363 -- test/test.two_arrays.js | 814 ---- 56 files changed, 4876 insertions(+), 6759 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.dispatch_size.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/add.js delete mode 100644 examples/sin.js delete mode 100644 examples/unary.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/index_of_types.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/fixtures/binary.js delete mode 100644 test/fixtures/fill.js delete mode 100644 test/fixtures/foreach.js delete mode 100644 test/fixtures/map1n.js delete mode 100644 test/fixtures/nullary.js delete mode 100644 test/fixtures/quaternary.js delete mode 100644 test/fixtures/quinary.js delete mode 100644 test/fixtures/sum.js delete mode 100644 test/fixtures/ternary.js delete mode 100644 test/test.js delete mode 100644 test/test.two_arrays.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ac0b7cd..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 5e92c3e..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2b4fac7..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '43 7 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f92a6c5..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -304,7 +295,7 @@ console.log( ybuf ); ## 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. +This package is part of [stdlib][stdlib], a standard library 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]. @@ -367,11 +358,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-dispatch/main/LICENSE -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.dispatch_size.js b/benchmark/benchmark.dispatch_size.js deleted file mode 100644 index 15805ba..0000000 --- a/benchmark/benchmark.dispatch_size.js +++ /dev/null @@ -1,156 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib/main.js' ); - - -// FUNCTIONS // - -/** -* Evaluates the identity function. -* -* @private -* @param {*} v - value -* @returns {*} input value -*/ -function identity( v ) { - return v; -} - -/** -* Dummy function which throws an error. -* -* @private -* @throws {Error} unexpected error -*/ -function throwError() { - throw new Error( 'unexpected error' ); -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} size - dispatch size -* @returns {Function} benchmark function -*/ -function createBenchmark( size ) { - var types; - var data; - var fcn; - var x; - var y; - var t; - var i; - - types = []; - - // Create dummy types... - for ( i = 0; i < (size-1)*2; i += 2 ) { - t = 'foo' + i; - types.push( t ); - types.push( t ); - } - // Append test types: - types.push( 'float64' ); - types.push( 'float64' ); - - // Define a list of callbacks: - data = []; - for ( i = 0; i < size-1; i++ ) { - data.push( throwError ); - } - // Append a test callback: - data.push( identity ); - - // Create the dispatcher: - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - // Create sample arrays: - x = new Float64Array( 1 ); - y = new Float64Array( x.length ); - - x = ndarray( 'float64', x, [ 1 ], [ 1 ], 0, 'row-major' ); - y = ndarray( 'float64', y, [ 1 ], [ 1 ], 0, 'row-major' ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var z; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x.data[ 0 ] = i; - z = fcn( x, y ); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var size; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - size = pow( 2, i ); - f = createBenchmark( size ); - bench( pkg+':size='+size, f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 3c6f450..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::fcns_array', function benchmark( b ) { - var types; - var fcns; - var data; - var out; - var i; - - fcns = [ unary ]; - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( fcns, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::fcn_arg', function benchmark( b ) { - var types; - var data; - var out; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( unary, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0aae4af..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch" -%% click B href "https://github.com/stdlib-js/ndarray-dispatch/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-dispatch/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-dispatch/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-dispatch/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-dispatch/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch -[production-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 1295a44..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import dispatch from '../docs/types/index'; -export = dispatch; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 7fb29cb..0000000 --- a/dist/index.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict";var y=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var b=y(function(D,w){ -function k(i,r,e,u,f,m,n,o,l){var h,t,s,a;for(h=m,s=0;s [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( 'invalid invocation. Insufficient arguments.' );\n\t\t\t}\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = dispatch;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an ndarray function interface which performs multiple dispatch.\n*\n* @module @stdlib/ndarray-dispatch\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var unary = require( '@stdlib/ndarray-base-unary' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var Float64Array = require( '@stdlib/array-float64' );\n* var dispatch = require( '@stdlib/ndarray-dispatch' );\n*\n* var types = [\n* 'float64', 'float64'\n* ];\n*\n* var data = [\n* abs\n* ];\n*\n* var absolute = dispatch( unary, types, data, 2, 1, 1 );\n*\n* // ...\n*\n* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] );\n* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] );\n*\n* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' );\n* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' );\n*\n* absolute( x, y );\n* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA6EA,SAASC,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,EAAU,CAClF,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,CAAU,IAAME,EAAGI,CAAG,EADjBE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,CACP,CACA,MAAO,EACR,CAKAL,EAAO,QAAUC,ICzGjB,IAAAc,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAoB,QAAS,oCAAqC,EAClEC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAkB,QAAS,kCAAmC,EAC9DC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAc,QAAS,yCAA0C,EACjEC,EAAe,IAYnB,SAASC,EAAaC,EAAQ,CAC7B,IAAIC,EACAC,EAGJ,IADAD,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIF,EAAM,OAAQE,IAC9BD,EAAI,KAAMJ,EAAaG,EAAOE,CAAE,CAAE,CAAE,EAErC,OAAOD,CACR,CAqDA,SAASE,EAAUC,EAAMJ,EAAOK,EAAMC,EAAOC,EAAKC,EAAO,CACxD,IAAIC,EACAC,EACAC,EAEJ,GAAKnB,EAAYY,CAAK,EACrBO,EAAMP,UACK,CAACb,EAAiBa,CAAK,EAClC,MAAM,IAAI,UAAWT,EAAQ,oGAAqGS,CAAK,CAAE,EAE1I,GAAK,CAACX,EAAcO,CAAM,EACzB,MAAM,IAAI,UAAWL,EAAQ,+EAAgFK,CAAM,CAAE,EAEtH,GAAK,CAACP,EAAcY,CAAK,GAAKA,IAAS,KACtC,MAAM,IAAI,UAAWV,EAAQ,sFAAuFU,CAAK,CAAE,EAE5H,GAAK,CAAChB,EAAmBiB,CAAM,EAC9B,MAAM,IAAI,UAAWX,EAAQ,6EAA8EW,CAAM,CAAE,EAEpH,GAAK,CAAClB,EAAsBmB,CAAI,EAC/B,MAAM,IAAI,UAAWZ,EAAQ,+EAAgFY,CAAI,CAAE,EAEpH,GAAK,CAACnB,EAAsBoB,CAAK,EAChC,MAAM,IAAI,UAAWb,EAAQ,+EAAgFa,CAAK,CAAE,EAGrH,GADAC,EAAUF,EAAMC,EACXC,IAAY,EAChB,MAAM,IAAI,MAAO,4IAA6I,EAE/J,GAAKH,IAAUG,EACd,MAAM,IAAI,MAAO,4FAA6F,EAE/G,GAAKE,GAEJ,GADAD,EAAQV,EAAM,OAASS,EAClB,CAACnB,EAAWoB,CAAM,EACtB,MAAM,IAAI,MAAO,8IAA+I,UAGjKA,EAAQN,EAAK,OACRJ,EAAM,SAAWU,EAAMD,EAC3B,MAAM,IAAI,MAAO,8IAA+I,EAGlK,GAAKJ,GAAQA,EAAK,SAAWK,EAC5B,MAAM,IAAI,MAAO,mGAAoG,EAEtH,OAAAV,EAAQD,EAAaC,CAAM,EACpBY,EAeP,SAASA,GAAa,CACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EAGJ,GADAa,EAAO,UAAU,OACZA,IAAST,EACb,MAAKS,EAAOT,EACL,IAAI,MAAO,6CAA8C,EAE1D,IAAI,MAAO,yCAA0C,EAI5D,IAFAO,EAAS,CAAC,EACVC,EAAS,CAAC,EACJZ,EAAI,EAAGA,EAAII,EAAOJ,IAAM,CAE7B,GADAe,EAAI,UAAWf,CAAE,EACZ,CAACR,EAAeuB,CAAE,EACtB,MAAKf,EAAIK,EACF,IAAI,UAAWZ,EAAQ,6EAA8EsB,CAAE,CAAE,EAEzG,IAAI,UAAWtB,EAAQ,8EAA+EsB,CAAE,CAAE,EAGlHJ,EAAO,KAAMI,CAAE,EACfH,EAAO,KAAMjB,EAAaD,EAAUqB,CAAE,CAAE,CAAE,CAC3C,CAKA,GAHAD,EAAMlB,EAAcY,EAAOD,EAAST,EAAOS,EAAS,EAAG,EAAGK,EAAQ,EAAG,CAAE,EAGlEE,EAAM,EACV,MAAM,IAAI,UAAW,6GAA8G,EAcpI,GAXKL,EACJO,EAAIP,EAEJO,EAAId,EAAMY,CAAI,EAGVX,EACJa,EAAGL,EAAQR,EAAMW,CAAI,CAAE,EAEvBE,EAAGL,CAAO,EAENL,IAAS,EACb,OAAOK,EAAQJ,EAAQ,CAAE,EAE1B,GAAKD,IAAS,EAGd,OAAOK,EAAO,MAAON,CAAI,CAC1B,CACD,CAKApB,EAAO,QAAUgB,IC9KjB,IAAIgB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_index_of_types", "__commonJSMin", "exports", "module", "indexOfTypes", "N", "M", "x", "strideX1", "strideX2", "offsetX", "y", "strideY", "offsetY", "ix", "iy", "i", "j", "require_main", "__commonJSMin", "exports", "module", "isNonNegativeInteger", "isPositiveInteger", "isInteger", "isFunctionArray", "isFunction", "isCollection", "isndarrayLike", "format", "getDType", "resolveEnum", "indexOfTypes", "types2enums", "types", "out", "i", "dispatch", "fcns", "data", "nargs", "nin", "nout", "narrays", "nfcns", "fcn", "dispatcher", "arrays", "dtypes", "argc", "idx", "v", "f", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 02fe150..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,87 +0,0 @@ - -{{alias}}( fcns, types, data, nargs, nin, nout ) - Returns an ndarray function interface which performs multiple dispatch. - - An ndarray function interface has the following signature: - - f( x, y, ... ) - - where - - - x: ndarray. - - y: ndarray. - - ...: additional ndarrays. - - The number of parameters is derived from `nargs`, the number of input - ndarrays is derived from `nin`, and the number of output ndarrays is derived - from `nout`. - - Parameters - ---------- - fcns: Function|ArrayLikeObject - List of ndarray functions. An ndarray function should have the following - signature: - - f( arrays, data ) - - where - - - arrays: array containing input and output ndarrays. - - data: ndarray function data (e.g., a callback). - - For convenience, a single ndarray function may be provided which will be - invoked whenever the ndarray argument data types match a sequence of - types in `types`. Providing a single ndarray function is particularly - convenient for the case where, regardless of array data types, - traversing arrays remains the same, but the ndarray function `data` - differs (e.g., callbacks which differ based on the array data types). - - types: ArrayLikeObject - One-dimensional list of ndarray argument data types. - - data: ArrayLikeObject|null - ndarray function data (e.g., callbacks). If `null`, a returned ndarray - function interface does **not** provide a `data` argument to an invoked - ndarray function. - - nargs: integer - Total number of ndarray function interface arguments. - - nin: integer - Number of input ndarrays. - - nout: integer - Number of output ndarrays. - - Returns - ------- - fcn: Function - ndarray function interface. - - Examples - -------- - // Define ndarray argument data types: - > var t = [ 'float64', 'float64', 'float32', 'float32' ]; - - // Define a list of ndarray function data (callbacks): - > var d = [ {{alias:@stdlib/math/base/special/abs}}, {{alias:@stdlib/math/base/special/absf}} ]; - - // Create an ndarray function interface for applying unary callbacks: - > var f = {{alias}}( {{alias:@stdlib/ndarray/base/unary}}, t, d, 2, 1, 1 ); - - // Create an input ndarray: - > var xbuf = new {{alias:@stdlib/array/float64}}( [ -1.0, -2.0, -3.0, -4.0 ] ); - > var x = {{alias:@stdlib/ndarray/ctor}}( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Create an output ndarray: - > var ybuf = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 0.0, 0.0 ] ); - > var y = {{alias:@stdlib/ndarray/ctor}}( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Compute the element-wise absolute value: - > f( x, y ); - > ybuf - [ 1.0, 2.0, 3.0, 4.0 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 3cba031..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,641 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable max-lines */ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import dispatch = require( './index' ); - - -// FUNCTIONS // - -/** -* Nullary callback. -* -* @return input value -*/ -function nullary(): any { - return 5.0; -} - -/** -* Unary callback. -* -* @param x - input value -* @return input value -*/ -function unary( x: any ): any { - return x; -} - -/** -* Binary callback. -* -* @param x - input value -* @param y - input value -* @return output value -*/ -function binary( x: number, y: number ): number { - return x + y; -} - -/** -* Ternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @return output value -*/ -function ternary( x: number, y: number, z: number ): number { - return x + y + z; -} - -/** -* Quaternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @param w - input value -* @return output value -*/ -function quaternary( x: number, y: number, z: number, w: number ): number { - return x + y + z + w; -} - -/** -* Mock `ind2sub` function. -* -* @param shape - dimensions -* @param idx - linear index -* @param opts - options -* @return subscripts -*/ -function ind2sub( shape: ArrayLike, idx: number, opts?: any ): Array { - let out; - let i; - - out = []; - if ( typeof opts === 'object' && opts !== null && opts.order === 'row-major' ) { no-unsafe-any - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } else { - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } - return out; -} - -/** -* Mock ndarray function. -* -* @param arrays - ndarrays -* @param fcn - callback -*/ -function ndarrayFcn( arrays: Array, fcn: ( x: any ) => any ): void { - let xord; - let yord; - let opts; - let sub; - let sh; - let N; - let x; - let y; - let v; - let i; - - x = arrays[ 0 ]; - y = arrays[ 1 ]; - sh = x.shape; - if ( sh.length === 0 ) { - return; - } - N = 1; - for ( i = 0; i < sh.length; i += 1 ) { - N *= sh[ i ]; - } - xord = x.order; - yord = y.order; - opts = { - 'order': '' - }; - opts.order = xord; - for ( i = 0; i < N; i += 1 ) { - // Convert a linear index to subscripts: - opts.order = xord; - sub = ind2sub( sh, i, opts ); - - // Retrieve an element from `x`: - v = x.get.apply( x, sub ); - - // Convert a linear index to subscripts: - opts.order = yord; - sub = ind2sub( sh, i, opts ); - - // Append the result of applying the callback: - sub[ sub.length ] = fcn( v ) as number; - - // Assign the result to an element in `y`: - y.set.apply( y, sub ); - } -} - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a dispatch function... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, 1 ); // $ExpectType Dispatcher - dispatch( [ ndarrayFcn ], types, data, 2, 1, 1 ); // $ExpectType Dispatcher -} - -// The compiler throws an error if the function is provided a first argument which is not either an ndarray function or an array-like object containing ndarray functions... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( '10', types, data, 2, 1, 1 ); // $ExpectError - dispatch( 10, types, data, 2, 1, 1 ); // $ExpectError - dispatch( true, types, data, 2, 1, 1 ); // $ExpectError - dispatch( false, types, data, 2, 1, 1 ); // $ExpectError - dispatch( null, types, data, 2, 1, 1 ); // $ExpectError - dispatch( undefined, types, data, 2, 1, 1 ); // $ExpectError - dispatch( [ '1' ], types, data, 2, 1, 1 ); // $ExpectError - dispatch( {}, types, data, 2, 1, 1 ); // $ExpectError - dispatch( ( x: number ): number => x, types, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object... -{ - const data = [ unary ]; - - dispatch( ndarrayFcn, 10, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, true, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, false, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, null, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, undefined, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, {}, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object or null... -{ - const types = [ 'float64', 'float64' ]; - - dispatch( ndarrayFcn, types, 10, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, true, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, false, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, undefined, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, {}, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, '10', 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, true, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, false, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, null, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, undefined, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, [ '1' ], 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, {}, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, ( x: number ): number => x, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, '10', 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, true, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, false, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, null, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, undefined, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, [ '1' ], 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, {}, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, ( x: number ): number => x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, '10' ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, true ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, false ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, null ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, undefined ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, [ '1' ] ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, {} ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch(); // $ExpectError - dispatch( ndarrayFcn ); // $ExpectError - dispatch( ndarrayFcn, types ); // $ExpectError - dispatch( ndarrayFcn, types, data ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, 1, 0 ); // $ExpectError -} - -// The function returns a dispatch function... -{ - const x = array(); - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const t1 = [ 'float64' ]; - const d1 = [ nullary ]; - const f1 = dispatch( ndarrayFcn, t1, d1, 1, 1, 0 ); - f1( x ); // $ExpectType void | ndarray - - const t2 = [ 'float64', 'float64' ]; - const d2 = [ unary ]; - const f2 = dispatch( ndarrayFcn, t2, d2, 2, 1, 1 ); - f2( x, y ); // $ExpectType void | ndarray - - const t3 = [ 'float64', 'float64', 'float64' ]; - const d3 = [ binary ]; - const f3 = dispatch( ndarrayFcn, t3, d3, 3, 2, 1 ); - f3( x, y, z ); // $ExpectType void | ndarray - - const t4 = [ 'float64', 'float64', 'float64', 'float64' ]; - const d4 = [ ternary ]; - const f4 = dispatch( ndarrayFcn, t4, d4, 4, 3, 1 ); - f4( x, y, z, w ); // $ExpectType void | ndarray - - const t5 = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const d5 = [ quaternary ]; - const f5 = dispatch( ndarrayFcn, t5, d5, 5, 4, 1 ); - f5( x, y, z, w, u ); // $ExpectType void | ndarray -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (1 ndarray)... -{ - const types = [ 'float64' ]; - const data = [ nullary ]; - - const f = dispatch( ndarrayFcn, types, data, 1, 0, 1 ); - f( '10' ); // $ExpectError - f( 10 ); // $ExpectError - f( true ); // $ExpectError - f( false ); // $ExpectError - f( null ); // $ExpectError - f( undefined ); // $ExpectError - f( [ '1' ] ); // $ExpectError - f( {} ); // $ExpectError - f( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( 10, y ); // $ExpectError - f( '10', y ); // $ExpectError - f( true, y ); // $ExpectError - f( false, y ); // $ExpectError - f( null, y ); // $ExpectError - f( undefined, y ); // $ExpectError - f( [ '1' ], y ); // $ExpectError - f( {}, y ); // $ExpectError - f( ( x: number ): number => x, y ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const x = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( x, 10 ); // $ExpectError - f( x, '10' ); // $ExpectError - f( x, true ); // $ExpectError - f( x, false ); // $ExpectError - f( x, null ); // $ExpectError - f( x, undefined ); // $ExpectError - f( x, [ '1' ] ); // $ExpectError - f( x, {} ); // $ExpectError - f( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( 10, y, z ); // $ExpectError - f( '10', y, z ); // $ExpectError - f( true, y, z ); // $ExpectError - f( false, y, z ); // $ExpectError - f( null, y, z ); // $ExpectError - f( undefined, y, z ); // $ExpectError - f( [ '1' ], y, z ); // $ExpectError - f( {}, y, z ); // $ExpectError - f( ( x: number ): number => x, y, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, 10, z ); // $ExpectError - f( x, '10', z ); // $ExpectError - f( x, true, z ); // $ExpectError - f( x, false, z ); // $ExpectError - f( x, null, z ); // $ExpectError - f( x, undefined, z ); // $ExpectError - f( x, [ '1' ], z ); // $ExpectError - f( x, {}, z ); // $ExpectError - f( x, ( x: number ): number => x, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, y, '10' ); // $ExpectError - f( x, y, true ); // $ExpectError - f( x, y, false ); // $ExpectError - f( x, y, null ); // $ExpectError - f( x, y, undefined ); // $ExpectError - f( x, y, [ '1' ] ); // $ExpectError - f( x, y, {} ); // $ExpectError - f( x, y, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( 10, y, z, w ); // $ExpectError - f( '10', y, z, w ); // $ExpectError - f( true, y, z, w ); // $ExpectError - f( false, y, z, w ); // $ExpectError - f( null, y, z, w ); // $ExpectError - f( undefined, y, z, w ); // $ExpectError - f( [ '1' ], y, z, w ); // $ExpectError - f( {}, y, z, w ); // $ExpectError - f( ( x: number ): number => x, y, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, 10, z, w ); // $ExpectError - f( x, '10', z, w ); // $ExpectError - f( x, true, z, w ); // $ExpectError - f( x, false, z, w ); // $ExpectError - f( x, null, z, w ); // $ExpectError - f( x, undefined, z, w ); // $ExpectError - f( x, [ '1' ], z, w ); // $ExpectError - f( x, {}, z, w ); // $ExpectError - f( x, ( x: number ): number => x, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, 10, w ); // $ExpectError - f( x, y, '10', w ); // $ExpectError - f( x, y, true, w ); // $ExpectError - f( x, y, false, w ); // $ExpectError - f( x, y, null, w ); // $ExpectError - f( x, y, undefined, w ); // $ExpectError - f( x, y, [ '1' ], w ); // $ExpectError - f( x, y, {}, w ); // $ExpectError - f( x, y, ( x: number ): number => x, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, z, 10 ); // $ExpectError - f( x, y, z, '10' ); // $ExpectError - f( x, y, z, true ); // $ExpectError - f( x, y, z, false ); // $ExpectError - f( x, y, z, null ); // $ExpectError - f( x, y, z, undefined ); // $ExpectError - f( x, y, z, [ '1' ] ); // $ExpectError - f( x, y, z, {} ); // $ExpectError - f( x, y, z, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( 10, y, z, w, u ); // $ExpectError - f( '10', y, z, w, u ); // $ExpectError - f( true, y, z, w, u ); // $ExpectError - f( false, y, z, w, u ); // $ExpectError - f( null, y, z, w, u ); // $ExpectError - f( undefined, y, z, w, u ); // $ExpectError - f( [ '1' ], y, z, w, u ); // $ExpectError - f( {}, y, z, w, u ); // $ExpectError - f( ( x: number ): number => x, y, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, 10, z, w, u ); // $ExpectError - f( x, '10', z, w, u ); // $ExpectError - f( x, true, z, w, u ); // $ExpectError - f( x, false, z, w, u ); // $ExpectError - f( x, null, z, w, u ); // $ExpectError - f( x, undefined, z, w, u ); // $ExpectError - f( x, [ '1' ], z, w, u ); // $ExpectError - f( x, {}, z, w, u ); // $ExpectError - f( x, ( x: number ): number => x, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, 10, w, u ); // $ExpectError - f( x, y, '10', w, u ); // $ExpectError - f( x, y, true, w, u ); // $ExpectError - f( x, y, false, w, u ); // $ExpectError - f( x, y, null, w, u ); // $ExpectError - f( x, y, undefined, w, u ); // $ExpectError - f( x, y, [ '1' ], w, u ); // $ExpectError - f( x, y, {}, w, u ); // $ExpectError - f( x, y, ( x: number ): number => x, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, 10, u ); // $ExpectError - f( x, y, z, '10', u ); // $ExpectError - f( x, y, z, true, u ); // $ExpectError - f( x, y, z, false, u ); // $ExpectError - f( x, y, z, null, u ); // $ExpectError - f( x, y, z, undefined, u ); // $ExpectError - f( x, y, z, [ '1' ], u ); // $ExpectError - f( x, y, z, {}, u ); // $ExpectError - f( x, y, z, ( x: number ): number => x, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fifth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, w, 10 ); // $ExpectError - f( x, y, z, w, '10' ); // $ExpectError - f( x, y, z, w, true ); // $ExpectError - f( x, y, z, w, false ); // $ExpectError - f( x, y, z, w, null ); // $ExpectError - f( x, y, z, w, undefined ); // $ExpectError - f( x, y, z, w, [ '1' ] ); // $ExpectError - f( x, y, z, w, {} ); // $ExpectError - f( x, y, z, w, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/add.js b/examples/add.js deleted file mode 100644 index 775b711..0000000 --- a/examples/add.js +++ /dev/null @@ -1,121 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var dispatch = require( './../lib' ); - -function add2( arrays ) { - var opts; - var xo; - var yo; - var zo; - var sx; - var sy; - var sz; - var sh; - var N; - var x; - var y; - var z; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - z = arrays[ 2 ]; - xo = x.order; - yo = y.order; - zo = z.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - opts.order = yo; - sy = ind2sub( sh, i, opts ); - v = x.get.apply( x, sx ) + y.get.apply( y, sy ); - - opts.order = zo; - sz = ind2sub( sh, i, opts ); - sz.push( v ); - z.set.apply( z, sz ); - } -} - -var fcns = [ - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2 -]; - -var types = [ - dtypes.float64, dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.int32, dtypes.int32, - dtypes.uint32, dtypes.uint32, dtypes.uint32, - dtypes.int16, dtypes.int16, dtypes.int16, - dtypes.uint16, dtypes.uint16, dtypes.uint16, - dtypes.int8, dtypes.int8, dtypes.int8, - dtypes.uint8, dtypes.uint8, dtypes.uint8, - dtypes.uint8c, dtypes.uint8c, dtypes.uint8c -]; - -var add = dispatch( fcns, types, null, 3, 2, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var zbuf = new Float64Array( xbuf.length ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var z = ndarray( 'float64', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); - -xbuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -ybuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -zbuf = new Int32Array( xbuf.length ); - -x = ndarray( 'int32', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'int32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -z = ndarray( 'int32', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); diff --git a/examples/sin.js b/examples/sin.js deleted file mode 100644 index 8cd4871..0000000 --- a/examples/sin.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int8Array = require( '@stdlib/array-int8' ); -var sin = require( '@stdlib/math-base-special-sin' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/strided-dtypes' ); -var dispatch = require( './../lib' ); - -function apply( arrays, fcn ) { - var opts; - var xo; - var yo; - var sx; - var sy; - var sh; - var N; - var x; - var y; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - xo = x.order; - yo = y.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - v = fcn( x.get.apply( x, sx ) ); - - opts.order = yo; - sy = ind2sub( sh, i, opts ); - sy.push( v ); - y.set.apply( y, sy ); - } -} - -var fcns = [ - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply -]; - -var types = [ - dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float64, - dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.float64, - dtypes.uint32, dtypes.float64, - dtypes.int16, dtypes.float64, - dtypes.int16, dtypes.float32, - dtypes.uint16, dtypes.float64, - dtypes.uint16, dtypes.float32, - dtypes.int8, dtypes.float64, - dtypes.int8, dtypes.float32, - dtypes.uint8, dtypes.float64, - dtypes.uint8, dtypes.float32, - dtypes.uint8c, dtypes.float64, - dtypes.uint8c, dtypes.float32 -]; - -var data = [ - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin -]; - -var sine = dispatch( fcns, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); - -xbuf = new Int8Array( [ 1, 2, 3, 4, 5 ] ); -ybuf = new Float32Array( xbuf.length ); - -x = ndarray( 'int8', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'float32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); diff --git a/examples/unary.js b/examples/unary.js deleted file mode 100644 index e9c3fb4..0000000 --- a/examples/unary.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -var unary = require( '@stdlib/ndarray-base-unary' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var dispatch = require( './../lib' ); - -var types = [ 'float64', 'float64' ]; - -var data = [ - abs -]; - -var absolute = dispatch( unary, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -absolute( x, y ); -console.log( ybuf ); -// => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 5f280a1..c49a4e4 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..ad38c4f --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@v0.2.1-esm/index.mjs";function m(m,f,l,p,w,v){var a,g,c;if(i(m))c=m;else if(!s(m))throw new TypeError(d("0jr5d",m));if(!n(f))throw new TypeError(d("0jr2y",f));if(!n(l)&&null!==l)throw new TypeError(d("0jr5e",l));if(!e(p))throw new TypeError(d("0jr5f",p));if(!r(w))throw new TypeError(d("0jr5X",w));if(!r(v))throw new TypeError(d("0jr5g",v));if(0===(a=w+v))throw new Error(d("0jr0h"));if(p!==a)throw new Error(d("0jr0i"));if(c){if(g=f.length/a,!t(g))throw new Error(d("0jr0j"))}else if(g=m.length,f.length!==g*a)throw new Error(d("0jr0j"));if(l&&l.length!==g)throw new Error(d("0jr0k"));return f=function(r){var e,t;for(e=[],t=0;t [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0jr5d', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0jr2y', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( '0jr5e', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0jr5f', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0jr5X', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0jr5g', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format('0jr0h') );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format('0jr0i') );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format('0jr0k') );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format('0jr0l') );\n\t\t\t}\n\t\t\tthrow new Error( format('0jr0m') );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( '0jr5h', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( '0jr5i', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format('0jr0n') );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found).\n*\n* ## Notes\n*\n* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types).\n* - The function assumes that `x` is stored in row-major order.\n* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`.\n* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value.\n*\n* @private\n* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension)\n* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension)\n* @param {ArrayLikeObject} x - input two-dimensional reference array\n* @param {integer} strideX1 - `x` stride length along first dimension\n* @param {integer} strideX2 - `x` stride length along second dimension\n* @param {NonNegativeInteger} offsetX - `x` starting index\n* @param {ArrayLikeObject} y - search array\n* @param {integer} strideY - `y` stride length\n* @param {NonNegativeInteger} offsetY - `y` starting index\n* @returns {integer} row index (if found) and `-1` otherwise\n*\n* @example\n* // Define a reference array to search:\n* var types = [\n* 'float64', 'float64', 'float64',\n* 'float32', 'float32', 'float32',\n* 'uint32', 'uint32', 'float64',\n* 'int32', 'int32', 'float64',\n* 'uint16', 'uint16', 'float64',\n* 'int16', 'int16', 'float64',\n* 'uint8', 'uint8', 'float64',\n* 'int8', 'int8', 'float64'\n* ];\n*\n* // Define reference array dimensions:\n* var N = 8; // rows\n* var M = 3; // columns\n*\n* // Define a search array:\n* y1 = [\n* 'float32', 'float32', 'float32',\n* ];\n*\n* // Find the list of types:\n* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 );\n* // returns 1\n*\n// Define a search array:\n* y2 = [\n* 'float32', 'float32', 'float64',\n* ];\n*\n* // Find the list of types:\n* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 );\n* // returns -1\n*/\nfunction indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len\n\tvar ix;\n\tvar iy;\n\tvar i;\n\tvar j;\n\n\t// Search for the first row which matches `y`...\n\tix = offsetX;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tiy = offsetY;\n\t\tfor ( j = 0; j < M; j++ ) {\n\t\t\tif ( x[ ix+(j*strideX2) ] !== y[ iy ] ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tiy += strideY;\n\t\t}\n\t\t// If we successfully iterated over all columns, then that means we've found a match...\n\t\tif ( j === M ) {\n\t\t\treturn i;\n\t\t}\n\t\tix += strideX1;\n\t}\n\treturn -1;\n}\n\n\n// EXPORTS //\n\nexport default indexOfTypes;\n"],"names":["dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","out","i","push","resolveEnum","types2enums","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","getDType","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","j","indexOfTypes","slice"],"mappings":";;0+BA0GA,SAASA,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAO,UAEzB,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAO,UAEzB,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAO,eAIzB,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAO,UAG1B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAO,UAGzB,OADAX,EA5GD,SAAsBA,GACrB,IAAIkB,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAInB,EAAMgB,OAAQG,IAC9BD,EAAIE,KAAMC,EAAarB,EAAOmB,KAE/B,OAAOD,CACR,CAmGSI,CAAatB,GAgBrB,WACC,IAAIuB,EACAC,EACAC,EACAC,EACAC,EACAC,EACAT,EAGJ,GADAM,EAAOI,UAAUb,OACZS,IAASvB,EAAQ,CACrB,GAAKuB,EAAOvB,EACX,MAAM,IAAIa,MAAOJ,EAAO,UAEzB,MAAM,IAAII,MAAOJ,EAAO,SACxB,CAGD,IAFAY,EAAS,GACTC,EAAS,GACHL,EAAI,EAAGA,EAAIjB,EAAOiB,IAAM,CAE7B,IAAMW,EADNH,EAAIE,UAAWV,IAEd,MAAKA,EAAIhB,EACF,IAAIO,UAAWC,EAAQ,QAASgB,IAEhC,IAAIjB,UAAWC,EAAQ,QAASgB,IAGxCJ,EAAOH,KAAMO,GACbH,EAAOJ,KAAMC,EAAaU,EAAUJ,IACpC,CAKD,IAHAD,EC1HF,SAAuBM,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAvB,EACAwB,EAIJ,IADAF,EAAKJ,EACClB,EAAI,EAAGA,EAAIa,EAAGb,IAAM,CAEzB,IADAuB,EAAKF,EACCG,EAAI,EAAGA,EAAIV,GACXC,EAAGO,EAAIE,EAAEP,KAAgBE,EAAGI,GADdC,IAInBD,GAAMH,EAGP,GAAKI,IAAMV,EACV,OAAOd,EAERsB,GAAMN,CACN,CACD,OAAQ,CACT,CDmGQS,CAActC,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGmB,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAId,UAAWC,EAAO,UAI5BiB,EADIrB,GAGAR,EAAM2B,GAGNzB,EACJ2B,EAAGL,EAAQtB,EAAMyB,IAEjBE,EAAGL,GAEJ,GAAc,IAATnB,EACJ,OAAOmB,EAAQlB,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOmB,EAAOsB,MAAO1C,EACrB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 88f0e3e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Create an ndarray function interface which performs multiple dispatch. -* -* @module @stdlib/ndarray-dispatch -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var dispatch = require( '@stdlib/ndarray-dispatch' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/index_of_types.js b/lib/index_of_types.js deleted file mode 100644 index fda2297..0000000 --- a/lib/index_of_types.js +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found). -* -* ## Notes -* -* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types). -* - The function assumes that `x` is stored in row-major order. -* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`. -* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value. -* -* @private -* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension) -* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension) -* @param {ArrayLikeObject} x - input two-dimensional reference array -* @param {integer} strideX1 - `x` stride length along first dimension -* @param {integer} strideX2 - `x` stride length along second dimension -* @param {NonNegativeInteger} offsetX - `x` starting index -* @param {ArrayLikeObject} y - search array -* @param {integer} strideY - `y` stride length -* @param {NonNegativeInteger} offsetY - `y` starting index -* @returns {integer} row index (if found) and `-1` otherwise -* -* @example -* // Define a reference array to search: -* var types = [ -* 'float64', 'float64', 'float64', -* 'float32', 'float32', 'float32', -* 'uint32', 'uint32', 'float64', -* 'int32', 'int32', 'float64', -* 'uint16', 'uint16', 'float64', -* 'int16', 'int16', 'float64', -* 'uint8', 'uint8', 'float64', -* 'int8', 'int8', 'float64' -* ]; -* -* // Define reference array dimensions: -* var N = 8; // rows -* var M = 3; // columns -* -* // Define a search array: -* y1 = [ -* 'float32', 'float32', 'float32', -* ]; -* -* // Find the list of types: -* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 ); -* // returns 1 -* -// Define a search array: -* y2 = [ -* 'float32', 'float32', 'float64', -* ]; -* -* // Find the list of types: -* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 ); -* // returns -1 -*/ -function indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len - var ix; - var iy; - var i; - var j; - - // Search for the first row which matches `y`... - ix = offsetX; - for ( i = 0; i < N; i++ ) { - iy = offsetY; - for ( j = 0; j < M; j++ ) { - if ( x[ ix+(j*strideX2) ] !== y[ iy ] ) { - break; - } - iy += strideY; - } - // If we successfully iterated over all columns, then that means we've found a match... - if ( j === M ) { - return i; - } - ix += strideX1; - } - return -1; -} - - -// EXPORTS // - -module.exports = indexOfTypes; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4648598..0000000 --- a/lib/main.js +++ /dev/null @@ -1,231 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isFunctionArray = require( '@stdlib/assert-is-function-array' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var resolveEnum = require( '@stdlib/ndarray-base-dtype-resolve-enum' ); -var indexOfTypes = require( './index_of_types.js' ); - - -// FUNCTIONS // - -/** -* Returns a list of data type enumeration constants. -* -* @private -* @param {Collection} types - list of types -* @returns {IntegerArray} list of data type enumeration constants -*/ -function types2enums( types ) { - var out; - var i; - - out = []; - for ( i = 0; i < types.length; i++ ) { - out.push( resolveEnum( types[ i ] ) ); - } - return out; -} - - -// MAIN // - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param {(FunctionArray|Function)} fcns - list of ndarray functions -* @param {Collection} types - one-dimensional list of ndarray argument data types -* @param {(Collection|null)} data - ndarray function data (e.g., callbacks) -* @param {PositiveInteger} nargs - total number of ndarray function interface arguments -* @param {NonNegativeInteger} nin - number of input ndarrays -* @param {NonNegativeInteger} nout - number of output ndarrays -* @throws {TypeError} first argument must be either a function or an array of functions -* @throws {TypeError} second argument must be an array-like object -* @throws {TypeError} third argument must be an array-like object or `null` -* @throws {Error} third and first arguments must have the same number of elements -* @throws {TypeError} fourth argument must be a positive integer -* @throws {TypeError} fifth argument must be a nonnegative integer -* @throws {TypeError} sixth argument must be a nonnegative integer -* @throws {Error} fourth argument must equal the specified number of input and output arrays -* @throws {Error} number of types must match the number of functions times the total number of array arguments for each function -* @throws {Error} interface must accept at least one input and/or output ndarray -* @returns {Function} ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function dispatch( fcns, types, data, nargs, nin, nout ) { - var narrays; - var nfcns; - var fcn; - - if ( isFunction( fcns ) ) { - fcn = fcns; - } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( '0jr5d', fcns ) ); - } - if ( !isCollection( types ) ) { - throw new TypeError( format( '0jr2y', types ) ); - } - if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( '0jr5e', data ) ); - } - if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( '0jr5f', nargs ) ); - } - if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( '0jr5X', nin ) ); - } - if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( '0jr5g', nout ) ); - } - narrays = nin + nout; - if ( narrays === 0 ) { - throw new Error( format('0jr0h') ); - } - if ( nargs !== narrays ) { - throw new Error( format('0jr0i') ); - } - if ( fcn ) { - nfcns = types.length / narrays; - if ( !isInteger( nfcns ) ) { - throw new Error( format('0jr0j') ); - } - } else { - nfcns = fcns.length; - if ( types.length !== nfcns*narrays ) { - throw new Error( format('0jr0j') ); - } - } - if ( data && data.length !== nfcns ) { - throw new Error( format('0jr0k') ); - } - types = types2enums( types ); - return dispatcher; - - /** - * ndarray function interface which performs multiple dispatch. - * - * @private - * @param {ndarrayLike} x - ndarray - * @param {...ndarrayLike} args - ndarray arguments - * @throws {Error} insufficient arguments - * @throws {Error} too many arguments - * @throws {TypeError} input array arguments must be ndarray-like objects - * @throws {TypeError} output array arguments must be ndarray-like objects - * @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types - * @returns {(ndarrayLike|Array|void)} destination array(s) - */ - function dispatcher() { - var arrays; - var dtypes; - var argc; - var idx; - var v; - var f; - var i; - - argc = arguments.length; - if ( argc !== nargs ) { - if ( argc < nargs ) { - throw new Error( format('0jr0l') ); - } - throw new Error( format('0jr0m') ); - } - arrays = []; - dtypes = []; - for ( i = 0; i < nargs; i++ ) { - v = arguments[ i ]; - if ( !isndarrayLike( v ) ) { - if ( i < nin ) { - throw new TypeError( format( '0jr5h', v ) ); - } else { - throw new TypeError( format( '0jr5i', v ) ); - } - } - arrays.push( v ); - dtypes.push( resolveEnum( getDType( v ) ) ); - } - // Resolve the ndarray function satisfying the input array types: - idx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len - - // Check whether we were able to successfully resolve an ndarray function: - if ( idx < 0 ) { - throw new TypeError( format('0jr0n') ); - } - // Retrieve the ndarray function: - if ( fcn ) { - f = fcn; - } else { - f = fcns[ idx ]; - } - // Evaluate the ndarray function: - if ( data ) { - f( arrays, data[ idx ] ); - } else { - f( arrays ); - } - if ( nout === 1 ) { - return arrays[ narrays-1 ]; - } - if ( nout === 0 ) { - return; - } - return arrays.slice( nin ); - } -} - - -// EXPORTS // - -module.exports = dispatch; diff --git a/package.json b/package.json index d66c7e4..ffe4f55 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Create an ndarray function interface which performs multiple dispatch.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,57 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-collection": "^0.2.1", - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/assert-is-function-array": "^0.2.1", - "@stdlib/assert-is-integer": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/assert-is-nonnegative-integer": "^0.2.1", - "@stdlib/assert-is-positive-integer": "^0.2.1", - "@stdlib/ndarray-base-dtype-resolve-enum": "^0.2.1", - "@stdlib/ndarray-dtype": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.2.1", - "@stdlib/array-float64": "^0.2.1", - "@stdlib/array-int32": "^0.2.1", - "@stdlib/array-int8": "^0.2.1", - "@stdlib/array-uint8": "^0.2.1", - "@stdlib/math-base-assert-is-nan": "^0.2.1", - "@stdlib/math-base-special-abs": "^0.2.1", - "@stdlib/math-base-special-pow": "^0.2.1", - "@stdlib/math-base-special-sin": "^0.2.1", - "@stdlib/ndarray-base-buffer-dtype": "^0.2.1", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-base-unary": "^0.2.1", - "@stdlib/ndarray-ctor": "^0.2.1", - "@stdlib/ndarray-dtypes": "^0.2.1", - "@stdlib/ndarray-ind2sub": "^0.2.1", - "@stdlib/strided-dtypes": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "ndarray", @@ -100,7 +26,6 @@ "multimethod", "multimethods" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..f1e9034 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/fixtures/binary.js b/test/fixtures/binary.js deleted file mode 100644 index a60dfa2..0000000 --- a/test/fixtures/binary.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Binary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @returns {number} sum -*/ -function binary( x, y ) { - return x + y; -} - - -// EXPORTS // - -module.exports = binary; diff --git a/test/fixtures/fill.js b/test/fixtures/fill.js deleted file mode 100644 index 41b2958..0000000 --- a/test/fixtures/fill.js +++ /dev/null @@ -1,76 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which fills one or more ndarrays. -* -* @private -* @param {*} value - fill value -* @returns {Function} ndarray function -*/ -function fill( value ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - */ - function ndarrayFcn( arrays ) { - var opts; - var sub; - var arr; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - opts = { - 'order': '' - }; - for ( j = 0; j < M; j++ ) { - arr = arrays[ j ]; - opts.order = arrays[ j ].order; - for ( i = 0; i < N; i++ ) { - sub = ind2sub( sh, i, opts ); - sub.push( value ); - arr.set.apply( arr, sub ); - } - } - } -} - - -// EXPORTS // - -module.exports = fill; diff --git a/test/fixtures/foreach.js b/test/fixtures/foreach.js deleted file mode 100644 index a426290..0000000 --- a/test/fixtures/foreach.js +++ /dev/null @@ -1,72 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function forEach( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - fcn.apply( null, args ); - } -} - - -// EXPORTS // - -module.exports = forEach; diff --git a/test/fixtures/map1n.js b/test/fixtures/map1n.js deleted file mode 100644 index 614196b..0000000 --- a/test/fixtures/map1n.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function which maps the return value of a callback to `N` arrays. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function map1N( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var v; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - v = fcn(); - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - sub.push( v ); - arrays[ j ].set.apply( arrays[ j ], sub ); - } - } -} - - -// EXPORTS // - -module.exports = map1N; diff --git a/test/fixtures/nullary.js b/test/fixtures/nullary.js deleted file mode 100644 index 4f22126..0000000 --- a/test/fixtures/nullary.js +++ /dev/null @@ -1,36 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Nullary callback. -* -* @private -* @returns {number} value -*/ -function nullary() { - return 3.0; -} - - -// EXPORTS // - -module.exports = nullary; diff --git a/test/fixtures/quaternary.js b/test/fixtures/quaternary.js deleted file mode 100644 index 548437b..0000000 --- a/test/fixtures/quaternary.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quaternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @returns {number} sum -*/ -function quaternary( x, y, z, w ) { - return x + y + z + w; -} - - -// EXPORTS // - -module.exports = quaternary; diff --git a/test/fixtures/quinary.js b/test/fixtures/quinary.js deleted file mode 100644 index 36068de..0000000 --- a/test/fixtures/quinary.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quinary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @param {number} u - input value -* @returns {number} sum -*/ -function quinary( x, y, z, w, u ) { - return x + y + z + w + u; -} - - -// EXPORTS // - -module.exports = quinary; diff --git a/test/fixtures/sum.js b/test/fixtures/sum.js deleted file mode 100644 index efdbb1b..0000000 --- a/test/fixtures/sum.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which computes the sum across one or more ndarrays. -* -* @private -* @param {Object} ctx - context -* @param {number} ctx.sum - initial sum -* @returns {Function} ndarray function -*/ -function wrapper( ctx ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - * @param {Function} [fcn] - callback - */ - function ndarrayFcn( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var f; - var i; - var j; - - if ( arguments.length > 1 ) { - f = fcn; - } - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - if ( f ) { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - ctx.sum += f.apply( null, args ); - } - } else { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - ctx.sum += arrays[ j ].get.apply( arrays[ j ], sub ); - } - } - } - } -} - - -// EXPORTS // - -module.exports = wrapper; diff --git a/test/fixtures/ternary.js b/test/fixtures/ternary.js deleted file mode 100644 index 0595d5f..0000000 --- a/test/fixtures/ternary.js +++ /dev/null @@ -1,39 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Ternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @returns {number} sum -*/ -function ternary( x, y, z ) { - return x + y + z; -} - - -// EXPORTS // - -module.exports = ternary; diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d6c2c8e..0000000 --- a/test/test.js +++ /dev/null @@ -1,363 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var fill = require( './fixtures/fill.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either a function or an array of functions as a first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( value, types, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object as a second argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided either an array-like object or `null` as a third argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - dispatch( unary, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a positive integer for a fourth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 0, - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a fifth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, value, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a sixth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, 1, value ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function array)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var fcns = [ unary, unary, unary ]; - var data = [ abs, abs, abs ]; - dispatch( fcns, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function argument)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs, abs, abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the length of `data` argument does not match the number of ndarray functions', function test( t ) { - var values; - var i; - - values = [ - [], - [ abs, abs ], - [ abs, abs, abs ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var fcns = [ unary ]; - dispatch( fcns, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the fourth argument is incompatible with the number of input and output ndarrays', function test( t ) { - var values; - var i; - - values = [ - 0, - 1, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of specified input and output ndarrays is zero', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var types = [ 'float64' ]; - dispatch( fill( 3 ), types, null, 1, 0, 0 ); - } -}); - -tape( 'the function returns an ndarray function interface', function test( t ) { - var types; - var data; - var f; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - f = dispatch( unary, types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ unary ], types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( fill( 3 ), types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ fill( 3 ) ], types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.two_arrays.js b/test/test.two_arrays.js deleted file mode 100644 index 16eb61b..0000000 --- a/test/test.two_arrays.js +++ /dev/null @@ -1,814 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var dtype = require( '@stdlib/ndarray-base-buffer-dtype' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var forEach = require( './fixtures/foreach.js' ); -var map1N = require( './fixtures/map1n.js' ); -var fill = require( './fixtures/fill.js' ); -var sum = require( './fixtures/sum.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the first argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var ybuf = new Float64Array( 10 ); - var y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( value, y ); - }; - } -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the second argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var xbuf = new Float64Array( 10 ); - var x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( x, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided insufficient arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var f; - var x; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [], - [ x ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided too many arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var ybuf; - var f; - var x; - var y; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [ x, y, y ], - [ x, y, y, y ], - [ x, y, y, y, y ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if unable to resolve a ndarray function supporting the provided array argument data types', function test( t ) { - var values; - var types; - var data; - var xbuf; - var fcn; - var x; - var i; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ abs, abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 4 ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - values = [ - new Uint8Array( 4 ), - new Int32Array( 4 ), - [ 0, 0, 0, 0 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided an array having data type: ' + dtype( values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var y = ndarray( dtype( value ), value, [ value.length ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - }; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only input arrays)', function test( t ) { - var types; - var xbuf; - var ybuf; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only output arrays)', function test( t ) { - var expected; - var types; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only input arrays)', function test( t ) { - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var ctx; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcns = [ - sum( ctx ), - sum( ctx ) - ]; - fcn = dispatch( fcns, types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only output arrays)', function test( t ) { - var expected; - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcns = [ - fill( 3.0 ), - fill( 4.0 ) - ]; - fcn = dispatch( fcns, types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - - fcn = dispatch( forEach, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - - fcn = dispatch( map1N, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - fcns = [ - forEach, - forEach - ]; - fcn = dispatch( fcns, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - fcns = [ - map1N, - map1N - ]; - fcn = dispatch( fcns, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - fcns = [ - unary, - unary - ]; - fcn = dispatch( fcns, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which returns one or more output arrays, if one or more output arrays is specified, and otherwise returns `undefined`', function test( t ) { - var types; - var data; - var xbuf; - var ybuf; - var out; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - // No output arrays... - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, void 0, 'returns expected value' ); - - // One output array... - data = [ - abs, - abs - ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - fcn = dispatch( fill( 3.0 ), types, null, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - // Two output arrays... - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.end(); -}); From bf02bc0ee9838780e2c0770c5e4ada3b86e38e82 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 03:24:00 +0000 Subject: [PATCH 081/109] Transform error messages --- lib/main.js | 34 +++++++++++++++++----------------- package.json | 2 +- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/main.js b/lib/main.js index 5f4bb5d..4648598 100644 --- a/lib/main.js +++ b/lib/main.js @@ -27,7 +27,7 @@ var isFunctionArray = require( '@stdlib/assert-is-function-array' ); var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var getDType = require( '@stdlib/ndarray-dtype' ); var resolveEnum = require( '@stdlib/ndarray-base-dtype-resolve-enum' ); var indexOfTypes = require( './index_of_types.js' ); @@ -112,43 +112,43 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { if ( isFunction( fcns ) ) { fcn = fcns; } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) ); + throw new TypeError( format( '0jr5d', fcns ) ); } if ( !isCollection( types ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) ); + throw new TypeError( format( '0jr2y', types ) ); } if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); + throw new TypeError( format( '0jr5e', data ) ); } if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) ); + throw new TypeError( format( '0jr5f', nargs ) ); } if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) ); + throw new TypeError( format( '0jr5X', nin ) ); } if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) ); + throw new TypeError( format( '0jr5g', nout ) ); } narrays = nin + nout; if ( narrays === 0 ) { - throw new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' ); + throw new Error( format('0jr0h') ); } if ( nargs !== narrays ) { - throw new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' ); + throw new Error( format('0jr0i') ); } if ( fcn ) { nfcns = types.length / narrays; if ( !isInteger( nfcns ) ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format('0jr0j') ); } } else { nfcns = fcns.length; if ( types.length !== nfcns*narrays ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format('0jr0j') ); } } if ( data && data.length !== nfcns ) { - throw new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' ); + throw new Error( format('0jr0k') ); } types = types2enums( types ); return dispatcher; @@ -178,9 +178,9 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { argc = arguments.length; if ( argc !== nargs ) { if ( argc < nargs ) { - throw new Error( 'invalid invocation. Insufficient arguments.' ); + throw new Error( format('0jr0l') ); } - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('0jr0m') ); } arrays = []; dtypes = []; @@ -188,9 +188,9 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { v = arguments[ i ]; if ( !isndarrayLike( v ) ) { if ( i < nin ) { - throw new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) ); + throw new TypeError( format( '0jr5h', v ) ); } else { - throw new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) ); + throw new TypeError( format( '0jr5i', v ) ); } } arrays.push( v ); @@ -201,7 +201,7 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { // Check whether we were able to successfully resolve an ndarray function: if ( idx < 0 ) { - throw new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' ); + throw new TypeError( format('0jr0n') ); } // Retrieve the ndarray function: if ( fcn ) { diff --git a/package.json b/package.json index d805c2e..4dfd645 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/assert-is-positive-integer": "^0.2.2", "@stdlib/ndarray-base-dtype-resolve-enum": "^0.2.2", "@stdlib/ndarray-dtype": "^0.2.1", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.3.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 1c267b87c55b713431248ebd528230cf86358891 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 03:48:14 +0000 Subject: [PATCH 082/109] Remove files --- index.d.ts | 334 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5181 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index c49a4e4..0000000 --- a/index.d.ts +++ /dev/null @@ -1,334 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* ndarray function. -* -* @param arrays - array containing input and output ndarrays -* @param data - ndarray function data (e.g., a callback) -* -* @example -* var numel = require( '@stdlib/ndarray-base-numel' ); -* var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -* -* function ndarrayFcn( arrays, fcn ) { -* var xord; -* var yord; -* var opts; -* var sub; -* var sh; -* var N; -* var x; -* var y; -* var v; -* var i; -* -* x = arrays[ 0 ]; -* y = arrays[ 1 ]; -* sh = x.shape; -* N = numel( sh ); -* if ( N <= 0 ) { -* return; -* } -* xord = x.order; -* yord = y.order; -* opts = {}; -* opts.order = xord; -* for ( i = 0; i < N; i++ ) { -* // Convert a linear index to subscripts: -* opts.order = xord; -* sub = ind2sub( sh, i, opts ); -* -* // Retrieve an element from `x`: -* v = x.get.apply( x, sub ); -* -* // Convert a linear index to subscripts: -* opts.order = yord; -* sub = ind2sub( sh, i, opts ); -* -* // Append the result of applying the callback: -* sub.push( fcn( v ) ); -* -* // Assign the result to an element in `y`: -* y.set.apply( y, sub ); -* } -* } -*/ -type ndarrayFcn = ( arrays: Array, data?: any ) => void; - -/** -* Interface describing an ndarray function dispatcher. -*/ -interface Dispatcher { - /** - * Invokes an ndarray function based on the provided array data type(s). - * - * @param x - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array - * - * @example - * var nullary = require( '@stdlib/ndarray-base-nullary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function value() { - * return 3.14; - * } - * - * var types = [ 'float64' ]; - * var data = [ value ]; - * - * var fcn = dispatch( nullary, types, data, 1, 0, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( 5 ); - * var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x ); - * // xbuf => [ 3.14, 3.14, 3.14, 3.14, 3.14 ] - */ - ( x: ndarray ): ndarray | void; - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var unary = require( '@stdlib/ndarray-base-unary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * var abs = require( '@stdlib/math-base-special-abs' ); - * - * var types = [ 'float64', 'float64' ]; - * var data = [ abs ]; - * - * var fcn = dispatch( unary, types, data, 2, 1, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - * var ybuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y ); - * // ybuf => [ 1.0, 2.0, 3.0 ] - */ - ( x: ndarray, y: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var ternary = require( '@stdlib/ndarray-base-ternary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function add2( x, y ) { - * return x + y; - * } - * - * var types = [ 'float64', 'float64', 'float64' ]; - * var data = [ add2 ]; - * - * var fcn = dispatch( ternary, types, data, 3, 2, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z ); - * // zbuf => [ 2.0, 4.0, 6.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quaternary = require( '@stdlib/ndarray-base-quaternary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function add3( x, y, z ) { - * return x + y + z; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add3 ]; - * - * var fcn = dispatch( quaternary, types, data, 4, 3, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w ); - * // wbuf => [ 3.0, 6.0, 9.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @param args - ndarray arguments - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quinary = require( '@stdlib/ndarray-base-quinary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function add4( x, y, z, w ) { - * return x + y + z + w; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add4 ]; - * - * var fcn = dispatch( quinary, types, data, 5, 4, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ubuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var u = ndarray( 'float64', ubuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w, u ); - * // ubuf => [ 4.0, 8.0, 12.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray, ...args: Array ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures -} - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param fcns - list of ndarray functions -* @param types - one-dimensional list of ndarray argument data types -* @param data - ndarray function data (e.g., callbacks) -* @param nargs - total number of ndarray function interface arguments -* @param nin - number of input ndarrays -* @param nout - number of output ndarrays -* @throws first argument must be either a function or an array of functions -* @throws second argument must be an array-like object -* @throws third argument must be an array-like object or `null` -* @throws third and first arguments must have the same number of elements -* @throws fourth argument must be a positive integer -* @throws fifth argument must be a nonnegative integer -* @throws sixth argument must be a nonnegative integer -* @throws fourth argument must equal the specified number of input and output arrays -* @throws number of types must match the number of functions times the total number of array arguments for each function -* @throws interface must accept at least one input and/or output ndarray -* @returns ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var fcn = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* fcn( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function dispatch( fcns: ndarrayFcn | ArrayLike, types: ArrayLike, data: ArrayLike | null, nargs: number, nin: number, nout: number ): Dispatcher; - - -// EXPORTS // - -export = dispatch; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index ad38c4f..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.1-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@v0.2.1-esm/index.mjs";function m(m,f,l,p,w,v){var a,g,c;if(i(m))c=m;else if(!s(m))throw new TypeError(d("0jr5d",m));if(!n(f))throw new TypeError(d("0jr2y",f));if(!n(l)&&null!==l)throw new TypeError(d("0jr5e",l));if(!e(p))throw new TypeError(d("0jr5f",p));if(!r(w))throw new TypeError(d("0jr5X",w));if(!r(v))throw new TypeError(d("0jr5g",v));if(0===(a=w+v))throw new Error(d("0jr0h"));if(p!==a)throw new Error(d("0jr0i"));if(c){if(g=f.length/a,!t(g))throw new Error(d("0jr0j"))}else if(g=m.length,f.length!==g*a)throw new Error(d("0jr0j"));if(l&&l.length!==g)throw new Error(d("0jr0k"));return f=function(r){var e,t;for(e=[],t=0;t [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0jr5d', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0jr2y', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( '0jr5e', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0jr5f', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0jr5X', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0jr5g', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format('0jr0h') );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format('0jr0i') );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format('0jr0k') );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format('0jr0l') );\n\t\t\t}\n\t\t\tthrow new Error( format('0jr0m') );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( '0jr5h', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( '0jr5i', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format('0jr0n') );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found).\n*\n* ## Notes\n*\n* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types).\n* - The function assumes that `x` is stored in row-major order.\n* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`.\n* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value.\n*\n* @private\n* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension)\n* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension)\n* @param {ArrayLikeObject} x - input two-dimensional reference array\n* @param {integer} strideX1 - `x` stride length along first dimension\n* @param {integer} strideX2 - `x` stride length along second dimension\n* @param {NonNegativeInteger} offsetX - `x` starting index\n* @param {ArrayLikeObject} y - search array\n* @param {integer} strideY - `y` stride length\n* @param {NonNegativeInteger} offsetY - `y` starting index\n* @returns {integer} row index (if found) and `-1` otherwise\n*\n* @example\n* // Define a reference array to search:\n* var types = [\n* 'float64', 'float64', 'float64',\n* 'float32', 'float32', 'float32',\n* 'uint32', 'uint32', 'float64',\n* 'int32', 'int32', 'float64',\n* 'uint16', 'uint16', 'float64',\n* 'int16', 'int16', 'float64',\n* 'uint8', 'uint8', 'float64',\n* 'int8', 'int8', 'float64'\n* ];\n*\n* // Define reference array dimensions:\n* var N = 8; // rows\n* var M = 3; // columns\n*\n* // Define a search array:\n* y1 = [\n* 'float32', 'float32', 'float32',\n* ];\n*\n* // Find the list of types:\n* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 );\n* // returns 1\n*\n// Define a search array:\n* y2 = [\n* 'float32', 'float32', 'float64',\n* ];\n*\n* // Find the list of types:\n* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 );\n* // returns -1\n*/\nfunction indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len\n\tvar ix;\n\tvar iy;\n\tvar i;\n\tvar j;\n\n\t// Search for the first row which matches `y`...\n\tix = offsetX;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tiy = offsetY;\n\t\tfor ( j = 0; j < M; j++ ) {\n\t\t\tif ( x[ ix+(j*strideX2) ] !== y[ iy ] ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tiy += strideY;\n\t\t}\n\t\t// If we successfully iterated over all columns, then that means we've found a match...\n\t\tif ( j === M ) {\n\t\t\treturn i;\n\t\t}\n\t\tix += strideX1;\n\t}\n\treturn -1;\n}\n\n\n// EXPORTS //\n\nexport default indexOfTypes;\n"],"names":["dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","out","i","push","resolveEnum","types2enums","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","getDType","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","j","indexOfTypes","slice"],"mappings":";;0+BA0GA,SAASA,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAO,UAEzB,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAO,UAEzB,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAO,eAIzB,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAO,UAG1B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAO,UAGzB,OADAX,EA5GD,SAAsBA,GACrB,IAAIkB,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAInB,EAAMgB,OAAQG,IAC9BD,EAAIE,KAAMC,EAAarB,EAAOmB,KAE/B,OAAOD,CACR,CAmGSI,CAAatB,GAgBrB,WACC,IAAIuB,EACAC,EACAC,EACAC,EACAC,EACAC,EACAT,EAGJ,GADAM,EAAOI,UAAUb,OACZS,IAASvB,EAAQ,CACrB,GAAKuB,EAAOvB,EACX,MAAM,IAAIa,MAAOJ,EAAO,UAEzB,MAAM,IAAII,MAAOJ,EAAO,SACxB,CAGD,IAFAY,EAAS,GACTC,EAAS,GACHL,EAAI,EAAGA,EAAIjB,EAAOiB,IAAM,CAE7B,IAAMW,EADNH,EAAIE,UAAWV,IAEd,MAAKA,EAAIhB,EACF,IAAIO,UAAWC,EAAQ,QAASgB,IAEhC,IAAIjB,UAAWC,EAAQ,QAASgB,IAGxCJ,EAAOH,KAAMO,GACbH,EAAOJ,KAAMC,EAAaU,EAAUJ,IACpC,CAKD,IAHAD,EC1HF,SAAuBM,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAvB,EACAwB,EAIJ,IADAF,EAAKJ,EACClB,EAAI,EAAGA,EAAIa,EAAGb,IAAM,CAEzB,IADAuB,EAAKF,EACCG,EAAI,EAAGA,EAAIV,GACXC,EAAGO,EAAIE,EAAEP,KAAgBE,EAAGI,GADdC,IAInBD,GAAMH,EAGP,GAAKI,IAAMV,EACV,OAAOd,EAERsB,GAAMN,CACN,CACD,OAAQ,CACT,CDmGQS,CAActC,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGmB,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAId,UAAWC,EAAO,UAI5BiB,EADIrB,GAGAR,EAAM2B,GAGNzB,EACJ2B,EAAGL,EAAQtB,EAAMyB,IAEjBE,EAAGL,GAEJ,GAAc,IAATnB,EACJ,OAAOmB,EAAQlB,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOmB,EAAOsB,MAAO1C,EACrB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index f1e9034..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 4cc2e95211cb8b71817edf9f00b214dd09523446 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 03:48:31 +0000 Subject: [PATCH 083/109] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 222 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 61 +- SECURITY.md | 5 - benchmark/benchmark.dispatch_size.js | 156 - benchmark/benchmark.js | 81 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 87 - docs/types/test.ts | 641 --- examples/add.js | 121 - examples/sin.js | 142 - examples/unary.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/index_of_types.js | 106 - lib/main.js | 231 - package.json | 79 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/binary.js | 38 - test/fixtures/fill.js | 76 - test/fixtures/foreach.js | 72 - test/fixtures/map1n.js | 74 - test/fixtures/nullary.js | 36 - test/fixtures/quaternary.js | 40 - test/fixtures/quinary.js | 41 - test/fixtures/sum.js | 98 - test/fixtures/ternary.js | 39 - test/test.js | 363 -- test/test.two_arrays.js | 814 ---- 56 files changed, 4876 insertions(+), 6994 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.dispatch_size.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/add.js delete mode 100644 examples/sin.js delete mode 100644 examples/unary.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/index_of_types.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/fixtures/binary.js delete mode 100644 test/fixtures/fill.js delete mode 100644 test/fixtures/foreach.js delete mode 100644 test/fixtures/map1n.js delete mode 100644 test/fixtures/nullary.js delete mode 100644 test/fixtures/quaternary.js delete mode 100644 test/fixtures/quinary.js delete mode 100644 test/fixtures/sum.js delete mode 100644 test/fixtures/ternary.js delete mode 100644 test/test.js delete mode 100644 test/test.two_arrays.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ac0b7cd..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 5e92c3e..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2b4fac7..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '43 7 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -304,7 +295,7 @@ console.log( ybuf ); ## 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. +This package is part of [stdlib][stdlib], a standard library 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]. @@ -367,11 +358,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-dispatch/main/LICENSE -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.dispatch_size.js b/benchmark/benchmark.dispatch_size.js deleted file mode 100644 index 15805ba..0000000 --- a/benchmark/benchmark.dispatch_size.js +++ /dev/null @@ -1,156 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib/main.js' ); - - -// FUNCTIONS // - -/** -* Evaluates the identity function. -* -* @private -* @param {*} v - value -* @returns {*} input value -*/ -function identity( v ) { - return v; -} - -/** -* Dummy function which throws an error. -* -* @private -* @throws {Error} unexpected error -*/ -function throwError() { - throw new Error( 'unexpected error' ); -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} size - dispatch size -* @returns {Function} benchmark function -*/ -function createBenchmark( size ) { - var types; - var data; - var fcn; - var x; - var y; - var t; - var i; - - types = []; - - // Create dummy types... - for ( i = 0; i < (size-1)*2; i += 2 ) { - t = 'foo' + i; - types.push( t ); - types.push( t ); - } - // Append test types: - types.push( 'float64' ); - types.push( 'float64' ); - - // Define a list of callbacks: - data = []; - for ( i = 0; i < size-1; i++ ) { - data.push( throwError ); - } - // Append a test callback: - data.push( identity ); - - // Create the dispatcher: - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - // Create sample arrays: - x = new Float64Array( 1 ); - y = new Float64Array( x.length ); - - x = ndarray( 'float64', x, [ 1 ], [ 1 ], 0, 'row-major' ); - y = ndarray( 'float64', y, [ 1 ], [ 1 ], 0, 'row-major' ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var z; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x.data[ 0 ] = i; - z = fcn( x, y ); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var size; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - size = pow( 2, i ); - f = createBenchmark( size ); - bench( pkg+':size='+size, f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 3c6f450..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::fcns_array', function benchmark( b ) { - var types; - var fcns; - var data; - var out; - var i; - - fcns = [ unary ]; - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( fcns, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::fcn_arg', function benchmark( b ) { - var types; - var data; - var out; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( unary, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0aae4af..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch" -%% click B href "https://github.com/stdlib-js/ndarray-dispatch/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-dispatch/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-dispatch/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-dispatch/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-dispatch/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch -[production-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 1295a44..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import dispatch from '../docs/types/index'; -export = dispatch; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c23dc5d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var y=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var b=y(function(D,w){"use strict";function k(i,r,e,u,f,m,n,o,l){var h,t,s,a;for(h=m,s=0;s [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( 'invalid invocation. Insufficient arguments.' );\n\t\t\t}\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = dispatch;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an ndarray function interface which performs multiple dispatch.\n*\n* @module @stdlib/ndarray-dispatch\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var unary = require( '@stdlib/ndarray-base-unary' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var Float64Array = require( '@stdlib/array-float64' );\n* var dispatch = require( '@stdlib/ndarray-dispatch' );\n*\n* var types = [\n* 'float64', 'float64'\n* ];\n*\n* var data = [\n* abs\n* ];\n*\n* var absolute = dispatch( unary, types, data, 2, 1, 1 );\n*\n* // ...\n*\n* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] );\n* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] );\n*\n* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' );\n* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' );\n*\n* absolute( x, y );\n* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA6EA,SAASC,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,EAAU,CAClF,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,CAAU,IAAME,EAAGI,CAAG,EADjBE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,CACP,CACA,MAAO,EACR,CAKAL,EAAO,QAAUC,ICzGjB,IAAAc,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAoB,QAAS,oCAAqC,EAClEC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAkB,QAAS,kCAAmC,EAC9DC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAc,QAAS,yCAA0C,EACjEC,EAAe,IAYnB,SAASC,EAAaC,EAAQ,CAC7B,IAAIC,EACAC,EAGJ,IADAD,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIF,EAAM,OAAQE,IAC9BD,EAAI,KAAMJ,EAAaG,EAAOE,CAAE,CAAE,CAAE,EAErC,OAAOD,CACR,CAqDA,SAASE,EAAUC,EAAMJ,EAAOK,EAAMC,EAAOC,EAAKC,EAAO,CACxD,IAAIC,EACAC,EACAC,EAEJ,GAAKnB,EAAYY,CAAK,EACrBO,EAAMP,UACK,CAACb,EAAiBa,CAAK,EAClC,MAAM,IAAI,UAAWT,EAAQ,oGAAqGS,CAAK,CAAE,EAE1I,GAAK,CAACX,EAAcO,CAAM,EACzB,MAAM,IAAI,UAAWL,EAAQ,+EAAgFK,CAAM,CAAE,EAEtH,GAAK,CAACP,EAAcY,CAAK,GAAKA,IAAS,KACtC,MAAM,IAAI,UAAWV,EAAQ,sFAAuFU,CAAK,CAAE,EAE5H,GAAK,CAAChB,EAAmBiB,CAAM,EAC9B,MAAM,IAAI,UAAWX,EAAQ,6EAA8EW,CAAM,CAAE,EAEpH,GAAK,CAAClB,EAAsBmB,CAAI,EAC/B,MAAM,IAAI,UAAWZ,EAAQ,+EAAgFY,CAAI,CAAE,EAEpH,GAAK,CAACnB,EAAsBoB,CAAK,EAChC,MAAM,IAAI,UAAWb,EAAQ,+EAAgFa,CAAK,CAAE,EAGrH,GADAC,EAAUF,EAAMC,EACXC,IAAY,EAChB,MAAM,IAAI,MAAO,4IAA6I,EAE/J,GAAKH,IAAUG,EACd,MAAM,IAAI,MAAO,4FAA6F,EAE/G,GAAKE,GAEJ,GADAD,EAAQV,EAAM,OAASS,EAClB,CAACnB,EAAWoB,CAAM,EACtB,MAAM,IAAI,MAAO,8IAA+I,UAGjKA,EAAQN,EAAK,OACRJ,EAAM,SAAWU,EAAMD,EAC3B,MAAM,IAAI,MAAO,8IAA+I,EAGlK,GAAKJ,GAAQA,EAAK,SAAWK,EAC5B,MAAM,IAAI,MAAO,mGAAoG,EAEtH,OAAAV,EAAQD,EAAaC,CAAM,EACpBY,EAeP,SAASA,GAAa,CACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EAGJ,GADAa,EAAO,UAAU,OACZA,IAAST,EACb,MAAKS,EAAOT,EACL,IAAI,MAAO,6CAA8C,EAE1D,IAAI,MAAO,yCAA0C,EAI5D,IAFAO,EAAS,CAAC,EACVC,EAAS,CAAC,EACJZ,EAAI,EAAGA,EAAII,EAAOJ,IAAM,CAE7B,GADAe,EAAI,UAAWf,CAAE,EACZ,CAACR,EAAeuB,CAAE,EACtB,MAAKf,EAAIK,EACF,IAAI,UAAWZ,EAAQ,6EAA8EsB,CAAE,CAAE,EAEzG,IAAI,UAAWtB,EAAQ,8EAA+EsB,CAAE,CAAE,EAGlHJ,EAAO,KAAMI,CAAE,EACfH,EAAO,KAAMjB,EAAaD,EAAUqB,CAAE,CAAE,CAAE,CAC3C,CAKA,GAHAD,EAAMlB,EAAcY,EAAOD,EAAST,EAAOS,EAAS,EAAG,EAAGK,EAAQ,EAAG,CAAE,EAGlEE,EAAM,EACV,MAAM,IAAI,UAAW,6GAA8G,EAcpI,GAXKL,EACJO,EAAIP,EAEJO,EAAId,EAAMY,CAAI,EAGVX,EACJa,EAAGL,EAAQR,EAAMW,CAAI,CAAE,EAEvBE,EAAGL,CAAO,EAENL,IAAS,EACb,OAAOK,EAAQJ,EAAQ,CAAE,EAE1B,GAAKD,IAAS,EAGd,OAAOK,EAAO,MAAON,CAAI,CAC1B,CACD,CAKApB,EAAO,QAAUgB,IC9KjB,IAAIgB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_index_of_types", "__commonJSMin", "exports", "module", "indexOfTypes", "N", "M", "x", "strideX1", "strideX2", "offsetX", "y", "strideY", "offsetY", "ix", "iy", "i", "j", "require_main", "__commonJSMin", "exports", "module", "isNonNegativeInteger", "isPositiveInteger", "isInteger", "isFunctionArray", "isFunction", "isCollection", "isndarrayLike", "format", "getDType", "resolveEnum", "indexOfTypes", "types2enums", "types", "out", "i", "dispatch", "fcns", "data", "nargs", "nin", "nout", "narrays", "nfcns", "fcn", "dispatcher", "arrays", "dtypes", "argc", "idx", "v", "f", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 02fe150..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,87 +0,0 @@ - -{{alias}}( fcns, types, data, nargs, nin, nout ) - Returns an ndarray function interface which performs multiple dispatch. - - An ndarray function interface has the following signature: - - f( x, y, ... ) - - where - - - x: ndarray. - - y: ndarray. - - ...: additional ndarrays. - - The number of parameters is derived from `nargs`, the number of input - ndarrays is derived from `nin`, and the number of output ndarrays is derived - from `nout`. - - Parameters - ---------- - fcns: Function|ArrayLikeObject - List of ndarray functions. An ndarray function should have the following - signature: - - f( arrays, data ) - - where - - - arrays: array containing input and output ndarrays. - - data: ndarray function data (e.g., a callback). - - For convenience, a single ndarray function may be provided which will be - invoked whenever the ndarray argument data types match a sequence of - types in `types`. Providing a single ndarray function is particularly - convenient for the case where, regardless of array data types, - traversing arrays remains the same, but the ndarray function `data` - differs (e.g., callbacks which differ based on the array data types). - - types: ArrayLikeObject - One-dimensional list of ndarray argument data types. - - data: ArrayLikeObject|null - ndarray function data (e.g., callbacks). If `null`, a returned ndarray - function interface does **not** provide a `data` argument to an invoked - ndarray function. - - nargs: integer - Total number of ndarray function interface arguments. - - nin: integer - Number of input ndarrays. - - nout: integer - Number of output ndarrays. - - Returns - ------- - fcn: Function - ndarray function interface. - - Examples - -------- - // Define ndarray argument data types: - > var t = [ 'float64', 'float64', 'float32', 'float32' ]; - - // Define a list of ndarray function data (callbacks): - > var d = [ {{alias:@stdlib/math/base/special/abs}}, {{alias:@stdlib/math/base/special/absf}} ]; - - // Create an ndarray function interface for applying unary callbacks: - > var f = {{alias}}( {{alias:@stdlib/ndarray/base/unary}}, t, d, 2, 1, 1 ); - - // Create an input ndarray: - > var xbuf = new {{alias:@stdlib/array/float64}}( [ -1.0, -2.0, -3.0, -4.0 ] ); - > var x = {{alias:@stdlib/ndarray/ctor}}( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Create an output ndarray: - > var ybuf = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 0.0, 0.0 ] ); - > var y = {{alias:@stdlib/ndarray/ctor}}( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Compute the element-wise absolute value: - > f( x, y ); - > ybuf - [ 1.0, 2.0, 3.0, 4.0 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 3cba031..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,641 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable max-lines */ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import dispatch = require( './index' ); - - -// FUNCTIONS // - -/** -* Nullary callback. -* -* @return input value -*/ -function nullary(): any { - return 5.0; -} - -/** -* Unary callback. -* -* @param x - input value -* @return input value -*/ -function unary( x: any ): any { - return x; -} - -/** -* Binary callback. -* -* @param x - input value -* @param y - input value -* @return output value -*/ -function binary( x: number, y: number ): number { - return x + y; -} - -/** -* Ternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @return output value -*/ -function ternary( x: number, y: number, z: number ): number { - return x + y + z; -} - -/** -* Quaternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @param w - input value -* @return output value -*/ -function quaternary( x: number, y: number, z: number, w: number ): number { - return x + y + z + w; -} - -/** -* Mock `ind2sub` function. -* -* @param shape - dimensions -* @param idx - linear index -* @param opts - options -* @return subscripts -*/ -function ind2sub( shape: ArrayLike, idx: number, opts?: any ): Array { - let out; - let i; - - out = []; - if ( typeof opts === 'object' && opts !== null && opts.order === 'row-major' ) { no-unsafe-any - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } else { - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } - return out; -} - -/** -* Mock ndarray function. -* -* @param arrays - ndarrays -* @param fcn - callback -*/ -function ndarrayFcn( arrays: Array, fcn: ( x: any ) => any ): void { - let xord; - let yord; - let opts; - let sub; - let sh; - let N; - let x; - let y; - let v; - let i; - - x = arrays[ 0 ]; - y = arrays[ 1 ]; - sh = x.shape; - if ( sh.length === 0 ) { - return; - } - N = 1; - for ( i = 0; i < sh.length; i += 1 ) { - N *= sh[ i ]; - } - xord = x.order; - yord = y.order; - opts = { - 'order': '' - }; - opts.order = xord; - for ( i = 0; i < N; i += 1 ) { - // Convert a linear index to subscripts: - opts.order = xord; - sub = ind2sub( sh, i, opts ); - - // Retrieve an element from `x`: - v = x.get.apply( x, sub ); - - // Convert a linear index to subscripts: - opts.order = yord; - sub = ind2sub( sh, i, opts ); - - // Append the result of applying the callback: - sub[ sub.length ] = fcn( v ) as number; - - // Assign the result to an element in `y`: - y.set.apply( y, sub ); - } -} - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a dispatch function... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, 1 ); // $ExpectType Dispatcher - dispatch( [ ndarrayFcn ], types, data, 2, 1, 1 ); // $ExpectType Dispatcher -} - -// The compiler throws an error if the function is provided a first argument which is not either an ndarray function or an array-like object containing ndarray functions... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( '10', types, data, 2, 1, 1 ); // $ExpectError - dispatch( 10, types, data, 2, 1, 1 ); // $ExpectError - dispatch( true, types, data, 2, 1, 1 ); // $ExpectError - dispatch( false, types, data, 2, 1, 1 ); // $ExpectError - dispatch( null, types, data, 2, 1, 1 ); // $ExpectError - dispatch( undefined, types, data, 2, 1, 1 ); // $ExpectError - dispatch( [ '1' ], types, data, 2, 1, 1 ); // $ExpectError - dispatch( {}, types, data, 2, 1, 1 ); // $ExpectError - dispatch( ( x: number ): number => x, types, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object... -{ - const data = [ unary ]; - - dispatch( ndarrayFcn, 10, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, true, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, false, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, null, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, undefined, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, {}, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object or null... -{ - const types = [ 'float64', 'float64' ]; - - dispatch( ndarrayFcn, types, 10, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, true, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, false, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, undefined, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, {}, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, '10', 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, true, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, false, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, null, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, undefined, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, [ '1' ], 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, {}, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, ( x: number ): number => x, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, '10', 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, true, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, false, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, null, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, undefined, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, [ '1' ], 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, {}, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, ( x: number ): number => x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, '10' ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, true ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, false ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, null ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, undefined ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, [ '1' ] ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, {} ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch(); // $ExpectError - dispatch( ndarrayFcn ); // $ExpectError - dispatch( ndarrayFcn, types ); // $ExpectError - dispatch( ndarrayFcn, types, data ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, 1, 0 ); // $ExpectError -} - -// The function returns a dispatch function... -{ - const x = array(); - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const t1 = [ 'float64' ]; - const d1 = [ nullary ]; - const f1 = dispatch( ndarrayFcn, t1, d1, 1, 1, 0 ); - f1( x ); // $ExpectType void | ndarray - - const t2 = [ 'float64', 'float64' ]; - const d2 = [ unary ]; - const f2 = dispatch( ndarrayFcn, t2, d2, 2, 1, 1 ); - f2( x, y ); // $ExpectType void | ndarray - - const t3 = [ 'float64', 'float64', 'float64' ]; - const d3 = [ binary ]; - const f3 = dispatch( ndarrayFcn, t3, d3, 3, 2, 1 ); - f3( x, y, z ); // $ExpectType void | ndarray - - const t4 = [ 'float64', 'float64', 'float64', 'float64' ]; - const d4 = [ ternary ]; - const f4 = dispatch( ndarrayFcn, t4, d4, 4, 3, 1 ); - f4( x, y, z, w ); // $ExpectType void | ndarray - - const t5 = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const d5 = [ quaternary ]; - const f5 = dispatch( ndarrayFcn, t5, d5, 5, 4, 1 ); - f5( x, y, z, w, u ); // $ExpectType void | ndarray -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (1 ndarray)... -{ - const types = [ 'float64' ]; - const data = [ nullary ]; - - const f = dispatch( ndarrayFcn, types, data, 1, 0, 1 ); - f( '10' ); // $ExpectError - f( 10 ); // $ExpectError - f( true ); // $ExpectError - f( false ); // $ExpectError - f( null ); // $ExpectError - f( undefined ); // $ExpectError - f( [ '1' ] ); // $ExpectError - f( {} ); // $ExpectError - f( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( 10, y ); // $ExpectError - f( '10', y ); // $ExpectError - f( true, y ); // $ExpectError - f( false, y ); // $ExpectError - f( null, y ); // $ExpectError - f( undefined, y ); // $ExpectError - f( [ '1' ], y ); // $ExpectError - f( {}, y ); // $ExpectError - f( ( x: number ): number => x, y ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const x = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( x, 10 ); // $ExpectError - f( x, '10' ); // $ExpectError - f( x, true ); // $ExpectError - f( x, false ); // $ExpectError - f( x, null ); // $ExpectError - f( x, undefined ); // $ExpectError - f( x, [ '1' ] ); // $ExpectError - f( x, {} ); // $ExpectError - f( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( 10, y, z ); // $ExpectError - f( '10', y, z ); // $ExpectError - f( true, y, z ); // $ExpectError - f( false, y, z ); // $ExpectError - f( null, y, z ); // $ExpectError - f( undefined, y, z ); // $ExpectError - f( [ '1' ], y, z ); // $ExpectError - f( {}, y, z ); // $ExpectError - f( ( x: number ): number => x, y, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, 10, z ); // $ExpectError - f( x, '10', z ); // $ExpectError - f( x, true, z ); // $ExpectError - f( x, false, z ); // $ExpectError - f( x, null, z ); // $ExpectError - f( x, undefined, z ); // $ExpectError - f( x, [ '1' ], z ); // $ExpectError - f( x, {}, z ); // $ExpectError - f( x, ( x: number ): number => x, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, y, '10' ); // $ExpectError - f( x, y, true ); // $ExpectError - f( x, y, false ); // $ExpectError - f( x, y, null ); // $ExpectError - f( x, y, undefined ); // $ExpectError - f( x, y, [ '1' ] ); // $ExpectError - f( x, y, {} ); // $ExpectError - f( x, y, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( 10, y, z, w ); // $ExpectError - f( '10', y, z, w ); // $ExpectError - f( true, y, z, w ); // $ExpectError - f( false, y, z, w ); // $ExpectError - f( null, y, z, w ); // $ExpectError - f( undefined, y, z, w ); // $ExpectError - f( [ '1' ], y, z, w ); // $ExpectError - f( {}, y, z, w ); // $ExpectError - f( ( x: number ): number => x, y, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, 10, z, w ); // $ExpectError - f( x, '10', z, w ); // $ExpectError - f( x, true, z, w ); // $ExpectError - f( x, false, z, w ); // $ExpectError - f( x, null, z, w ); // $ExpectError - f( x, undefined, z, w ); // $ExpectError - f( x, [ '1' ], z, w ); // $ExpectError - f( x, {}, z, w ); // $ExpectError - f( x, ( x: number ): number => x, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, 10, w ); // $ExpectError - f( x, y, '10', w ); // $ExpectError - f( x, y, true, w ); // $ExpectError - f( x, y, false, w ); // $ExpectError - f( x, y, null, w ); // $ExpectError - f( x, y, undefined, w ); // $ExpectError - f( x, y, [ '1' ], w ); // $ExpectError - f( x, y, {}, w ); // $ExpectError - f( x, y, ( x: number ): number => x, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, z, 10 ); // $ExpectError - f( x, y, z, '10' ); // $ExpectError - f( x, y, z, true ); // $ExpectError - f( x, y, z, false ); // $ExpectError - f( x, y, z, null ); // $ExpectError - f( x, y, z, undefined ); // $ExpectError - f( x, y, z, [ '1' ] ); // $ExpectError - f( x, y, z, {} ); // $ExpectError - f( x, y, z, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( 10, y, z, w, u ); // $ExpectError - f( '10', y, z, w, u ); // $ExpectError - f( true, y, z, w, u ); // $ExpectError - f( false, y, z, w, u ); // $ExpectError - f( null, y, z, w, u ); // $ExpectError - f( undefined, y, z, w, u ); // $ExpectError - f( [ '1' ], y, z, w, u ); // $ExpectError - f( {}, y, z, w, u ); // $ExpectError - f( ( x: number ): number => x, y, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, 10, z, w, u ); // $ExpectError - f( x, '10', z, w, u ); // $ExpectError - f( x, true, z, w, u ); // $ExpectError - f( x, false, z, w, u ); // $ExpectError - f( x, null, z, w, u ); // $ExpectError - f( x, undefined, z, w, u ); // $ExpectError - f( x, [ '1' ], z, w, u ); // $ExpectError - f( x, {}, z, w, u ); // $ExpectError - f( x, ( x: number ): number => x, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, 10, w, u ); // $ExpectError - f( x, y, '10', w, u ); // $ExpectError - f( x, y, true, w, u ); // $ExpectError - f( x, y, false, w, u ); // $ExpectError - f( x, y, null, w, u ); // $ExpectError - f( x, y, undefined, w, u ); // $ExpectError - f( x, y, [ '1' ], w, u ); // $ExpectError - f( x, y, {}, w, u ); // $ExpectError - f( x, y, ( x: number ): number => x, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, 10, u ); // $ExpectError - f( x, y, z, '10', u ); // $ExpectError - f( x, y, z, true, u ); // $ExpectError - f( x, y, z, false, u ); // $ExpectError - f( x, y, z, null, u ); // $ExpectError - f( x, y, z, undefined, u ); // $ExpectError - f( x, y, z, [ '1' ], u ); // $ExpectError - f( x, y, z, {}, u ); // $ExpectError - f( x, y, z, ( x: number ): number => x, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fifth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, w, 10 ); // $ExpectError - f( x, y, z, w, '10' ); // $ExpectError - f( x, y, z, w, true ); // $ExpectError - f( x, y, z, w, false ); // $ExpectError - f( x, y, z, w, null ); // $ExpectError - f( x, y, z, w, undefined ); // $ExpectError - f( x, y, z, w, [ '1' ] ); // $ExpectError - f( x, y, z, w, {} ); // $ExpectError - f( x, y, z, w, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/add.js b/examples/add.js deleted file mode 100644 index 775b711..0000000 --- a/examples/add.js +++ /dev/null @@ -1,121 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var dispatch = require( './../lib' ); - -function add2( arrays ) { - var opts; - var xo; - var yo; - var zo; - var sx; - var sy; - var sz; - var sh; - var N; - var x; - var y; - var z; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - z = arrays[ 2 ]; - xo = x.order; - yo = y.order; - zo = z.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - opts.order = yo; - sy = ind2sub( sh, i, opts ); - v = x.get.apply( x, sx ) + y.get.apply( y, sy ); - - opts.order = zo; - sz = ind2sub( sh, i, opts ); - sz.push( v ); - z.set.apply( z, sz ); - } -} - -var fcns = [ - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2 -]; - -var types = [ - dtypes.float64, dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.int32, dtypes.int32, - dtypes.uint32, dtypes.uint32, dtypes.uint32, - dtypes.int16, dtypes.int16, dtypes.int16, - dtypes.uint16, dtypes.uint16, dtypes.uint16, - dtypes.int8, dtypes.int8, dtypes.int8, - dtypes.uint8, dtypes.uint8, dtypes.uint8, - dtypes.uint8c, dtypes.uint8c, dtypes.uint8c -]; - -var add = dispatch( fcns, types, null, 3, 2, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var zbuf = new Float64Array( xbuf.length ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var z = ndarray( 'float64', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); - -xbuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -ybuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -zbuf = new Int32Array( xbuf.length ); - -x = ndarray( 'int32', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'int32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -z = ndarray( 'int32', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); diff --git a/examples/sin.js b/examples/sin.js deleted file mode 100644 index 8cd4871..0000000 --- a/examples/sin.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int8Array = require( '@stdlib/array-int8' ); -var sin = require( '@stdlib/math-base-special-sin' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/strided-dtypes' ); -var dispatch = require( './../lib' ); - -function apply( arrays, fcn ) { - var opts; - var xo; - var yo; - var sx; - var sy; - var sh; - var N; - var x; - var y; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - xo = x.order; - yo = y.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - v = fcn( x.get.apply( x, sx ) ); - - opts.order = yo; - sy = ind2sub( sh, i, opts ); - sy.push( v ); - y.set.apply( y, sy ); - } -} - -var fcns = [ - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply -]; - -var types = [ - dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float64, - dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.float64, - dtypes.uint32, dtypes.float64, - dtypes.int16, dtypes.float64, - dtypes.int16, dtypes.float32, - dtypes.uint16, dtypes.float64, - dtypes.uint16, dtypes.float32, - dtypes.int8, dtypes.float64, - dtypes.int8, dtypes.float32, - dtypes.uint8, dtypes.float64, - dtypes.uint8, dtypes.float32, - dtypes.uint8c, dtypes.float64, - dtypes.uint8c, dtypes.float32 -]; - -var data = [ - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin -]; - -var sine = dispatch( fcns, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); - -xbuf = new Int8Array( [ 1, 2, 3, 4, 5 ] ); -ybuf = new Float32Array( xbuf.length ); - -x = ndarray( 'int8', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'float32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); diff --git a/examples/unary.js b/examples/unary.js deleted file mode 100644 index e9c3fb4..0000000 --- a/examples/unary.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -var unary = require( '@stdlib/ndarray-base-unary' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var dispatch = require( './../lib' ); - -var types = [ 'float64', 'float64' ]; - -var data = [ - abs -]; - -var absolute = dispatch( unary, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -absolute( x, y ); -console.log( ybuf ); -// => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 5f280a1..c49a4e4 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..a78f36a --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@v0.2.2-esm/index.mjs";function m(m,f,l,p,w,v){var a,g,c;if(i(m))c=m;else if(!s(m))throw new TypeError(d("0jr5d",m));if(!n(f))throw new TypeError(d("0jr2y",f));if(!n(l)&&null!==l)throw new TypeError(d("0jr5e",l));if(!e(p))throw new TypeError(d("0jr5f",p));if(!r(w))throw new TypeError(d("0jr5X",w));if(!r(v))throw new TypeError(d("0jr5g",v));if(0===(a=w+v))throw new Error(d("0jr0h"));if(p!==a)throw new Error(d("0jr0i"));if(c){if(g=f.length/a,!t(g))throw new Error(d("0jr0j"))}else if(g=m.length,f.length!==g*a)throw new Error(d("0jr0j"));if(l&&l.length!==g)throw new Error(d("0jr0k"));return f=function(r){var e,t;for(e=[],t=0;t [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0jr5d', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0jr2y', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( '0jr5e', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0jr5f', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0jr5X', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0jr5g', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format('0jr0h') );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format('0jr0i') );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format('0jr0k') );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format('0jr0l') );\n\t\t\t}\n\t\t\tthrow new Error( format('0jr0m') );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( '0jr5h', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( '0jr5i', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format('0jr0n') );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found).\n*\n* ## Notes\n*\n* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types).\n* - The function assumes that `x` is stored in row-major order.\n* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`.\n* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value.\n*\n* @private\n* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension)\n* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension)\n* @param {ArrayLikeObject} x - input two-dimensional reference array\n* @param {integer} strideX1 - `x` stride length along first dimension\n* @param {integer} strideX2 - `x` stride length along second dimension\n* @param {NonNegativeInteger} offsetX - `x` starting index\n* @param {ArrayLikeObject} y - search array\n* @param {integer} strideY - `y` stride length\n* @param {NonNegativeInteger} offsetY - `y` starting index\n* @returns {integer} row index (if found) and `-1` otherwise\n*\n* @example\n* // Define a reference array to search:\n* var types = [\n* 'float64', 'float64', 'float64',\n* 'float32', 'float32', 'float32',\n* 'uint32', 'uint32', 'float64',\n* 'int32', 'int32', 'float64',\n* 'uint16', 'uint16', 'float64',\n* 'int16', 'int16', 'float64',\n* 'uint8', 'uint8', 'float64',\n* 'int8', 'int8', 'float64'\n* ];\n*\n* // Define reference array dimensions:\n* var N = 8; // rows\n* var M = 3; // columns\n*\n* // Define a search array:\n* y1 = [\n* 'float32', 'float32', 'float32',\n* ];\n*\n* // Find the list of types:\n* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 );\n* // returns 1\n*\n// Define a search array:\n* y2 = [\n* 'float32', 'float32', 'float64',\n* ];\n*\n* // Find the list of types:\n* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 );\n* // returns -1\n*/\nfunction indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len\n\tvar ix;\n\tvar iy;\n\tvar i;\n\tvar j;\n\n\t// Search for the first row which matches `y`...\n\tix = offsetX;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tiy = offsetY;\n\t\tfor ( j = 0; j < M; j++ ) {\n\t\t\tif ( x[ ix+(j*strideX2) ] !== y[ iy ] ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tiy += strideY;\n\t\t}\n\t\t// If we successfully iterated over all columns, then that means we've found a match...\n\t\tif ( j === M ) {\n\t\t\treturn i;\n\t\t}\n\t\tix += strideX1;\n\t}\n\treturn -1;\n}\n\n\n// EXPORTS //\n\nexport default indexOfTypes;\n"],"names":["dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","out","i","push","resolveEnum","types2enums","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","getDType","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","j","indexOfTypes","slice"],"mappings":";;0+BA0GA,SAASA,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAO,UAEzB,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAO,UAEzB,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAO,eAIzB,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAO,UAG1B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAO,UAGzB,OADAX,EA5GD,SAAsBA,GACrB,IAAIkB,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAInB,EAAMgB,OAAQG,IAC9BD,EAAIE,KAAMC,EAAarB,EAAOmB,KAE/B,OAAOD,CACR,CAmGSI,CAAatB,GAgBrB,WACC,IAAIuB,EACAC,EACAC,EACAC,EACAC,EACAC,EACAT,EAGJ,GADAM,EAAOI,UAAUb,OACZS,IAASvB,EAAQ,CACrB,GAAKuB,EAAOvB,EACX,MAAM,IAAIa,MAAOJ,EAAO,UAEzB,MAAM,IAAII,MAAOJ,EAAO,SACxB,CAGD,IAFAY,EAAS,GACTC,EAAS,GACHL,EAAI,EAAGA,EAAIjB,EAAOiB,IAAM,CAE7B,IAAMW,EADNH,EAAIE,UAAWV,IAEd,MAAKA,EAAIhB,EACF,IAAIO,UAAWC,EAAQ,QAASgB,IAEhC,IAAIjB,UAAWC,EAAQ,QAASgB,IAGxCJ,EAAOH,KAAMO,GACbH,EAAOJ,KAAMC,EAAaU,EAAUJ,IACpC,CAKD,IAHAD,EC1HF,SAAuBM,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAvB,EACAwB,EAIJ,IADAF,EAAKJ,EACClB,EAAI,EAAGA,EAAIa,EAAGb,IAAM,CAEzB,IADAuB,EAAKF,EACCG,EAAI,EAAGA,EAAIV,GACXC,EAAGO,EAAIE,EAAEP,KAAgBE,EAAGI,GADdC,IAInBD,GAAMH,EAGP,GAAKI,IAAMV,EACV,OAAOd,EAERsB,GAAMN,CACN,CACD,OAAQ,CACT,CDmGQS,CAActC,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGmB,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAId,UAAWC,EAAO,UAI5BiB,EADIrB,GAGAR,EAAM2B,GAGNzB,EACJ2B,EAAGL,EAAQtB,EAAMyB,IAEjBE,EAAGL,GAEJ,GAAc,IAATnB,EACJ,OAAOmB,EAAQlB,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOmB,EAAOsB,MAAO1C,EACrB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 88f0e3e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Create an ndarray function interface which performs multiple dispatch. -* -* @module @stdlib/ndarray-dispatch -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var dispatch = require( '@stdlib/ndarray-dispatch' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/index_of_types.js b/lib/index_of_types.js deleted file mode 100644 index fda2297..0000000 --- a/lib/index_of_types.js +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found). -* -* ## Notes -* -* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types). -* - The function assumes that `x` is stored in row-major order. -* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`. -* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value. -* -* @private -* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension) -* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension) -* @param {ArrayLikeObject} x - input two-dimensional reference array -* @param {integer} strideX1 - `x` stride length along first dimension -* @param {integer} strideX2 - `x` stride length along second dimension -* @param {NonNegativeInteger} offsetX - `x` starting index -* @param {ArrayLikeObject} y - search array -* @param {integer} strideY - `y` stride length -* @param {NonNegativeInteger} offsetY - `y` starting index -* @returns {integer} row index (if found) and `-1` otherwise -* -* @example -* // Define a reference array to search: -* var types = [ -* 'float64', 'float64', 'float64', -* 'float32', 'float32', 'float32', -* 'uint32', 'uint32', 'float64', -* 'int32', 'int32', 'float64', -* 'uint16', 'uint16', 'float64', -* 'int16', 'int16', 'float64', -* 'uint8', 'uint8', 'float64', -* 'int8', 'int8', 'float64' -* ]; -* -* // Define reference array dimensions: -* var N = 8; // rows -* var M = 3; // columns -* -* // Define a search array: -* y1 = [ -* 'float32', 'float32', 'float32', -* ]; -* -* // Find the list of types: -* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 ); -* // returns 1 -* -// Define a search array: -* y2 = [ -* 'float32', 'float32', 'float64', -* ]; -* -* // Find the list of types: -* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 ); -* // returns -1 -*/ -function indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len - var ix; - var iy; - var i; - var j; - - // Search for the first row which matches `y`... - ix = offsetX; - for ( i = 0; i < N; i++ ) { - iy = offsetY; - for ( j = 0; j < M; j++ ) { - if ( x[ ix+(j*strideX2) ] !== y[ iy ] ) { - break; - } - iy += strideY; - } - // If we successfully iterated over all columns, then that means we've found a match... - if ( j === M ) { - return i; - } - ix += strideX1; - } - return -1; -} - - -// EXPORTS // - -module.exports = indexOfTypes; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4648598..0000000 --- a/lib/main.js +++ /dev/null @@ -1,231 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isFunctionArray = require( '@stdlib/assert-is-function-array' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var resolveEnum = require( '@stdlib/ndarray-base-dtype-resolve-enum' ); -var indexOfTypes = require( './index_of_types.js' ); - - -// FUNCTIONS // - -/** -* Returns a list of data type enumeration constants. -* -* @private -* @param {Collection} types - list of types -* @returns {IntegerArray} list of data type enumeration constants -*/ -function types2enums( types ) { - var out; - var i; - - out = []; - for ( i = 0; i < types.length; i++ ) { - out.push( resolveEnum( types[ i ] ) ); - } - return out; -} - - -// MAIN // - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param {(FunctionArray|Function)} fcns - list of ndarray functions -* @param {Collection} types - one-dimensional list of ndarray argument data types -* @param {(Collection|null)} data - ndarray function data (e.g., callbacks) -* @param {PositiveInteger} nargs - total number of ndarray function interface arguments -* @param {NonNegativeInteger} nin - number of input ndarrays -* @param {NonNegativeInteger} nout - number of output ndarrays -* @throws {TypeError} first argument must be either a function or an array of functions -* @throws {TypeError} second argument must be an array-like object -* @throws {TypeError} third argument must be an array-like object or `null` -* @throws {Error} third and first arguments must have the same number of elements -* @throws {TypeError} fourth argument must be a positive integer -* @throws {TypeError} fifth argument must be a nonnegative integer -* @throws {TypeError} sixth argument must be a nonnegative integer -* @throws {Error} fourth argument must equal the specified number of input and output arrays -* @throws {Error} number of types must match the number of functions times the total number of array arguments for each function -* @throws {Error} interface must accept at least one input and/or output ndarray -* @returns {Function} ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function dispatch( fcns, types, data, nargs, nin, nout ) { - var narrays; - var nfcns; - var fcn; - - if ( isFunction( fcns ) ) { - fcn = fcns; - } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( '0jr5d', fcns ) ); - } - if ( !isCollection( types ) ) { - throw new TypeError( format( '0jr2y', types ) ); - } - if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( '0jr5e', data ) ); - } - if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( '0jr5f', nargs ) ); - } - if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( '0jr5X', nin ) ); - } - if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( '0jr5g', nout ) ); - } - narrays = nin + nout; - if ( narrays === 0 ) { - throw new Error( format('0jr0h') ); - } - if ( nargs !== narrays ) { - throw new Error( format('0jr0i') ); - } - if ( fcn ) { - nfcns = types.length / narrays; - if ( !isInteger( nfcns ) ) { - throw new Error( format('0jr0j') ); - } - } else { - nfcns = fcns.length; - if ( types.length !== nfcns*narrays ) { - throw new Error( format('0jr0j') ); - } - } - if ( data && data.length !== nfcns ) { - throw new Error( format('0jr0k') ); - } - types = types2enums( types ); - return dispatcher; - - /** - * ndarray function interface which performs multiple dispatch. - * - * @private - * @param {ndarrayLike} x - ndarray - * @param {...ndarrayLike} args - ndarray arguments - * @throws {Error} insufficient arguments - * @throws {Error} too many arguments - * @throws {TypeError} input array arguments must be ndarray-like objects - * @throws {TypeError} output array arguments must be ndarray-like objects - * @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types - * @returns {(ndarrayLike|Array|void)} destination array(s) - */ - function dispatcher() { - var arrays; - var dtypes; - var argc; - var idx; - var v; - var f; - var i; - - argc = arguments.length; - if ( argc !== nargs ) { - if ( argc < nargs ) { - throw new Error( format('0jr0l') ); - } - throw new Error( format('0jr0m') ); - } - arrays = []; - dtypes = []; - for ( i = 0; i < nargs; i++ ) { - v = arguments[ i ]; - if ( !isndarrayLike( v ) ) { - if ( i < nin ) { - throw new TypeError( format( '0jr5h', v ) ); - } else { - throw new TypeError( format( '0jr5i', v ) ); - } - } - arrays.push( v ); - dtypes.push( resolveEnum( getDType( v ) ) ); - } - // Resolve the ndarray function satisfying the input array types: - idx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len - - // Check whether we were able to successfully resolve an ndarray function: - if ( idx < 0 ) { - throw new TypeError( format('0jr0n') ); - } - // Retrieve the ndarray function: - if ( fcn ) { - f = fcn; - } else { - f = fcns[ idx ]; - } - // Evaluate the ndarray function: - if ( data ) { - f( arrays, data[ idx ] ); - } else { - f( arrays ); - } - if ( nout === 1 ) { - return arrays[ narrays-1 ]; - } - if ( nout === 0 ) { - return; - } - return arrays.slice( nin ); - } -} - - -// EXPORTS // - -module.exports = dispatch; diff --git a/package.json b/package.json index 4dfd645..e6c8bad 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Create an ndarray function interface which performs multiple dispatch.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,57 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-function-array": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer": "^0.2.2", - "@stdlib/assert-is-positive-integer": "^0.2.2", - "@stdlib/ndarray-base-dtype-resolve-enum": "^0.2.2", - "@stdlib/ndarray-dtype": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.2.2", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/array-int8": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/math-base-assert-is-nan": "^0.2.2", - "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/math-base-special-pow": "^0.3.0", - "@stdlib/math-base-special-sin": "^0.3.0", - "@stdlib/ndarray-base-buffer-dtype": "^0.3.0", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-unary": "^0.2.1", - "@stdlib/ndarray-ctor": "^0.2.1", - "@stdlib/ndarray-dtypes": "^0.3.0", - "@stdlib/ndarray-ind2sub": "^0.2.1", - "@stdlib/strided-dtypes": "^0.3.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "ndarray", @@ -100,7 +26,6 @@ "multimethod", "multimethods" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..f17fdd8 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/fixtures/binary.js b/test/fixtures/binary.js deleted file mode 100644 index a60dfa2..0000000 --- a/test/fixtures/binary.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Binary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @returns {number} sum -*/ -function binary( x, y ) { - return x + y; -} - - -// EXPORTS // - -module.exports = binary; diff --git a/test/fixtures/fill.js b/test/fixtures/fill.js deleted file mode 100644 index 41b2958..0000000 --- a/test/fixtures/fill.js +++ /dev/null @@ -1,76 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which fills one or more ndarrays. -* -* @private -* @param {*} value - fill value -* @returns {Function} ndarray function -*/ -function fill( value ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - */ - function ndarrayFcn( arrays ) { - var opts; - var sub; - var arr; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - opts = { - 'order': '' - }; - for ( j = 0; j < M; j++ ) { - arr = arrays[ j ]; - opts.order = arrays[ j ].order; - for ( i = 0; i < N; i++ ) { - sub = ind2sub( sh, i, opts ); - sub.push( value ); - arr.set.apply( arr, sub ); - } - } - } -} - - -// EXPORTS // - -module.exports = fill; diff --git a/test/fixtures/foreach.js b/test/fixtures/foreach.js deleted file mode 100644 index a426290..0000000 --- a/test/fixtures/foreach.js +++ /dev/null @@ -1,72 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function forEach( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - fcn.apply( null, args ); - } -} - - -// EXPORTS // - -module.exports = forEach; diff --git a/test/fixtures/map1n.js b/test/fixtures/map1n.js deleted file mode 100644 index 614196b..0000000 --- a/test/fixtures/map1n.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function which maps the return value of a callback to `N` arrays. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function map1N( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var v; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - v = fcn(); - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - sub.push( v ); - arrays[ j ].set.apply( arrays[ j ], sub ); - } - } -} - - -// EXPORTS // - -module.exports = map1N; diff --git a/test/fixtures/nullary.js b/test/fixtures/nullary.js deleted file mode 100644 index 4f22126..0000000 --- a/test/fixtures/nullary.js +++ /dev/null @@ -1,36 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Nullary callback. -* -* @private -* @returns {number} value -*/ -function nullary() { - return 3.0; -} - - -// EXPORTS // - -module.exports = nullary; diff --git a/test/fixtures/quaternary.js b/test/fixtures/quaternary.js deleted file mode 100644 index 548437b..0000000 --- a/test/fixtures/quaternary.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quaternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @returns {number} sum -*/ -function quaternary( x, y, z, w ) { - return x + y + z + w; -} - - -// EXPORTS // - -module.exports = quaternary; diff --git a/test/fixtures/quinary.js b/test/fixtures/quinary.js deleted file mode 100644 index 36068de..0000000 --- a/test/fixtures/quinary.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quinary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @param {number} u - input value -* @returns {number} sum -*/ -function quinary( x, y, z, w, u ) { - return x + y + z + w + u; -} - - -// EXPORTS // - -module.exports = quinary; diff --git a/test/fixtures/sum.js b/test/fixtures/sum.js deleted file mode 100644 index efdbb1b..0000000 --- a/test/fixtures/sum.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which computes the sum across one or more ndarrays. -* -* @private -* @param {Object} ctx - context -* @param {number} ctx.sum - initial sum -* @returns {Function} ndarray function -*/ -function wrapper( ctx ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - * @param {Function} [fcn] - callback - */ - function ndarrayFcn( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var f; - var i; - var j; - - if ( arguments.length > 1 ) { - f = fcn; - } - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - if ( f ) { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - ctx.sum += f.apply( null, args ); - } - } else { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - ctx.sum += arrays[ j ].get.apply( arrays[ j ], sub ); - } - } - } - } -} - - -// EXPORTS // - -module.exports = wrapper; diff --git a/test/fixtures/ternary.js b/test/fixtures/ternary.js deleted file mode 100644 index 0595d5f..0000000 --- a/test/fixtures/ternary.js +++ /dev/null @@ -1,39 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Ternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @returns {number} sum -*/ -function ternary( x, y, z ) { - return x + y + z; -} - - -// EXPORTS // - -module.exports = ternary; diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d6c2c8e..0000000 --- a/test/test.js +++ /dev/null @@ -1,363 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var fill = require( './fixtures/fill.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either a function or an array of functions as a first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( value, types, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object as a second argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided either an array-like object or `null` as a third argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - dispatch( unary, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a positive integer for a fourth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 0, - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a fifth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, value, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a sixth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, 1, value ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function array)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var fcns = [ unary, unary, unary ]; - var data = [ abs, abs, abs ]; - dispatch( fcns, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function argument)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs, abs, abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the length of `data` argument does not match the number of ndarray functions', function test( t ) { - var values; - var i; - - values = [ - [], - [ abs, abs ], - [ abs, abs, abs ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var fcns = [ unary ]; - dispatch( fcns, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the fourth argument is incompatible with the number of input and output ndarrays', function test( t ) { - var values; - var i; - - values = [ - 0, - 1, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of specified input and output ndarrays is zero', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var types = [ 'float64' ]; - dispatch( fill( 3 ), types, null, 1, 0, 0 ); - } -}); - -tape( 'the function returns an ndarray function interface', function test( t ) { - var types; - var data; - var f; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - f = dispatch( unary, types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ unary ], types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( fill( 3 ), types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ fill( 3 ) ], types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.two_arrays.js b/test/test.two_arrays.js deleted file mode 100644 index 16eb61b..0000000 --- a/test/test.two_arrays.js +++ /dev/null @@ -1,814 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var dtype = require( '@stdlib/ndarray-base-buffer-dtype' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var forEach = require( './fixtures/foreach.js' ); -var map1N = require( './fixtures/map1n.js' ); -var fill = require( './fixtures/fill.js' ); -var sum = require( './fixtures/sum.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the first argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var ybuf = new Float64Array( 10 ); - var y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( value, y ); - }; - } -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the second argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var xbuf = new Float64Array( 10 ); - var x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( x, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided insufficient arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var f; - var x; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [], - [ x ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided too many arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var ybuf; - var f; - var x; - var y; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [ x, y, y ], - [ x, y, y, y ], - [ x, y, y, y, y ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if unable to resolve a ndarray function supporting the provided array argument data types', function test( t ) { - var values; - var types; - var data; - var xbuf; - var fcn; - var x; - var i; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ abs, abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 4 ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - values = [ - new Uint8Array( 4 ), - new Int32Array( 4 ), - [ 0, 0, 0, 0 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided an array having data type: ' + dtype( values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var y = ndarray( dtype( value ), value, [ value.length ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - }; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only input arrays)', function test( t ) { - var types; - var xbuf; - var ybuf; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only output arrays)', function test( t ) { - var expected; - var types; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only input arrays)', function test( t ) { - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var ctx; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcns = [ - sum( ctx ), - sum( ctx ) - ]; - fcn = dispatch( fcns, types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only output arrays)', function test( t ) { - var expected; - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcns = [ - fill( 3.0 ), - fill( 4.0 ) - ]; - fcn = dispatch( fcns, types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - - fcn = dispatch( forEach, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - - fcn = dispatch( map1N, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - fcns = [ - forEach, - forEach - ]; - fcn = dispatch( fcns, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - fcns = [ - map1N, - map1N - ]; - fcn = dispatch( fcns, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - fcns = [ - unary, - unary - ]; - fcn = dispatch( fcns, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which returns one or more output arrays, if one or more output arrays is specified, and otherwise returns `undefined`', function test( t ) { - var types; - var data; - var xbuf; - var ybuf; - var out; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - // No output arrays... - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, void 0, 'returns expected value' ); - - // One output array... - data = [ - abs, - abs - ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - fcn = dispatch( fill( 3.0 ), types, null, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - // Two output arrays... - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.end(); -}); From ecbf152059476214f8a7509cfde833219856d32f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 03:53:38 +0000 Subject: [PATCH 084/109] Update README.md for ESM bundle v0.2.2 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ae20229..f46f87c 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ limitations under the License. ## Usage ```javascript -import dispatch from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dispatch@esm/index.mjs'; +import dispatch from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dispatch@v0.2.2-esm/index.mjs'; ``` #### dispatch( fcns, types, data, nargs, nin, nout ) @@ -242,7 +242,7 @@ import unary from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-unary@esm/ import ndarray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs'; import abs from 'https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs'; import Float64Array from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-float64@esm/index.mjs'; -import dispatch from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dispatch@esm/index.mjs'; +import dispatch from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dispatch@v0.2.2-esm/index.mjs'; var types = [ 'float64', 'float64' ]; From 1b9bcb45fbb36a54ec38eaeda95664220a8ece99 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 29 Jul 2024 03:53:38 +0000 Subject: [PATCH 085/109] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f46f87c..b1e83b2 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,11 @@ limitations under the License. ## Usage +```javascript +import dispatch from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dispatch@esm/index.mjs'; +``` +The previous example will load the latest bundled code from the esm branch. Alternatively, you may load a specific version by loading the file from one of the [tagged bundles](https://github.com/stdlib-js/ndarray-dispatch/tags). For example, + ```javascript import dispatch from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dispatch@v0.2.2-esm/index.mjs'; ``` @@ -242,7 +247,7 @@ import unary from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-unary@esm/ import ndarray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs'; import abs from 'https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs'; import Float64Array from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-float64@esm/index.mjs'; -import dispatch from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dispatch@v0.2.2-esm/index.mjs'; +import dispatch from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dispatch@esm/index.mjs'; var types = [ 'float64', 'float64' ]; From 0c2fae18626122144a4fbd19bba16e97657d4448 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 08:29:06 +0000 Subject: [PATCH 086/109] Transform error messages --- lib/main.js | 34 +++++++++++++++++----------------- package.json | 2 +- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/main.js b/lib/main.js index 5f4bb5d..4648598 100644 --- a/lib/main.js +++ b/lib/main.js @@ -27,7 +27,7 @@ var isFunctionArray = require( '@stdlib/assert-is-function-array' ); var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var getDType = require( '@stdlib/ndarray-dtype' ); var resolveEnum = require( '@stdlib/ndarray-base-dtype-resolve-enum' ); var indexOfTypes = require( './index_of_types.js' ); @@ -112,43 +112,43 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { if ( isFunction( fcns ) ) { fcn = fcns; } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) ); + throw new TypeError( format( '0jr5d', fcns ) ); } if ( !isCollection( types ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) ); + throw new TypeError( format( '0jr2y', types ) ); } if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); + throw new TypeError( format( '0jr5e', data ) ); } if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) ); + throw new TypeError( format( '0jr5f', nargs ) ); } if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) ); + throw new TypeError( format( '0jr5X', nin ) ); } if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) ); + throw new TypeError( format( '0jr5g', nout ) ); } narrays = nin + nout; if ( narrays === 0 ) { - throw new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' ); + throw new Error( format('0jr0h') ); } if ( nargs !== narrays ) { - throw new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' ); + throw new Error( format('0jr0i') ); } if ( fcn ) { nfcns = types.length / narrays; if ( !isInteger( nfcns ) ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format('0jr0j') ); } } else { nfcns = fcns.length; if ( types.length !== nfcns*narrays ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format('0jr0j') ); } } if ( data && data.length !== nfcns ) { - throw new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' ); + throw new Error( format('0jr0k') ); } types = types2enums( types ); return dispatcher; @@ -178,9 +178,9 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { argc = arguments.length; if ( argc !== nargs ) { if ( argc < nargs ) { - throw new Error( 'invalid invocation. Insufficient arguments.' ); + throw new Error( format('0jr0l') ); } - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('0jr0m') ); } arrays = []; dtypes = []; @@ -188,9 +188,9 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { v = arguments[ i ]; if ( !isndarrayLike( v ) ) { if ( i < nin ) { - throw new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) ); + throw new TypeError( format( '0jr5h', v ) ); } else { - throw new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) ); + throw new TypeError( format( '0jr5i', v ) ); } } arrays.push( v ); @@ -201,7 +201,7 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { // Check whether we were able to successfully resolve an ndarray function: if ( idx < 0 ) { - throw new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' ); + throw new TypeError( format('0jr0n') ); } // Retrieve the ndarray function: if ( fcn ) { diff --git a/package.json b/package.json index 4870cc2..b3f4488 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/assert-is-positive-integer": "^0.2.2", "@stdlib/ndarray-base-dtype-resolve-enum": "^0.2.2", "@stdlib/ndarray-dtype": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.3.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From d440121e2715bdb682b261d9fe6533d87e4c067c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 13:23:31 +0000 Subject: [PATCH 087/109] Remove files --- index.d.ts | 334 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5181 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index c49a4e4..0000000 --- a/index.d.ts +++ /dev/null @@ -1,334 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* ndarray function. -* -* @param arrays - array containing input and output ndarrays -* @param data - ndarray function data (e.g., a callback) -* -* @example -* var numel = require( '@stdlib/ndarray-base-numel' ); -* var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -* -* function ndarrayFcn( arrays, fcn ) { -* var xord; -* var yord; -* var opts; -* var sub; -* var sh; -* var N; -* var x; -* var y; -* var v; -* var i; -* -* x = arrays[ 0 ]; -* y = arrays[ 1 ]; -* sh = x.shape; -* N = numel( sh ); -* if ( N <= 0 ) { -* return; -* } -* xord = x.order; -* yord = y.order; -* opts = {}; -* opts.order = xord; -* for ( i = 0; i < N; i++ ) { -* // Convert a linear index to subscripts: -* opts.order = xord; -* sub = ind2sub( sh, i, opts ); -* -* // Retrieve an element from `x`: -* v = x.get.apply( x, sub ); -* -* // Convert a linear index to subscripts: -* opts.order = yord; -* sub = ind2sub( sh, i, opts ); -* -* // Append the result of applying the callback: -* sub.push( fcn( v ) ); -* -* // Assign the result to an element in `y`: -* y.set.apply( y, sub ); -* } -* } -*/ -type ndarrayFcn = ( arrays: Array, data?: any ) => void; - -/** -* Interface describing an ndarray function dispatcher. -*/ -interface Dispatcher { - /** - * Invokes an ndarray function based on the provided array data type(s). - * - * @param x - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array - * - * @example - * var nullary = require( '@stdlib/ndarray-base-nullary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function value() { - * return 3.14; - * } - * - * var types = [ 'float64' ]; - * var data = [ value ]; - * - * var fcn = dispatch( nullary, types, data, 1, 0, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( 5 ); - * var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x ); - * // xbuf => [ 3.14, 3.14, 3.14, 3.14, 3.14 ] - */ - ( x: ndarray ): ndarray | void; - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var unary = require( '@stdlib/ndarray-base-unary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * var abs = require( '@stdlib/math-base-special-abs' ); - * - * var types = [ 'float64', 'float64' ]; - * var data = [ abs ]; - * - * var fcn = dispatch( unary, types, data, 2, 1, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - * var ybuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y ); - * // ybuf => [ 1.0, 2.0, 3.0 ] - */ - ( x: ndarray, y: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var ternary = require( '@stdlib/ndarray-base-ternary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function add2( x, y ) { - * return x + y; - * } - * - * var types = [ 'float64', 'float64', 'float64' ]; - * var data = [ add2 ]; - * - * var fcn = dispatch( ternary, types, data, 3, 2, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z ); - * // zbuf => [ 2.0, 4.0, 6.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quaternary = require( '@stdlib/ndarray-base-quaternary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function add3( x, y, z ) { - * return x + y + z; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add3 ]; - * - * var fcn = dispatch( quaternary, types, data, 4, 3, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w ); - * // wbuf => [ 3.0, 6.0, 9.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @param args - ndarray arguments - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quinary = require( '@stdlib/ndarray-base-quinary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function add4( x, y, z, w ) { - * return x + y + z + w; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add4 ]; - * - * var fcn = dispatch( quinary, types, data, 5, 4, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ubuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var u = ndarray( 'float64', ubuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w, u ); - * // ubuf => [ 4.0, 8.0, 12.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray, ...args: Array ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures -} - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param fcns - list of ndarray functions -* @param types - one-dimensional list of ndarray argument data types -* @param data - ndarray function data (e.g., callbacks) -* @param nargs - total number of ndarray function interface arguments -* @param nin - number of input ndarrays -* @param nout - number of output ndarrays -* @throws first argument must be either a function or an array of functions -* @throws second argument must be an array-like object -* @throws third argument must be an array-like object or `null` -* @throws third and first arguments must have the same number of elements -* @throws fourth argument must be a positive integer -* @throws fifth argument must be a nonnegative integer -* @throws sixth argument must be a nonnegative integer -* @throws fourth argument must equal the specified number of input and output arrays -* @throws number of types must match the number of functions times the total number of array arguments for each function -* @throws interface must accept at least one input and/or output ndarray -* @returns ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var fcn = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* fcn( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function dispatch( fcns: ndarrayFcn | ArrayLike, types: ArrayLike, data: ArrayLike | null, nargs: number, nin: number, nout: number ): Dispatcher; - - -// EXPORTS // - -export = dispatch; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index a78f36a..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@v0.2.2-esm/index.mjs";function m(m,f,l,p,w,v){var a,g,c;if(i(m))c=m;else if(!s(m))throw new TypeError(d("0jr5d",m));if(!n(f))throw new TypeError(d("0jr2y",f));if(!n(l)&&null!==l)throw new TypeError(d("0jr5e",l));if(!e(p))throw new TypeError(d("0jr5f",p));if(!r(w))throw new TypeError(d("0jr5X",w));if(!r(v))throw new TypeError(d("0jr5g",v));if(0===(a=w+v))throw new Error(d("0jr0h"));if(p!==a)throw new Error(d("0jr0i"));if(c){if(g=f.length/a,!t(g))throw new Error(d("0jr0j"))}else if(g=m.length,f.length!==g*a)throw new Error(d("0jr0j"));if(l&&l.length!==g)throw new Error(d("0jr0k"));return f=function(r){var e,t;for(e=[],t=0;t [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0jr5d', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0jr2y', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( '0jr5e', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0jr5f', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0jr5X', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0jr5g', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format('0jr0h') );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format('0jr0i') );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format('0jr0k') );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format('0jr0l') );\n\t\t\t}\n\t\t\tthrow new Error( format('0jr0m') );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( '0jr5h', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( '0jr5i', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format('0jr0n') );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found).\n*\n* ## Notes\n*\n* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types).\n* - The function assumes that `x` is stored in row-major order.\n* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`.\n* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value.\n*\n* @private\n* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension)\n* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension)\n* @param {ArrayLikeObject} x - input two-dimensional reference array\n* @param {integer} strideX1 - `x` stride length along first dimension\n* @param {integer} strideX2 - `x` stride length along second dimension\n* @param {NonNegativeInteger} offsetX - `x` starting index\n* @param {ArrayLikeObject} y - search array\n* @param {integer} strideY - `y` stride length\n* @param {NonNegativeInteger} offsetY - `y` starting index\n* @returns {integer} row index (if found) and `-1` otherwise\n*\n* @example\n* // Define a reference array to search:\n* var types = [\n* 'float64', 'float64', 'float64',\n* 'float32', 'float32', 'float32',\n* 'uint32', 'uint32', 'float64',\n* 'int32', 'int32', 'float64',\n* 'uint16', 'uint16', 'float64',\n* 'int16', 'int16', 'float64',\n* 'uint8', 'uint8', 'float64',\n* 'int8', 'int8', 'float64'\n* ];\n*\n* // Define reference array dimensions:\n* var N = 8; // rows\n* var M = 3; // columns\n*\n* // Define a search array:\n* y1 = [\n* 'float32', 'float32', 'float32',\n* ];\n*\n* // Find the list of types:\n* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 );\n* // returns 1\n*\n// Define a search array:\n* y2 = [\n* 'float32', 'float32', 'float64',\n* ];\n*\n* // Find the list of types:\n* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 );\n* // returns -1\n*/\nfunction indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len\n\tvar ix;\n\tvar iy;\n\tvar i;\n\tvar j;\n\n\t// Search for the first row which matches `y`...\n\tix = offsetX;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tiy = offsetY;\n\t\tfor ( j = 0; j < M; j++ ) {\n\t\t\tif ( x[ ix+(j*strideX2) ] !== y[ iy ] ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tiy += strideY;\n\t\t}\n\t\t// If we successfully iterated over all columns, then that means we've found a match...\n\t\tif ( j === M ) {\n\t\t\treturn i;\n\t\t}\n\t\tix += strideX1;\n\t}\n\treturn -1;\n}\n\n\n// EXPORTS //\n\nexport default indexOfTypes;\n"],"names":["dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","out","i","push","resolveEnum","types2enums","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","getDType","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","j","indexOfTypes","slice"],"mappings":";;0+BA0GA,SAASA,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAO,UAEzB,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAO,UAEzB,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAO,eAIzB,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAO,UAG1B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAO,UAGzB,OADAX,EA5GD,SAAsBA,GACrB,IAAIkB,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAInB,EAAMgB,OAAQG,IAC9BD,EAAIE,KAAMC,EAAarB,EAAOmB,KAE/B,OAAOD,CACR,CAmGSI,CAAatB,GAgBrB,WACC,IAAIuB,EACAC,EACAC,EACAC,EACAC,EACAC,EACAT,EAGJ,GADAM,EAAOI,UAAUb,OACZS,IAASvB,EAAQ,CACrB,GAAKuB,EAAOvB,EACX,MAAM,IAAIa,MAAOJ,EAAO,UAEzB,MAAM,IAAII,MAAOJ,EAAO,SACxB,CAGD,IAFAY,EAAS,GACTC,EAAS,GACHL,EAAI,EAAGA,EAAIjB,EAAOiB,IAAM,CAE7B,IAAMW,EADNH,EAAIE,UAAWV,IAEd,MAAKA,EAAIhB,EACF,IAAIO,UAAWC,EAAQ,QAASgB,IAEhC,IAAIjB,UAAWC,EAAQ,QAASgB,IAGxCJ,EAAOH,KAAMO,GACbH,EAAOJ,KAAMC,EAAaU,EAAUJ,IACpC,CAKD,IAHAD,EC1HF,SAAuBM,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAvB,EACAwB,EAIJ,IADAF,EAAKJ,EACClB,EAAI,EAAGA,EAAIa,EAAGb,IAAM,CAEzB,IADAuB,EAAKF,EACCG,EAAI,EAAGA,EAAIV,GACXC,EAAGO,EAAIE,EAAEP,KAAgBE,EAAGI,GADdC,IAInBD,GAAMH,EAGP,GAAKI,IAAMV,EACV,OAAOd,EAERsB,GAAMN,CACN,CACD,OAAQ,CACT,CDmGQS,CAActC,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGmB,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAId,UAAWC,EAAO,UAI5BiB,EADIrB,GAGAR,EAAM2B,GAGNzB,EACJ2B,EAAGL,EAAQtB,EAAMyB,IAEjBE,EAAGL,GAEJ,GAAc,IAATnB,EACJ,OAAOmB,EAAQlB,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOmB,EAAOsB,MAAO1C,EACrB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index f17fdd8..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 28ae3dca79b35e379d1967de6cf40b47a91cc0c6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Aug 2024 13:24:05 +0000 Subject: [PATCH 088/109] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 138 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 61 +- SECURITY.md | 5 - benchmark/benchmark.dispatch_size.js | 156 - benchmark/benchmark.js | 81 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 87 - docs/types/test.ts | 641 --- examples/add.js | 121 - examples/sin.js | 142 - examples/unary.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/index_of_types.js | 106 - lib/main.js | 231 - package.json | 79 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/binary.js | 38 - test/fixtures/fill.js | 76 - test/fixtures/foreach.js | 72 - test/fixtures/map1n.js | 74 - test/fixtures/nullary.js | 36 - test/fixtures/quaternary.js | 40 - test/fixtures/quinary.js | 41 - test/fixtures/sum.js | 98 - test/fixtures/ternary.js | 39 - test/test.js | 363 -- test/test.two_arrays.js | 814 ---- 57 files changed, 4876 insertions(+), 6911 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.dispatch_size.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/add.js delete mode 100644 examples/sin.js delete mode 100644 examples/unary.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/index_of_types.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/fixtures/binary.js delete mode 100644 test/fixtures/fill.js delete mode 100644 test/fixtures/foreach.js delete mode 100644 test/fixtures/map1n.js delete mode 100644 test/fixtures/nullary.js delete mode 100644 test/fixtures/quaternary.js delete mode 100644 test/fixtures/quinary.js delete mode 100644 test/fixtures/sum.js delete mode 100644 test/fixtures/ternary.js delete mode 100644 test/test.js delete mode 100644 test/test.two_arrays.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 9122b64..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-08-01T06:11:42.766Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ac0b7cd..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 5e92c3e..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2b4fac7..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '43 7 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -304,7 +295,7 @@ console.log( ybuf ); ## 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. +This package is part of [stdlib][stdlib], a standard library 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]. @@ -367,11 +358,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-dispatch/main/LICENSE -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.dispatch_size.js b/benchmark/benchmark.dispatch_size.js deleted file mode 100644 index 15805ba..0000000 --- a/benchmark/benchmark.dispatch_size.js +++ /dev/null @@ -1,156 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib/main.js' ); - - -// FUNCTIONS // - -/** -* Evaluates the identity function. -* -* @private -* @param {*} v - value -* @returns {*} input value -*/ -function identity( v ) { - return v; -} - -/** -* Dummy function which throws an error. -* -* @private -* @throws {Error} unexpected error -*/ -function throwError() { - throw new Error( 'unexpected error' ); -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} size - dispatch size -* @returns {Function} benchmark function -*/ -function createBenchmark( size ) { - var types; - var data; - var fcn; - var x; - var y; - var t; - var i; - - types = []; - - // Create dummy types... - for ( i = 0; i < (size-1)*2; i += 2 ) { - t = 'foo' + i; - types.push( t ); - types.push( t ); - } - // Append test types: - types.push( 'float64' ); - types.push( 'float64' ); - - // Define a list of callbacks: - data = []; - for ( i = 0; i < size-1; i++ ) { - data.push( throwError ); - } - // Append a test callback: - data.push( identity ); - - // Create the dispatcher: - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - // Create sample arrays: - x = new Float64Array( 1 ); - y = new Float64Array( x.length ); - - x = ndarray( 'float64', x, [ 1 ], [ 1 ], 0, 'row-major' ); - y = ndarray( 'float64', y, [ 1 ], [ 1 ], 0, 'row-major' ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var z; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x.data[ 0 ] = i; - z = fcn( x, y ); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var size; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - size = pow( 2, i ); - f = createBenchmark( size ); - bench( pkg+':size='+size, f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 3c6f450..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::fcns_array', function benchmark( b ) { - var types; - var fcns; - var data; - var out; - var i; - - fcns = [ unary ]; - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( fcns, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::fcn_arg', function benchmark( b ) { - var types; - var data; - var out; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( unary, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0aae4af..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch" -%% click B href "https://github.com/stdlib-js/ndarray-dispatch/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-dispatch/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-dispatch/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-dispatch/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-dispatch/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch -[production-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 1295a44..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import dispatch from '../docs/types/index'; -export = dispatch; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c23dc5d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var y=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var b=y(function(D,w){"use strict";function k(i,r,e,u,f,m,n,o,l){var h,t,s,a;for(h=m,s=0;s [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( 'invalid invocation. Insufficient arguments.' );\n\t\t\t}\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = dispatch;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an ndarray function interface which performs multiple dispatch.\n*\n* @module @stdlib/ndarray-dispatch\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var unary = require( '@stdlib/ndarray-base-unary' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var Float64Array = require( '@stdlib/array-float64' );\n* var dispatch = require( '@stdlib/ndarray-dispatch' );\n*\n* var types = [\n* 'float64', 'float64'\n* ];\n*\n* var data = [\n* abs\n* ];\n*\n* var absolute = dispatch( unary, types, data, 2, 1, 1 );\n*\n* // ...\n*\n* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] );\n* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] );\n*\n* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' );\n* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' );\n*\n* absolute( x, y );\n* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA6EA,SAASC,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,EAAU,CAClF,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,CAAU,IAAME,EAAGI,CAAG,EADjBE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,CACP,CACA,MAAO,EACR,CAKAL,EAAO,QAAUC,ICzGjB,IAAAc,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAoB,QAAS,oCAAqC,EAClEC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAkB,QAAS,kCAAmC,EAC9DC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAc,QAAS,yCAA0C,EACjEC,EAAe,IAYnB,SAASC,EAAaC,EAAQ,CAC7B,IAAIC,EACAC,EAGJ,IADAD,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIF,EAAM,OAAQE,IAC9BD,EAAI,KAAMJ,EAAaG,EAAOE,CAAE,CAAE,CAAE,EAErC,OAAOD,CACR,CAqDA,SAASE,EAAUC,EAAMJ,EAAOK,EAAMC,EAAOC,EAAKC,EAAO,CACxD,IAAIC,EACAC,EACAC,EAEJ,GAAKnB,EAAYY,CAAK,EACrBO,EAAMP,UACK,CAACb,EAAiBa,CAAK,EAClC,MAAM,IAAI,UAAWT,EAAQ,oGAAqGS,CAAK,CAAE,EAE1I,GAAK,CAACX,EAAcO,CAAM,EACzB,MAAM,IAAI,UAAWL,EAAQ,+EAAgFK,CAAM,CAAE,EAEtH,GAAK,CAACP,EAAcY,CAAK,GAAKA,IAAS,KACtC,MAAM,IAAI,UAAWV,EAAQ,sFAAuFU,CAAK,CAAE,EAE5H,GAAK,CAAChB,EAAmBiB,CAAM,EAC9B,MAAM,IAAI,UAAWX,EAAQ,6EAA8EW,CAAM,CAAE,EAEpH,GAAK,CAAClB,EAAsBmB,CAAI,EAC/B,MAAM,IAAI,UAAWZ,EAAQ,+EAAgFY,CAAI,CAAE,EAEpH,GAAK,CAACnB,EAAsBoB,CAAK,EAChC,MAAM,IAAI,UAAWb,EAAQ,+EAAgFa,CAAK,CAAE,EAGrH,GADAC,EAAUF,EAAMC,EACXC,IAAY,EAChB,MAAM,IAAI,MAAO,4IAA6I,EAE/J,GAAKH,IAAUG,EACd,MAAM,IAAI,MAAO,4FAA6F,EAE/G,GAAKE,GAEJ,GADAD,EAAQV,EAAM,OAASS,EAClB,CAACnB,EAAWoB,CAAM,EACtB,MAAM,IAAI,MAAO,8IAA+I,UAGjKA,EAAQN,EAAK,OACRJ,EAAM,SAAWU,EAAMD,EAC3B,MAAM,IAAI,MAAO,8IAA+I,EAGlK,GAAKJ,GAAQA,EAAK,SAAWK,EAC5B,MAAM,IAAI,MAAO,mGAAoG,EAEtH,OAAAV,EAAQD,EAAaC,CAAM,EACpBY,EAeP,SAASA,GAAa,CACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EAGJ,GADAa,EAAO,UAAU,OACZA,IAAST,EACb,MAAKS,EAAOT,EACL,IAAI,MAAO,6CAA8C,EAE1D,IAAI,MAAO,yCAA0C,EAI5D,IAFAO,EAAS,CAAC,EACVC,EAAS,CAAC,EACJZ,EAAI,EAAGA,EAAII,EAAOJ,IAAM,CAE7B,GADAe,EAAI,UAAWf,CAAE,EACZ,CAACR,EAAeuB,CAAE,EACtB,MAAKf,EAAIK,EACF,IAAI,UAAWZ,EAAQ,6EAA8EsB,CAAE,CAAE,EAEzG,IAAI,UAAWtB,EAAQ,8EAA+EsB,CAAE,CAAE,EAGlHJ,EAAO,KAAMI,CAAE,EACfH,EAAO,KAAMjB,EAAaD,EAAUqB,CAAE,CAAE,CAAE,CAC3C,CAKA,GAHAD,EAAMlB,EAAcY,EAAOD,EAAST,EAAOS,EAAS,EAAG,EAAGK,EAAQ,EAAG,CAAE,EAGlEE,EAAM,EACV,MAAM,IAAI,UAAW,6GAA8G,EAcpI,GAXKL,EACJO,EAAIP,EAEJO,EAAId,EAAMY,CAAI,EAGVX,EACJa,EAAGL,EAAQR,EAAMW,CAAI,CAAE,EAEvBE,EAAGL,CAAO,EAENL,IAAS,EACb,OAAOK,EAAQJ,EAAQ,CAAE,EAE1B,GAAKD,IAAS,EAGd,OAAOK,EAAO,MAAON,CAAI,CAC1B,CACD,CAKApB,EAAO,QAAUgB,IC9KjB,IAAIgB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_index_of_types", "__commonJSMin", "exports", "module", "indexOfTypes", "N", "M", "x", "strideX1", "strideX2", "offsetX", "y", "strideY", "offsetY", "ix", "iy", "i", "j", "require_main", "__commonJSMin", "exports", "module", "isNonNegativeInteger", "isPositiveInteger", "isInteger", "isFunctionArray", "isFunction", "isCollection", "isndarrayLike", "format", "getDType", "resolveEnum", "indexOfTypes", "types2enums", "types", "out", "i", "dispatch", "fcns", "data", "nargs", "nin", "nout", "narrays", "nfcns", "fcn", "dispatcher", "arrays", "dtypes", "argc", "idx", "v", "f", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 02fe150..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,87 +0,0 @@ - -{{alias}}( fcns, types, data, nargs, nin, nout ) - Returns an ndarray function interface which performs multiple dispatch. - - An ndarray function interface has the following signature: - - f( x, y, ... ) - - where - - - x: ndarray. - - y: ndarray. - - ...: additional ndarrays. - - The number of parameters is derived from `nargs`, the number of input - ndarrays is derived from `nin`, and the number of output ndarrays is derived - from `nout`. - - Parameters - ---------- - fcns: Function|ArrayLikeObject - List of ndarray functions. An ndarray function should have the following - signature: - - f( arrays, data ) - - where - - - arrays: array containing input and output ndarrays. - - data: ndarray function data (e.g., a callback). - - For convenience, a single ndarray function may be provided which will be - invoked whenever the ndarray argument data types match a sequence of - types in `types`. Providing a single ndarray function is particularly - convenient for the case where, regardless of array data types, - traversing arrays remains the same, but the ndarray function `data` - differs (e.g., callbacks which differ based on the array data types). - - types: ArrayLikeObject - One-dimensional list of ndarray argument data types. - - data: ArrayLikeObject|null - ndarray function data (e.g., callbacks). If `null`, a returned ndarray - function interface does **not** provide a `data` argument to an invoked - ndarray function. - - nargs: integer - Total number of ndarray function interface arguments. - - nin: integer - Number of input ndarrays. - - nout: integer - Number of output ndarrays. - - Returns - ------- - fcn: Function - ndarray function interface. - - Examples - -------- - // Define ndarray argument data types: - > var t = [ 'float64', 'float64', 'float32', 'float32' ]; - - // Define a list of ndarray function data (callbacks): - > var d = [ {{alias:@stdlib/math/base/special/abs}}, {{alias:@stdlib/math/base/special/absf}} ]; - - // Create an ndarray function interface for applying unary callbacks: - > var f = {{alias}}( {{alias:@stdlib/ndarray/base/unary}}, t, d, 2, 1, 1 ); - - // Create an input ndarray: - > var xbuf = new {{alias:@stdlib/array/float64}}( [ -1.0, -2.0, -3.0, -4.0 ] ); - > var x = {{alias:@stdlib/ndarray/ctor}}( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Create an output ndarray: - > var ybuf = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 0.0, 0.0 ] ); - > var y = {{alias:@stdlib/ndarray/ctor}}( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Compute the element-wise absolute value: - > f( x, y ); - > ybuf - [ 1.0, 2.0, 3.0, 4.0 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 3cba031..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,641 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable max-lines */ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import dispatch = require( './index' ); - - -// FUNCTIONS // - -/** -* Nullary callback. -* -* @return input value -*/ -function nullary(): any { - return 5.0; -} - -/** -* Unary callback. -* -* @param x - input value -* @return input value -*/ -function unary( x: any ): any { - return x; -} - -/** -* Binary callback. -* -* @param x - input value -* @param y - input value -* @return output value -*/ -function binary( x: number, y: number ): number { - return x + y; -} - -/** -* Ternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @return output value -*/ -function ternary( x: number, y: number, z: number ): number { - return x + y + z; -} - -/** -* Quaternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @param w - input value -* @return output value -*/ -function quaternary( x: number, y: number, z: number, w: number ): number { - return x + y + z + w; -} - -/** -* Mock `ind2sub` function. -* -* @param shape - dimensions -* @param idx - linear index -* @param opts - options -* @return subscripts -*/ -function ind2sub( shape: ArrayLike, idx: number, opts?: any ): Array { - let out; - let i; - - out = []; - if ( typeof opts === 'object' && opts !== null && opts.order === 'row-major' ) { no-unsafe-any - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } else { - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } - return out; -} - -/** -* Mock ndarray function. -* -* @param arrays - ndarrays -* @param fcn - callback -*/ -function ndarrayFcn( arrays: Array, fcn: ( x: any ) => any ): void { - let xord; - let yord; - let opts; - let sub; - let sh; - let N; - let x; - let y; - let v; - let i; - - x = arrays[ 0 ]; - y = arrays[ 1 ]; - sh = x.shape; - if ( sh.length === 0 ) { - return; - } - N = 1; - for ( i = 0; i < sh.length; i += 1 ) { - N *= sh[ i ]; - } - xord = x.order; - yord = y.order; - opts = { - 'order': '' - }; - opts.order = xord; - for ( i = 0; i < N; i += 1 ) { - // Convert a linear index to subscripts: - opts.order = xord; - sub = ind2sub( sh, i, opts ); - - // Retrieve an element from `x`: - v = x.get.apply( x, sub ); - - // Convert a linear index to subscripts: - opts.order = yord; - sub = ind2sub( sh, i, opts ); - - // Append the result of applying the callback: - sub[ sub.length ] = fcn( v ) as number; - - // Assign the result to an element in `y`: - y.set.apply( y, sub ); - } -} - -/** -* Mock function to create an ndarray-like object. -* -* @return ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a dispatch function... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, 1 ); // $ExpectType Dispatcher - dispatch( [ ndarrayFcn ], types, data, 2, 1, 1 ); // $ExpectType Dispatcher -} - -// The compiler throws an error if the function is provided a first argument which is not either an ndarray function or an array-like object containing ndarray functions... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( '10', types, data, 2, 1, 1 ); // $ExpectError - dispatch( 10, types, data, 2, 1, 1 ); // $ExpectError - dispatch( true, types, data, 2, 1, 1 ); // $ExpectError - dispatch( false, types, data, 2, 1, 1 ); // $ExpectError - dispatch( null, types, data, 2, 1, 1 ); // $ExpectError - dispatch( undefined, types, data, 2, 1, 1 ); // $ExpectError - dispatch( [ '1' ], types, data, 2, 1, 1 ); // $ExpectError - dispatch( {}, types, data, 2, 1, 1 ); // $ExpectError - dispatch( ( x: number ): number => x, types, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object... -{ - const data = [ unary ]; - - dispatch( ndarrayFcn, 10, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, true, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, false, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, null, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, undefined, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, {}, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object or null... -{ - const types = [ 'float64', 'float64' ]; - - dispatch( ndarrayFcn, types, 10, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, true, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, false, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, undefined, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, {}, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, '10', 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, true, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, false, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, null, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, undefined, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, [ '1' ], 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, {}, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, ( x: number ): number => x, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, '10', 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, true, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, false, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, null, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, undefined, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, [ '1' ], 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, {}, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, ( x: number ): number => x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, '10' ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, true ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, false ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, null ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, undefined ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, [ '1' ] ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, {} ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch(); // $ExpectError - dispatch( ndarrayFcn ); // $ExpectError - dispatch( ndarrayFcn, types ); // $ExpectError - dispatch( ndarrayFcn, types, data ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, 1, 0 ); // $ExpectError -} - -// The function returns a dispatch function... -{ - const x = array(); - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const t1 = [ 'float64' ]; - const d1 = [ nullary ]; - const f1 = dispatch( ndarrayFcn, t1, d1, 1, 1, 0 ); - f1( x ); // $ExpectType void | ndarray - - const t2 = [ 'float64', 'float64' ]; - const d2 = [ unary ]; - const f2 = dispatch( ndarrayFcn, t2, d2, 2, 1, 1 ); - f2( x, y ); // $ExpectType void | ndarray - - const t3 = [ 'float64', 'float64', 'float64' ]; - const d3 = [ binary ]; - const f3 = dispatch( ndarrayFcn, t3, d3, 3, 2, 1 ); - f3( x, y, z ); // $ExpectType void | ndarray - - const t4 = [ 'float64', 'float64', 'float64', 'float64' ]; - const d4 = [ ternary ]; - const f4 = dispatch( ndarrayFcn, t4, d4, 4, 3, 1 ); - f4( x, y, z, w ); // $ExpectType void | ndarray - - const t5 = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const d5 = [ quaternary ]; - const f5 = dispatch( ndarrayFcn, t5, d5, 5, 4, 1 ); - f5( x, y, z, w, u ); // $ExpectType void | ndarray -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (1 ndarray)... -{ - const types = [ 'float64' ]; - const data = [ nullary ]; - - const f = dispatch( ndarrayFcn, types, data, 1, 0, 1 ); - f( '10' ); // $ExpectError - f( 10 ); // $ExpectError - f( true ); // $ExpectError - f( false ); // $ExpectError - f( null ); // $ExpectError - f( undefined ); // $ExpectError - f( [ '1' ] ); // $ExpectError - f( {} ); // $ExpectError - f( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( 10, y ); // $ExpectError - f( '10', y ); // $ExpectError - f( true, y ); // $ExpectError - f( false, y ); // $ExpectError - f( null, y ); // $ExpectError - f( undefined, y ); // $ExpectError - f( [ '1' ], y ); // $ExpectError - f( {}, y ); // $ExpectError - f( ( x: number ): number => x, y ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const x = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( x, 10 ); // $ExpectError - f( x, '10' ); // $ExpectError - f( x, true ); // $ExpectError - f( x, false ); // $ExpectError - f( x, null ); // $ExpectError - f( x, undefined ); // $ExpectError - f( x, [ '1' ] ); // $ExpectError - f( x, {} ); // $ExpectError - f( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( 10, y, z ); // $ExpectError - f( '10', y, z ); // $ExpectError - f( true, y, z ); // $ExpectError - f( false, y, z ); // $ExpectError - f( null, y, z ); // $ExpectError - f( undefined, y, z ); // $ExpectError - f( [ '1' ], y, z ); // $ExpectError - f( {}, y, z ); // $ExpectError - f( ( x: number ): number => x, y, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, 10, z ); // $ExpectError - f( x, '10', z ); // $ExpectError - f( x, true, z ); // $ExpectError - f( x, false, z ); // $ExpectError - f( x, null, z ); // $ExpectError - f( x, undefined, z ); // $ExpectError - f( x, [ '1' ], z ); // $ExpectError - f( x, {}, z ); // $ExpectError - f( x, ( x: number ): number => x, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, y, '10' ); // $ExpectError - f( x, y, true ); // $ExpectError - f( x, y, false ); // $ExpectError - f( x, y, null ); // $ExpectError - f( x, y, undefined ); // $ExpectError - f( x, y, [ '1' ] ); // $ExpectError - f( x, y, {} ); // $ExpectError - f( x, y, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( 10, y, z, w ); // $ExpectError - f( '10', y, z, w ); // $ExpectError - f( true, y, z, w ); // $ExpectError - f( false, y, z, w ); // $ExpectError - f( null, y, z, w ); // $ExpectError - f( undefined, y, z, w ); // $ExpectError - f( [ '1' ], y, z, w ); // $ExpectError - f( {}, y, z, w ); // $ExpectError - f( ( x: number ): number => x, y, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, 10, z, w ); // $ExpectError - f( x, '10', z, w ); // $ExpectError - f( x, true, z, w ); // $ExpectError - f( x, false, z, w ); // $ExpectError - f( x, null, z, w ); // $ExpectError - f( x, undefined, z, w ); // $ExpectError - f( x, [ '1' ], z, w ); // $ExpectError - f( x, {}, z, w ); // $ExpectError - f( x, ( x: number ): number => x, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, 10, w ); // $ExpectError - f( x, y, '10', w ); // $ExpectError - f( x, y, true, w ); // $ExpectError - f( x, y, false, w ); // $ExpectError - f( x, y, null, w ); // $ExpectError - f( x, y, undefined, w ); // $ExpectError - f( x, y, [ '1' ], w ); // $ExpectError - f( x, y, {}, w ); // $ExpectError - f( x, y, ( x: number ): number => x, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, z, 10 ); // $ExpectError - f( x, y, z, '10' ); // $ExpectError - f( x, y, z, true ); // $ExpectError - f( x, y, z, false ); // $ExpectError - f( x, y, z, null ); // $ExpectError - f( x, y, z, undefined ); // $ExpectError - f( x, y, z, [ '1' ] ); // $ExpectError - f( x, y, z, {} ); // $ExpectError - f( x, y, z, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( 10, y, z, w, u ); // $ExpectError - f( '10', y, z, w, u ); // $ExpectError - f( true, y, z, w, u ); // $ExpectError - f( false, y, z, w, u ); // $ExpectError - f( null, y, z, w, u ); // $ExpectError - f( undefined, y, z, w, u ); // $ExpectError - f( [ '1' ], y, z, w, u ); // $ExpectError - f( {}, y, z, w, u ); // $ExpectError - f( ( x: number ): number => x, y, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, 10, z, w, u ); // $ExpectError - f( x, '10', z, w, u ); // $ExpectError - f( x, true, z, w, u ); // $ExpectError - f( x, false, z, w, u ); // $ExpectError - f( x, null, z, w, u ); // $ExpectError - f( x, undefined, z, w, u ); // $ExpectError - f( x, [ '1' ], z, w, u ); // $ExpectError - f( x, {}, z, w, u ); // $ExpectError - f( x, ( x: number ): number => x, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, 10, w, u ); // $ExpectError - f( x, y, '10', w, u ); // $ExpectError - f( x, y, true, w, u ); // $ExpectError - f( x, y, false, w, u ); // $ExpectError - f( x, y, null, w, u ); // $ExpectError - f( x, y, undefined, w, u ); // $ExpectError - f( x, y, [ '1' ], w, u ); // $ExpectError - f( x, y, {}, w, u ); // $ExpectError - f( x, y, ( x: number ): number => x, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, 10, u ); // $ExpectError - f( x, y, z, '10', u ); // $ExpectError - f( x, y, z, true, u ); // $ExpectError - f( x, y, z, false, u ); // $ExpectError - f( x, y, z, null, u ); // $ExpectError - f( x, y, z, undefined, u ); // $ExpectError - f( x, y, z, [ '1' ], u ); // $ExpectError - f( x, y, z, {}, u ); // $ExpectError - f( x, y, z, ( x: number ): number => x, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fifth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, w, 10 ); // $ExpectError - f( x, y, z, w, '10' ); // $ExpectError - f( x, y, z, w, true ); // $ExpectError - f( x, y, z, w, false ); // $ExpectError - f( x, y, z, w, null ); // $ExpectError - f( x, y, z, w, undefined ); // $ExpectError - f( x, y, z, w, [ '1' ] ); // $ExpectError - f( x, y, z, w, {} ); // $ExpectError - f( x, y, z, w, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/add.js b/examples/add.js deleted file mode 100644 index 775b711..0000000 --- a/examples/add.js +++ /dev/null @@ -1,121 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var dispatch = require( './../lib' ); - -function add2( arrays ) { - var opts; - var xo; - var yo; - var zo; - var sx; - var sy; - var sz; - var sh; - var N; - var x; - var y; - var z; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - z = arrays[ 2 ]; - xo = x.order; - yo = y.order; - zo = z.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - opts.order = yo; - sy = ind2sub( sh, i, opts ); - v = x.get.apply( x, sx ) + y.get.apply( y, sy ); - - opts.order = zo; - sz = ind2sub( sh, i, opts ); - sz.push( v ); - z.set.apply( z, sz ); - } -} - -var fcns = [ - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2 -]; - -var types = [ - dtypes.float64, dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.int32, dtypes.int32, - dtypes.uint32, dtypes.uint32, dtypes.uint32, - dtypes.int16, dtypes.int16, dtypes.int16, - dtypes.uint16, dtypes.uint16, dtypes.uint16, - dtypes.int8, dtypes.int8, dtypes.int8, - dtypes.uint8, dtypes.uint8, dtypes.uint8, - dtypes.uint8c, dtypes.uint8c, dtypes.uint8c -]; - -var add = dispatch( fcns, types, null, 3, 2, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var zbuf = new Float64Array( xbuf.length ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var z = ndarray( 'float64', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); - -xbuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -ybuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -zbuf = new Int32Array( xbuf.length ); - -x = ndarray( 'int32', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'int32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -z = ndarray( 'int32', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); diff --git a/examples/sin.js b/examples/sin.js deleted file mode 100644 index 8cd4871..0000000 --- a/examples/sin.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int8Array = require( '@stdlib/array-int8' ); -var sin = require( '@stdlib/math-base-special-sin' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/strided-dtypes' ); -var dispatch = require( './../lib' ); - -function apply( arrays, fcn ) { - var opts; - var xo; - var yo; - var sx; - var sy; - var sh; - var N; - var x; - var y; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - xo = x.order; - yo = y.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - v = fcn( x.get.apply( x, sx ) ); - - opts.order = yo; - sy = ind2sub( sh, i, opts ); - sy.push( v ); - y.set.apply( y, sy ); - } -} - -var fcns = [ - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply -]; - -var types = [ - dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float64, - dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.float64, - dtypes.uint32, dtypes.float64, - dtypes.int16, dtypes.float64, - dtypes.int16, dtypes.float32, - dtypes.uint16, dtypes.float64, - dtypes.uint16, dtypes.float32, - dtypes.int8, dtypes.float64, - dtypes.int8, dtypes.float32, - dtypes.uint8, dtypes.float64, - dtypes.uint8, dtypes.float32, - dtypes.uint8c, dtypes.float64, - dtypes.uint8c, dtypes.float32 -]; - -var data = [ - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin -]; - -var sine = dispatch( fcns, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); - -xbuf = new Int8Array( [ 1, 2, 3, 4, 5 ] ); -ybuf = new Float32Array( xbuf.length ); - -x = ndarray( 'int8', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'float32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); diff --git a/examples/unary.js b/examples/unary.js deleted file mode 100644 index e9c3fb4..0000000 --- a/examples/unary.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -var unary = require( '@stdlib/ndarray-base-unary' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var dispatch = require( './../lib' ); - -var types = [ 'float64', 'float64' ]; - -var data = [ - abs -]; - -var absolute = dispatch( unary, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -absolute( x, y ); -console.log( ybuf ); -// => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 5f280a1..c49a4e4 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..17b911b --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@v0.2.2-esm/index.mjs";function m(m,f,l,p,w,v){var a,g,c;if(i(m))c=m;else if(!s(m))throw new TypeError(d("0jr5d",m));if(!n(f))throw new TypeError(d("0jr2y",f));if(!n(l)&&null!==l)throw new TypeError(d("0jr5e",l));if(!e(p))throw new TypeError(d("0jr5f",p));if(!r(w))throw new TypeError(d("0jr5X",w));if(!r(v))throw new TypeError(d("0jr5g",v));if(0===(a=w+v))throw new Error(d("0jr0h"));if(p!==a)throw new Error(d("0jr0i"));if(c){if(g=f.length/a,!t(g))throw new Error(d("0jr0j"))}else if(g=m.length,f.length!==g*a)throw new Error(d("0jr0j"));if(l&&l.length!==g)throw new Error(d("0jr0k"));return f=function(r){var e,t;for(e=[],t=0;t [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0jr5d', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0jr2y', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( '0jr5e', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0jr5f', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0jr5X', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0jr5g', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format('0jr0h') );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format('0jr0i') );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format('0jr0k') );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format('0jr0l') );\n\t\t\t}\n\t\t\tthrow new Error( format('0jr0m') );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( '0jr5h', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( '0jr5i', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format('0jr0n') );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found).\n*\n* ## Notes\n*\n* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types).\n* - The function assumes that `x` is stored in row-major order.\n* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`.\n* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value.\n*\n* @private\n* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension)\n* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension)\n* @param {ArrayLikeObject} x - input two-dimensional reference array\n* @param {integer} strideX1 - `x` stride length along first dimension\n* @param {integer} strideX2 - `x` stride length along second dimension\n* @param {NonNegativeInteger} offsetX - `x` starting index\n* @param {ArrayLikeObject} y - search array\n* @param {integer} strideY - `y` stride length\n* @param {NonNegativeInteger} offsetY - `y` starting index\n* @returns {integer} row index (if found) and `-1` otherwise\n*\n* @example\n* // Define a reference array to search:\n* var types = [\n* 'float64', 'float64', 'float64',\n* 'float32', 'float32', 'float32',\n* 'uint32', 'uint32', 'float64',\n* 'int32', 'int32', 'float64',\n* 'uint16', 'uint16', 'float64',\n* 'int16', 'int16', 'float64',\n* 'uint8', 'uint8', 'float64',\n* 'int8', 'int8', 'float64'\n* ];\n*\n* // Define reference array dimensions:\n* var N = 8; // rows\n* var M = 3; // columns\n*\n* // Define a search array:\n* y1 = [\n* 'float32', 'float32', 'float32',\n* ];\n*\n* // Find the list of types:\n* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 );\n* // returns 1\n*\n// Define a search array:\n* y2 = [\n* 'float32', 'float32', 'float64',\n* ];\n*\n* // Find the list of types:\n* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 );\n* // returns -1\n*/\nfunction indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len\n\tvar ix;\n\tvar iy;\n\tvar i;\n\tvar j;\n\n\t// Search for the first row which matches `y`...\n\tix = offsetX;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tiy = offsetY;\n\t\tfor ( j = 0; j < M; j++ ) {\n\t\t\tif ( x[ ix+(j*strideX2) ] !== y[ iy ] ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tiy += strideY;\n\t\t}\n\t\t// If we successfully iterated over all columns, then that means we've found a match...\n\t\tif ( j === M ) {\n\t\t\treturn i;\n\t\t}\n\t\tix += strideX1;\n\t}\n\treturn -1;\n}\n\n\n// EXPORTS //\n\nexport default indexOfTypes;\n"],"names":["dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","out","i","push","resolveEnum","types2enums","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","getDType","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","j","indexOfTypes","slice"],"mappings":";;0+BA0GA,SAASA,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAO,UAEzB,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAO,UAEzB,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAO,eAIzB,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAO,UAG1B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAO,UAGzB,OADAX,EA5GD,SAAsBA,GACrB,IAAIkB,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAInB,EAAMgB,OAAQG,IAC9BD,EAAIE,KAAMC,EAAarB,EAAOmB,KAE/B,OAAOD,CACR,CAmGSI,CAAatB,GAgBrB,WACC,IAAIuB,EACAC,EACAC,EACAC,EACAC,EACAC,EACAT,EAGJ,GADAM,EAAOI,UAAUb,OACZS,IAASvB,EAAQ,CACrB,GAAKuB,EAAOvB,EACX,MAAM,IAAIa,MAAOJ,EAAO,UAEzB,MAAM,IAAII,MAAOJ,EAAO,SACxB,CAGD,IAFAY,EAAS,GACTC,EAAS,GACHL,EAAI,EAAGA,EAAIjB,EAAOiB,IAAM,CAE7B,IAAMW,EADNH,EAAIE,UAAWV,IAEd,MAAKA,EAAIhB,EACF,IAAIO,UAAWC,EAAQ,QAASgB,IAEhC,IAAIjB,UAAWC,EAAQ,QAASgB,IAGxCJ,EAAOH,KAAMO,GACbH,EAAOJ,KAAMC,EAAaU,EAAUJ,IACpC,CAKD,IAHAD,EC1HF,SAAuBM,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAvB,EACAwB,EAIJ,IADAF,EAAKJ,EACClB,EAAI,EAAGA,EAAIa,EAAGb,IAAM,CAEzB,IADAuB,EAAKF,EACCG,EAAI,EAAGA,EAAIV,GACXC,EAAGO,EAAIE,EAAEP,KAAgBE,EAAGI,GADdC,IAInBD,GAAMH,EAGP,GAAKI,IAAMV,EACV,OAAOd,EAERsB,GAAMN,CACN,CACD,OAAQ,CACT,CDmGQS,CAActC,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGmB,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAId,UAAWC,EAAO,UAI5BiB,EADIrB,GAGAR,EAAM2B,GAGNzB,EACJ2B,EAAGL,EAAQtB,EAAMyB,IAEjBE,EAAGL,GAEJ,GAAc,IAATnB,EACJ,OAAOmB,EAAQlB,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOmB,EAAOsB,MAAO1C,EACrB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 88f0e3e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Create an ndarray function interface which performs multiple dispatch. -* -* @module @stdlib/ndarray-dispatch -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var dispatch = require( '@stdlib/ndarray-dispatch' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/index_of_types.js b/lib/index_of_types.js deleted file mode 100644 index fda2297..0000000 --- a/lib/index_of_types.js +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found). -* -* ## Notes -* -* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types). -* - The function assumes that `x` is stored in row-major order. -* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`. -* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value. -* -* @private -* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension) -* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension) -* @param {ArrayLikeObject} x - input two-dimensional reference array -* @param {integer} strideX1 - `x` stride length along first dimension -* @param {integer} strideX2 - `x` stride length along second dimension -* @param {NonNegativeInteger} offsetX - `x` starting index -* @param {ArrayLikeObject} y - search array -* @param {integer} strideY - `y` stride length -* @param {NonNegativeInteger} offsetY - `y` starting index -* @returns {integer} row index (if found) and `-1` otherwise -* -* @example -* // Define a reference array to search: -* var types = [ -* 'float64', 'float64', 'float64', -* 'float32', 'float32', 'float32', -* 'uint32', 'uint32', 'float64', -* 'int32', 'int32', 'float64', -* 'uint16', 'uint16', 'float64', -* 'int16', 'int16', 'float64', -* 'uint8', 'uint8', 'float64', -* 'int8', 'int8', 'float64' -* ]; -* -* // Define reference array dimensions: -* var N = 8; // rows -* var M = 3; // columns -* -* // Define a search array: -* y1 = [ -* 'float32', 'float32', 'float32', -* ]; -* -* // Find the list of types: -* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 ); -* // returns 1 -* -// Define a search array: -* y2 = [ -* 'float32', 'float32', 'float64', -* ]; -* -* // Find the list of types: -* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 ); -* // returns -1 -*/ -function indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len - var ix; - var iy; - var i; - var j; - - // Search for the first row which matches `y`... - ix = offsetX; - for ( i = 0; i < N; i++ ) { - iy = offsetY; - for ( j = 0; j < M; j++ ) { - if ( x[ ix+(j*strideX2) ] !== y[ iy ] ) { - break; - } - iy += strideY; - } - // If we successfully iterated over all columns, then that means we've found a match... - if ( j === M ) { - return i; - } - ix += strideX1; - } - return -1; -} - - -// EXPORTS // - -module.exports = indexOfTypes; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4648598..0000000 --- a/lib/main.js +++ /dev/null @@ -1,231 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isFunctionArray = require( '@stdlib/assert-is-function-array' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var resolveEnum = require( '@stdlib/ndarray-base-dtype-resolve-enum' ); -var indexOfTypes = require( './index_of_types.js' ); - - -// FUNCTIONS // - -/** -* Returns a list of data type enumeration constants. -* -* @private -* @param {Collection} types - list of types -* @returns {IntegerArray} list of data type enumeration constants -*/ -function types2enums( types ) { - var out; - var i; - - out = []; - for ( i = 0; i < types.length; i++ ) { - out.push( resolveEnum( types[ i ] ) ); - } - return out; -} - - -// MAIN // - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param {(FunctionArray|Function)} fcns - list of ndarray functions -* @param {Collection} types - one-dimensional list of ndarray argument data types -* @param {(Collection|null)} data - ndarray function data (e.g., callbacks) -* @param {PositiveInteger} nargs - total number of ndarray function interface arguments -* @param {NonNegativeInteger} nin - number of input ndarrays -* @param {NonNegativeInteger} nout - number of output ndarrays -* @throws {TypeError} first argument must be either a function or an array of functions -* @throws {TypeError} second argument must be an array-like object -* @throws {TypeError} third argument must be an array-like object or `null` -* @throws {Error} third and first arguments must have the same number of elements -* @throws {TypeError} fourth argument must be a positive integer -* @throws {TypeError} fifth argument must be a nonnegative integer -* @throws {TypeError} sixth argument must be a nonnegative integer -* @throws {Error} fourth argument must equal the specified number of input and output arrays -* @throws {Error} number of types must match the number of functions times the total number of array arguments for each function -* @throws {Error} interface must accept at least one input and/or output ndarray -* @returns {Function} ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function dispatch( fcns, types, data, nargs, nin, nout ) { - var narrays; - var nfcns; - var fcn; - - if ( isFunction( fcns ) ) { - fcn = fcns; - } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( '0jr5d', fcns ) ); - } - if ( !isCollection( types ) ) { - throw new TypeError( format( '0jr2y', types ) ); - } - if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( '0jr5e', data ) ); - } - if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( '0jr5f', nargs ) ); - } - if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( '0jr5X', nin ) ); - } - if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( '0jr5g', nout ) ); - } - narrays = nin + nout; - if ( narrays === 0 ) { - throw new Error( format('0jr0h') ); - } - if ( nargs !== narrays ) { - throw new Error( format('0jr0i') ); - } - if ( fcn ) { - nfcns = types.length / narrays; - if ( !isInteger( nfcns ) ) { - throw new Error( format('0jr0j') ); - } - } else { - nfcns = fcns.length; - if ( types.length !== nfcns*narrays ) { - throw new Error( format('0jr0j') ); - } - } - if ( data && data.length !== nfcns ) { - throw new Error( format('0jr0k') ); - } - types = types2enums( types ); - return dispatcher; - - /** - * ndarray function interface which performs multiple dispatch. - * - * @private - * @param {ndarrayLike} x - ndarray - * @param {...ndarrayLike} args - ndarray arguments - * @throws {Error} insufficient arguments - * @throws {Error} too many arguments - * @throws {TypeError} input array arguments must be ndarray-like objects - * @throws {TypeError} output array arguments must be ndarray-like objects - * @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types - * @returns {(ndarrayLike|Array|void)} destination array(s) - */ - function dispatcher() { - var arrays; - var dtypes; - var argc; - var idx; - var v; - var f; - var i; - - argc = arguments.length; - if ( argc !== nargs ) { - if ( argc < nargs ) { - throw new Error( format('0jr0l') ); - } - throw new Error( format('0jr0m') ); - } - arrays = []; - dtypes = []; - for ( i = 0; i < nargs; i++ ) { - v = arguments[ i ]; - if ( !isndarrayLike( v ) ) { - if ( i < nin ) { - throw new TypeError( format( '0jr5h', v ) ); - } else { - throw new TypeError( format( '0jr5i', v ) ); - } - } - arrays.push( v ); - dtypes.push( resolveEnum( getDType( v ) ) ); - } - // Resolve the ndarray function satisfying the input array types: - idx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len - - // Check whether we were able to successfully resolve an ndarray function: - if ( idx < 0 ) { - throw new TypeError( format('0jr0n') ); - } - // Retrieve the ndarray function: - if ( fcn ) { - f = fcn; - } else { - f = fcns[ idx ]; - } - // Evaluate the ndarray function: - if ( data ) { - f( arrays, data[ idx ] ); - } else { - f( arrays ); - } - if ( nout === 1 ) { - return arrays[ narrays-1 ]; - } - if ( nout === 0 ) { - return; - } - return arrays.slice( nin ); - } -} - - -// EXPORTS // - -module.exports = dispatch; diff --git a/package.json b/package.json index b3f4488..e6c8bad 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Create an ndarray function interface which performs multiple dispatch.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,57 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-function-array": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer": "^0.2.2", - "@stdlib/assert-is-positive-integer": "^0.2.2", - "@stdlib/ndarray-base-dtype-resolve-enum": "^0.2.2", - "@stdlib/ndarray-dtype": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.2.2", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/array-int8": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/math-base-assert-is-nan": "^0.2.2", - "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/math-base-special-pow": "^0.3.0", - "@stdlib/math-base-special-sin": "^0.3.0", - "@stdlib/ndarray-base-buffer-dtype": "^0.3.0", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-unary": "^0.2.1", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-dtypes": "^0.3.0", - "@stdlib/ndarray-ind2sub": "^0.2.2", - "@stdlib/strided-dtypes": "^0.3.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "ndarray", @@ -100,7 +26,6 @@ "multimethod", "multimethods" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..252182f --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/fixtures/binary.js b/test/fixtures/binary.js deleted file mode 100644 index a60dfa2..0000000 --- a/test/fixtures/binary.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Binary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @returns {number} sum -*/ -function binary( x, y ) { - return x + y; -} - - -// EXPORTS // - -module.exports = binary; diff --git a/test/fixtures/fill.js b/test/fixtures/fill.js deleted file mode 100644 index 41b2958..0000000 --- a/test/fixtures/fill.js +++ /dev/null @@ -1,76 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which fills one or more ndarrays. -* -* @private -* @param {*} value - fill value -* @returns {Function} ndarray function -*/ -function fill( value ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - */ - function ndarrayFcn( arrays ) { - var opts; - var sub; - var arr; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - opts = { - 'order': '' - }; - for ( j = 0; j < M; j++ ) { - arr = arrays[ j ]; - opts.order = arrays[ j ].order; - for ( i = 0; i < N; i++ ) { - sub = ind2sub( sh, i, opts ); - sub.push( value ); - arr.set.apply( arr, sub ); - } - } - } -} - - -// EXPORTS // - -module.exports = fill; diff --git a/test/fixtures/foreach.js b/test/fixtures/foreach.js deleted file mode 100644 index a426290..0000000 --- a/test/fixtures/foreach.js +++ /dev/null @@ -1,72 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function forEach( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - fcn.apply( null, args ); - } -} - - -// EXPORTS // - -module.exports = forEach; diff --git a/test/fixtures/map1n.js b/test/fixtures/map1n.js deleted file mode 100644 index 614196b..0000000 --- a/test/fixtures/map1n.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function which maps the return value of a callback to `N` arrays. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function map1N( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var v; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - v = fcn(); - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - sub.push( v ); - arrays[ j ].set.apply( arrays[ j ], sub ); - } - } -} - - -// EXPORTS // - -module.exports = map1N; diff --git a/test/fixtures/nullary.js b/test/fixtures/nullary.js deleted file mode 100644 index 4f22126..0000000 --- a/test/fixtures/nullary.js +++ /dev/null @@ -1,36 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Nullary callback. -* -* @private -* @returns {number} value -*/ -function nullary() { - return 3.0; -} - - -// EXPORTS // - -module.exports = nullary; diff --git a/test/fixtures/quaternary.js b/test/fixtures/quaternary.js deleted file mode 100644 index 548437b..0000000 --- a/test/fixtures/quaternary.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quaternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @returns {number} sum -*/ -function quaternary( x, y, z, w ) { - return x + y + z + w; -} - - -// EXPORTS // - -module.exports = quaternary; diff --git a/test/fixtures/quinary.js b/test/fixtures/quinary.js deleted file mode 100644 index 36068de..0000000 --- a/test/fixtures/quinary.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quinary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @param {number} u - input value -* @returns {number} sum -*/ -function quinary( x, y, z, w, u ) { - return x + y + z + w + u; -} - - -// EXPORTS // - -module.exports = quinary; diff --git a/test/fixtures/sum.js b/test/fixtures/sum.js deleted file mode 100644 index efdbb1b..0000000 --- a/test/fixtures/sum.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which computes the sum across one or more ndarrays. -* -* @private -* @param {Object} ctx - context -* @param {number} ctx.sum - initial sum -* @returns {Function} ndarray function -*/ -function wrapper( ctx ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - * @param {Function} [fcn] - callback - */ - function ndarrayFcn( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var f; - var i; - var j; - - if ( arguments.length > 1 ) { - f = fcn; - } - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - if ( f ) { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - ctx.sum += f.apply( null, args ); - } - } else { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - ctx.sum += arrays[ j ].get.apply( arrays[ j ], sub ); - } - } - } - } -} - - -// EXPORTS // - -module.exports = wrapper; diff --git a/test/fixtures/ternary.js b/test/fixtures/ternary.js deleted file mode 100644 index 0595d5f..0000000 --- a/test/fixtures/ternary.js +++ /dev/null @@ -1,39 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Ternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @returns {number} sum -*/ -function ternary( x, y, z ) { - return x + y + z; -} - - -// EXPORTS // - -module.exports = ternary; diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d6c2c8e..0000000 --- a/test/test.js +++ /dev/null @@ -1,363 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var fill = require( './fixtures/fill.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either a function or an array of functions as a first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( value, types, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object as a second argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided either an array-like object or `null` as a third argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - dispatch( unary, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a positive integer for a fourth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 0, - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a fifth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, value, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a sixth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, 1, value ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function array)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var fcns = [ unary, unary, unary ]; - var data = [ abs, abs, abs ]; - dispatch( fcns, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function argument)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs, abs, abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the length of `data` argument does not match the number of ndarray functions', function test( t ) { - var values; - var i; - - values = [ - [], - [ abs, abs ], - [ abs, abs, abs ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var fcns = [ unary ]; - dispatch( fcns, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the fourth argument is incompatible with the number of input and output ndarrays', function test( t ) { - var values; - var i; - - values = [ - 0, - 1, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of specified input and output ndarrays is zero', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var types = [ 'float64' ]; - dispatch( fill( 3 ), types, null, 1, 0, 0 ); - } -}); - -tape( 'the function returns an ndarray function interface', function test( t ) { - var types; - var data; - var f; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - f = dispatch( unary, types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ unary ], types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( fill( 3 ), types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ fill( 3 ) ], types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.two_arrays.js b/test/test.two_arrays.js deleted file mode 100644 index 16eb61b..0000000 --- a/test/test.two_arrays.js +++ /dev/null @@ -1,814 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var dtype = require( '@stdlib/ndarray-base-buffer-dtype' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var forEach = require( './fixtures/foreach.js' ); -var map1N = require( './fixtures/map1n.js' ); -var fill = require( './fixtures/fill.js' ); -var sum = require( './fixtures/sum.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the first argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var ybuf = new Float64Array( 10 ); - var y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( value, y ); - }; - } -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the second argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var xbuf = new Float64Array( 10 ); - var x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( x, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided insufficient arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var f; - var x; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [], - [ x ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided too many arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var ybuf; - var f; - var x; - var y; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [ x, y, y ], - [ x, y, y, y ], - [ x, y, y, y, y ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if unable to resolve a ndarray function supporting the provided array argument data types', function test( t ) { - var values; - var types; - var data; - var xbuf; - var fcn; - var x; - var i; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ abs, abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 4 ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - values = [ - new Uint8Array( 4 ), - new Int32Array( 4 ), - [ 0, 0, 0, 0 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided an array having data type: ' + dtype( values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var y = ndarray( dtype( value ), value, [ value.length ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - }; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only input arrays)', function test( t ) { - var types; - var xbuf; - var ybuf; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only output arrays)', function test( t ) { - var expected; - var types; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only input arrays)', function test( t ) { - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var ctx; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcns = [ - sum( ctx ), - sum( ctx ) - ]; - fcn = dispatch( fcns, types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only output arrays)', function test( t ) { - var expected; - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcns = [ - fill( 3.0 ), - fill( 4.0 ) - ]; - fcn = dispatch( fcns, types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - - fcn = dispatch( forEach, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - - fcn = dispatch( map1N, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - fcns = [ - forEach, - forEach - ]; - fcn = dispatch( fcns, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - fcns = [ - map1N, - map1N - ]; - fcn = dispatch( fcns, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - fcns = [ - unary, - unary - ]; - fcn = dispatch( fcns, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which returns one or more output arrays, if one or more output arrays is specified, and otherwise returns `undefined`', function test( t ) { - var types; - var data; - var xbuf; - var ybuf; - var out; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - // No output arrays... - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, void 0, 'returns expected value' ); - - // One output array... - data = [ - abs, - abs - ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - fcn = dispatch( fill( 3.0 ), types, null, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - // Two output arrays... - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.end(); -}); From e020288355eaf475e64a65f66b17f1af9cdb0161 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 28 Sep 2024 21:25:25 +0000 Subject: [PATCH 089/109] Transform error messages --- lib/main.js | 34 +++++++++++++++++----------------- package.json | 2 +- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/main.js b/lib/main.js index 5f4bb5d..4648598 100644 --- a/lib/main.js +++ b/lib/main.js @@ -27,7 +27,7 @@ var isFunctionArray = require( '@stdlib/assert-is-function-array' ); var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var getDType = require( '@stdlib/ndarray-dtype' ); var resolveEnum = require( '@stdlib/ndarray-base-dtype-resolve-enum' ); var indexOfTypes = require( './index_of_types.js' ); @@ -112,43 +112,43 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { if ( isFunction( fcns ) ) { fcn = fcns; } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) ); + throw new TypeError( format( '0jr5d', fcns ) ); } if ( !isCollection( types ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) ); + throw new TypeError( format( '0jr2y', types ) ); } if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); + throw new TypeError( format( '0jr5e', data ) ); } if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) ); + throw new TypeError( format( '0jr5f', nargs ) ); } if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) ); + throw new TypeError( format( '0jr5X', nin ) ); } if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) ); + throw new TypeError( format( '0jr5g', nout ) ); } narrays = nin + nout; if ( narrays === 0 ) { - throw new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' ); + throw new Error( format('0jr0h') ); } if ( nargs !== narrays ) { - throw new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' ); + throw new Error( format('0jr0i') ); } if ( fcn ) { nfcns = types.length / narrays; if ( !isInteger( nfcns ) ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format('0jr0j') ); } } else { nfcns = fcns.length; if ( types.length !== nfcns*narrays ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format('0jr0j') ); } } if ( data && data.length !== nfcns ) { - throw new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' ); + throw new Error( format('0jr0k') ); } types = types2enums( types ); return dispatcher; @@ -178,9 +178,9 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { argc = arguments.length; if ( argc !== nargs ) { if ( argc < nargs ) { - throw new Error( 'invalid invocation. Insufficient arguments.' ); + throw new Error( format('0jr0l') ); } - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('0jr0m') ); } arrays = []; dtypes = []; @@ -188,9 +188,9 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { v = arguments[ i ]; if ( !isndarrayLike( v ) ) { if ( i < nin ) { - throw new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) ); + throw new TypeError( format( '0jr5h', v ) ); } else { - throw new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) ); + throw new TypeError( format( '0jr5i', v ) ); } } arrays.push( v ); @@ -201,7 +201,7 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { // Check whether we were able to successfully resolve an ndarray function: if ( idx < 0 ) { - throw new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' ); + throw new TypeError( format('0jr0n') ); } // Retrieve the ndarray function: if ( fcn ) { diff --git a/package.json b/package.json index 82b9edc..16afec6 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/assert-is-positive-integer": "^0.2.2", "@stdlib/ndarray-base-dtype-resolve-enum": "^0.2.2", "@stdlib/ndarray-dtype": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.1", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 213dbb6040321a1d941b8b358fd656a4c870f863 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 28 Sep 2024 21:38:26 +0000 Subject: [PATCH 090/109] Remove files --- index.d.ts | 334 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5181 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index c49a4e4..0000000 --- a/index.d.ts +++ /dev/null @@ -1,334 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* ndarray function. -* -* @param arrays - array containing input and output ndarrays -* @param data - ndarray function data (e.g., a callback) -* -* @example -* var numel = require( '@stdlib/ndarray-base-numel' ); -* var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -* -* function ndarrayFcn( arrays, fcn ) { -* var xord; -* var yord; -* var opts; -* var sub; -* var sh; -* var N; -* var x; -* var y; -* var v; -* var i; -* -* x = arrays[ 0 ]; -* y = arrays[ 1 ]; -* sh = x.shape; -* N = numel( sh ); -* if ( N <= 0 ) { -* return; -* } -* xord = x.order; -* yord = y.order; -* opts = {}; -* opts.order = xord; -* for ( i = 0; i < N; i++ ) { -* // Convert a linear index to subscripts: -* opts.order = xord; -* sub = ind2sub( sh, i, opts ); -* -* // Retrieve an element from `x`: -* v = x.get.apply( x, sub ); -* -* // Convert a linear index to subscripts: -* opts.order = yord; -* sub = ind2sub( sh, i, opts ); -* -* // Append the result of applying the callback: -* sub.push( fcn( v ) ); -* -* // Assign the result to an element in `y`: -* y.set.apply( y, sub ); -* } -* } -*/ -type ndarrayFcn = ( arrays: Array, data?: any ) => void; - -/** -* Interface describing an ndarray function dispatcher. -*/ -interface Dispatcher { - /** - * Invokes an ndarray function based on the provided array data type(s). - * - * @param x - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array - * - * @example - * var nullary = require( '@stdlib/ndarray-base-nullary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function value() { - * return 3.14; - * } - * - * var types = [ 'float64' ]; - * var data = [ value ]; - * - * var fcn = dispatch( nullary, types, data, 1, 0, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( 5 ); - * var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x ); - * // xbuf => [ 3.14, 3.14, 3.14, 3.14, 3.14 ] - */ - ( x: ndarray ): ndarray | void; - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var unary = require( '@stdlib/ndarray-base-unary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * var abs = require( '@stdlib/math-base-special-abs' ); - * - * var types = [ 'float64', 'float64' ]; - * var data = [ abs ]; - * - * var fcn = dispatch( unary, types, data, 2, 1, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - * var ybuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y ); - * // ybuf => [ 1.0, 2.0, 3.0 ] - */ - ( x: ndarray, y: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var ternary = require( '@stdlib/ndarray-base-ternary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function add2( x, y ) { - * return x + y; - * } - * - * var types = [ 'float64', 'float64', 'float64' ]; - * var data = [ add2 ]; - * - * var fcn = dispatch( ternary, types, data, 3, 2, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z ); - * // zbuf => [ 2.0, 4.0, 6.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quaternary = require( '@stdlib/ndarray-base-quaternary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function add3( x, y, z ) { - * return x + y + z; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add3 ]; - * - * var fcn = dispatch( quaternary, types, data, 4, 3, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w ); - * // wbuf => [ 3.0, 6.0, 9.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @param args - ndarray arguments - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quinary = require( '@stdlib/ndarray-base-quinary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function add4( x, y, z, w ) { - * return x + y + z + w; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add4 ]; - * - * var fcn = dispatch( quinary, types, data, 5, 4, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ubuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var u = ndarray( 'float64', ubuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w, u ); - * // ubuf => [ 4.0, 8.0, 12.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray, ...args: Array ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures -} - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param fcns - list of ndarray functions -* @param types - one-dimensional list of ndarray argument data types -* @param data - ndarray function data (e.g., callbacks) -* @param nargs - total number of ndarray function interface arguments -* @param nin - number of input ndarrays -* @param nout - number of output ndarrays -* @throws first argument must be either a function or an array of functions -* @throws second argument must be an array-like object -* @throws third argument must be an array-like object or `null` -* @throws third and first arguments must have the same number of elements -* @throws fourth argument must be a positive integer -* @throws fifth argument must be a nonnegative integer -* @throws sixth argument must be a nonnegative integer -* @throws fourth argument must equal the specified number of input and output arrays -* @throws number of types must match the number of functions times the total number of array arguments for each function -* @throws interface must accept at least one input and/or output ndarray -* @returns ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var fcn = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* fcn( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function dispatch( fcns: ndarrayFcn | ArrayLike, types: ArrayLike, data: ArrayLike | null, nargs: number, nin: number, nout: number ): Dispatcher; - - -// EXPORTS // - -export = dispatch; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 17b911b..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@v0.2.2-esm/index.mjs";function m(m,f,l,p,w,v){var a,g,c;if(i(m))c=m;else if(!s(m))throw new TypeError(d("0jr5d",m));if(!n(f))throw new TypeError(d("0jr2y",f));if(!n(l)&&null!==l)throw new TypeError(d("0jr5e",l));if(!e(p))throw new TypeError(d("0jr5f",p));if(!r(w))throw new TypeError(d("0jr5X",w));if(!r(v))throw new TypeError(d("0jr5g",v));if(0===(a=w+v))throw new Error(d("0jr0h"));if(p!==a)throw new Error(d("0jr0i"));if(c){if(g=f.length/a,!t(g))throw new Error(d("0jr0j"))}else if(g=m.length,f.length!==g*a)throw new Error(d("0jr0j"));if(l&&l.length!==g)throw new Error(d("0jr0k"));return f=function(r){var e,t;for(e=[],t=0;t [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0jr5d', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0jr2y', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( '0jr5e', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0jr5f', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0jr5X', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0jr5g', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format('0jr0h') );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format('0jr0i') );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format('0jr0k') );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format('0jr0l') );\n\t\t\t}\n\t\t\tthrow new Error( format('0jr0m') );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( '0jr5h', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( '0jr5i', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format('0jr0n') );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found).\n*\n* ## Notes\n*\n* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types).\n* - The function assumes that `x` is stored in row-major order.\n* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`.\n* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value.\n*\n* @private\n* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension)\n* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension)\n* @param {ArrayLikeObject} x - input two-dimensional reference array\n* @param {integer} strideX1 - `x` stride length along first dimension\n* @param {integer} strideX2 - `x` stride length along second dimension\n* @param {NonNegativeInteger} offsetX - `x` starting index\n* @param {ArrayLikeObject} y - search array\n* @param {integer} strideY - `y` stride length\n* @param {NonNegativeInteger} offsetY - `y` starting index\n* @returns {integer} row index (if found) and `-1` otherwise\n*\n* @example\n* // Define a reference array to search:\n* var types = [\n* 'float64', 'float64', 'float64',\n* 'float32', 'float32', 'float32',\n* 'uint32', 'uint32', 'float64',\n* 'int32', 'int32', 'float64',\n* 'uint16', 'uint16', 'float64',\n* 'int16', 'int16', 'float64',\n* 'uint8', 'uint8', 'float64',\n* 'int8', 'int8', 'float64'\n* ];\n*\n* // Define reference array dimensions:\n* var N = 8; // rows\n* var M = 3; // columns\n*\n* // Define a search array:\n* y1 = [\n* 'float32', 'float32', 'float32',\n* ];\n*\n* // Find the list of types:\n* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 );\n* // returns 1\n*\n// Define a search array:\n* y2 = [\n* 'float32', 'float32', 'float64',\n* ];\n*\n* // Find the list of types:\n* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 );\n* // returns -1\n*/\nfunction indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len\n\tvar ix;\n\tvar iy;\n\tvar i;\n\tvar j;\n\n\t// Search for the first row which matches `y`...\n\tix = offsetX;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tiy = offsetY;\n\t\tfor ( j = 0; j < M; j++ ) {\n\t\t\tif ( x[ ix+(j*strideX2) ] !== y[ iy ] ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tiy += strideY;\n\t\t}\n\t\t// If we successfully iterated over all columns, then that means we've found a match...\n\t\tif ( j === M ) {\n\t\t\treturn i;\n\t\t}\n\t\tix += strideX1;\n\t}\n\treturn -1;\n}\n\n\n// EXPORTS //\n\nexport default indexOfTypes;\n"],"names":["dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","out","i","push","resolveEnum","types2enums","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","getDType","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","j","indexOfTypes","slice"],"mappings":";;0+BA0GA,SAASA,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAO,UAEzB,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAO,UAEzB,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAO,eAIzB,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAO,UAG1B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAO,UAGzB,OADAX,EA5GD,SAAsBA,GACrB,IAAIkB,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAInB,EAAMgB,OAAQG,IAC9BD,EAAIE,KAAMC,EAAarB,EAAOmB,KAE/B,OAAOD,CACR,CAmGSI,CAAatB,GAgBrB,WACC,IAAIuB,EACAC,EACAC,EACAC,EACAC,EACAC,EACAT,EAGJ,GADAM,EAAOI,UAAUb,OACZS,IAASvB,EAAQ,CACrB,GAAKuB,EAAOvB,EACX,MAAM,IAAIa,MAAOJ,EAAO,UAEzB,MAAM,IAAII,MAAOJ,EAAO,SACxB,CAGD,IAFAY,EAAS,GACTC,EAAS,GACHL,EAAI,EAAGA,EAAIjB,EAAOiB,IAAM,CAE7B,IAAMW,EADNH,EAAIE,UAAWV,IAEd,MAAKA,EAAIhB,EACF,IAAIO,UAAWC,EAAQ,QAASgB,IAEhC,IAAIjB,UAAWC,EAAQ,QAASgB,IAGxCJ,EAAOH,KAAMO,GACbH,EAAOJ,KAAMC,EAAaU,EAAUJ,IACpC,CAKD,IAHAD,EC1HF,SAAuBM,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAvB,EACAwB,EAIJ,IADAF,EAAKJ,EACClB,EAAI,EAAGA,EAAIa,EAAGb,IAAM,CAEzB,IADAuB,EAAKF,EACCG,EAAI,EAAGA,EAAIV,GACXC,EAAGO,EAAIE,EAAEP,KAAgBE,EAAGI,GADdC,IAInBD,GAAMH,EAGP,GAAKI,IAAMV,EACV,OAAOd,EAERsB,GAAMN,CACN,CACD,OAAQ,CACT,CDmGQS,CAActC,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGmB,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAId,UAAWC,EAAO,UAI5BiB,EADIrB,GAGAR,EAAM2B,GAGNzB,EACJ2B,EAAGL,EAAQtB,EAAMyB,IAEjBE,EAAGL,GAEJ,GAAc,IAATnB,EACJ,OAAOmB,EAAQlB,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOmB,EAAOsB,MAAO1C,EACrB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 252182f..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From ce2efaea68cda30c9cde6e2e811dfb85b4151d0f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 28 Sep 2024 21:38:43 +0000 Subject: [PATCH 091/109] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 ---- .github/workflows/publish.yml | 252 -- .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 255 -- CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 61 +- SECURITY.md | 5 - benchmark/benchmark.dispatch_size.js | 156 - benchmark/benchmark.js | 81 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 87 - docs/types/test.ts | 641 --- examples/add.js | 121 - examples/sin.js | 142 - examples/unary.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/index_of_types.js | 106 - lib/main.js | 231 - package.json | 79 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/binary.js | 38 - test/fixtures/fill.js | 76 - test/fixtures/foreach.js | 72 - test/fixtures/map1n.js | 74 - test/fixtures/nullary.js | 36 - test/fixtures/quaternary.js | 40 - test/fixtures/quinary.js | 41 - test/fixtures/sum.js | 98 - test/fixtures/ternary.js | 39 - test/test.js | 363 -- test/test.two_arrays.js | 814 ---- 56 files changed, 4876 insertions(+), 7027 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.dispatch_size.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/add.js delete mode 100644 examples/sin.js delete mode 100644 examples/unary.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/index_of_types.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/fixtures/binary.js delete mode 100644 test/fixtures/fill.js delete mode 100644 test/fixtures/foreach.js delete mode 100644 test/fixtures/map1n.js delete mode 100644 test/fixtures/nullary.js delete mode 100644 test/fixtures/quaternary.js delete mode 100644 test/fixtures/quinary.js delete mode 100644 test/fixtures/sum.js delete mode 100644 test/fixtures/ternary.js delete mode 100644 test/test.js delete mode 100644 test/test.two_arrays.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ac0b7cd..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 5e92c3e..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2b4fac7..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '43 7 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -304,7 +295,7 @@ console.log( ybuf ); ## 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. +This package is part of [stdlib][stdlib], a standard library 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]. @@ -367,11 +358,11 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-dispatch/main/LICENSE -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.dispatch_size.js b/benchmark/benchmark.dispatch_size.js deleted file mode 100644 index 15805ba..0000000 --- a/benchmark/benchmark.dispatch_size.js +++ /dev/null @@ -1,156 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib/main.js' ); - - -// FUNCTIONS // - -/** -* Evaluates the identity function. -* -* @private -* @param {*} v - value -* @returns {*} input value -*/ -function identity( v ) { - return v; -} - -/** -* Dummy function which throws an error. -* -* @private -* @throws {Error} unexpected error -*/ -function throwError() { - throw new Error( 'unexpected error' ); -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} size - dispatch size -* @returns {Function} benchmark function -*/ -function createBenchmark( size ) { - var types; - var data; - var fcn; - var x; - var y; - var t; - var i; - - types = []; - - // Create dummy types... - for ( i = 0; i < (size-1)*2; i += 2 ) { - t = 'foo' + i; - types.push( t ); - types.push( t ); - } - // Append test types: - types.push( 'float64' ); - types.push( 'float64' ); - - // Define a list of callbacks: - data = []; - for ( i = 0; i < size-1; i++ ) { - data.push( throwError ); - } - // Append a test callback: - data.push( identity ); - - // Create the dispatcher: - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - // Create sample arrays: - x = new Float64Array( 1 ); - y = new Float64Array( x.length ); - - x = ndarray( 'float64', x, [ 1 ], [ 1 ], 0, 'row-major' ); - y = ndarray( 'float64', y, [ 1 ], [ 1 ], 0, 'row-major' ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var z; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x.data[ 0 ] = i; - z = fcn( x, y ); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var size; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - size = pow( 2, i ); - f = createBenchmark( size ); - bench( pkg+':size='+size, f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 3c6f450..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::fcns_array', function benchmark( b ) { - var types; - var fcns; - var data; - var out; - var i; - - fcns = [ unary ]; - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( fcns, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::fcn_arg', function benchmark( b ) { - var types; - var data; - var out; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( unary, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0aae4af..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch" -%% click B href "https://github.com/stdlib-js/ndarray-dispatch/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-dispatch/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-dispatch/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-dispatch/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-dispatch/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch -[production-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 1295a44..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import dispatch from '../docs/types/index'; -export = dispatch; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c23dc5d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var y=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var b=y(function(D,w){"use strict";function k(i,r,e,u,f,m,n,o,l){var h,t,s,a;for(h=m,s=0;s [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( 'invalid invocation. Insufficient arguments.' );\n\t\t\t}\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = dispatch;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an ndarray function interface which performs multiple dispatch.\n*\n* @module @stdlib/ndarray-dispatch\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var unary = require( '@stdlib/ndarray-base-unary' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var Float64Array = require( '@stdlib/array-float64' );\n* var dispatch = require( '@stdlib/ndarray-dispatch' );\n*\n* var types = [\n* 'float64', 'float64'\n* ];\n*\n* var data = [\n* abs\n* ];\n*\n* var absolute = dispatch( unary, types, data, 2, 1, 1 );\n*\n* // ...\n*\n* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] );\n* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] );\n*\n* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' );\n* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' );\n*\n* absolute( x, y );\n* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA6EA,SAASC,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,EAAU,CAClF,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,CAAU,IAAME,EAAGI,CAAG,EADjBE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,CACP,CACA,MAAO,EACR,CAKAL,EAAO,QAAUC,ICzGjB,IAAAc,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAoB,QAAS,oCAAqC,EAClEC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAkB,QAAS,kCAAmC,EAC9DC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAc,QAAS,yCAA0C,EACjEC,EAAe,IAYnB,SAASC,EAAaC,EAAQ,CAC7B,IAAIC,EACAC,EAGJ,IADAD,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIF,EAAM,OAAQE,IAC9BD,EAAI,KAAMJ,EAAaG,EAAOE,CAAE,CAAE,CAAE,EAErC,OAAOD,CACR,CAqDA,SAASE,EAAUC,EAAMJ,EAAOK,EAAMC,EAAOC,EAAKC,EAAO,CACxD,IAAIC,EACAC,EACAC,EAEJ,GAAKnB,EAAYY,CAAK,EACrBO,EAAMP,UACK,CAACb,EAAiBa,CAAK,EAClC,MAAM,IAAI,UAAWT,EAAQ,oGAAqGS,CAAK,CAAE,EAE1I,GAAK,CAACX,EAAcO,CAAM,EACzB,MAAM,IAAI,UAAWL,EAAQ,+EAAgFK,CAAM,CAAE,EAEtH,GAAK,CAACP,EAAcY,CAAK,GAAKA,IAAS,KACtC,MAAM,IAAI,UAAWV,EAAQ,sFAAuFU,CAAK,CAAE,EAE5H,GAAK,CAAChB,EAAmBiB,CAAM,EAC9B,MAAM,IAAI,UAAWX,EAAQ,6EAA8EW,CAAM,CAAE,EAEpH,GAAK,CAAClB,EAAsBmB,CAAI,EAC/B,MAAM,IAAI,UAAWZ,EAAQ,+EAAgFY,CAAI,CAAE,EAEpH,GAAK,CAACnB,EAAsBoB,CAAK,EAChC,MAAM,IAAI,UAAWb,EAAQ,+EAAgFa,CAAK,CAAE,EAGrH,GADAC,EAAUF,EAAMC,EACXC,IAAY,EAChB,MAAM,IAAI,MAAO,4IAA6I,EAE/J,GAAKH,IAAUG,EACd,MAAM,IAAI,MAAO,4FAA6F,EAE/G,GAAKE,GAEJ,GADAD,EAAQV,EAAM,OAASS,EAClB,CAACnB,EAAWoB,CAAM,EACtB,MAAM,IAAI,MAAO,8IAA+I,UAGjKA,EAAQN,EAAK,OACRJ,EAAM,SAAWU,EAAMD,EAC3B,MAAM,IAAI,MAAO,8IAA+I,EAGlK,GAAKJ,GAAQA,EAAK,SAAWK,EAC5B,MAAM,IAAI,MAAO,mGAAoG,EAEtH,OAAAV,EAAQD,EAAaC,CAAM,EACpBY,EAeP,SAASA,GAAa,CACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EAGJ,GADAa,EAAO,UAAU,OACZA,IAAST,EACb,MAAKS,EAAOT,EACL,IAAI,MAAO,6CAA8C,EAE1D,IAAI,MAAO,yCAA0C,EAI5D,IAFAO,EAAS,CAAC,EACVC,EAAS,CAAC,EACJZ,EAAI,EAAGA,EAAII,EAAOJ,IAAM,CAE7B,GADAe,EAAI,UAAWf,CAAE,EACZ,CAACR,EAAeuB,CAAE,EACtB,MAAKf,EAAIK,EACF,IAAI,UAAWZ,EAAQ,6EAA8EsB,CAAE,CAAE,EAEzG,IAAI,UAAWtB,EAAQ,8EAA+EsB,CAAE,CAAE,EAGlHJ,EAAO,KAAMI,CAAE,EACfH,EAAO,KAAMjB,EAAaD,EAAUqB,CAAE,CAAE,CAAE,CAC3C,CAKA,GAHAD,EAAMlB,EAAcY,EAAOD,EAAST,EAAOS,EAAS,EAAG,EAAGK,EAAQ,EAAG,CAAE,EAGlEE,EAAM,EACV,MAAM,IAAI,UAAW,6GAA8G,EAcpI,GAXKL,EACJO,EAAIP,EAEJO,EAAId,EAAMY,CAAI,EAGVX,EACJa,EAAGL,EAAQR,EAAMW,CAAI,CAAE,EAEvBE,EAAGL,CAAO,EAENL,IAAS,EACb,OAAOK,EAAQJ,EAAQ,CAAE,EAE1B,GAAKD,IAAS,EAGd,OAAOK,EAAO,MAAON,CAAI,CAC1B,CACD,CAKApB,EAAO,QAAUgB,IC9KjB,IAAIgB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_index_of_types", "__commonJSMin", "exports", "module", "indexOfTypes", "N", "M", "x", "strideX1", "strideX2", "offsetX", "y", "strideY", "offsetY", "ix", "iy", "i", "j", "require_main", "__commonJSMin", "exports", "module", "isNonNegativeInteger", "isPositiveInteger", "isInteger", "isFunctionArray", "isFunction", "isCollection", "isndarrayLike", "format", "getDType", "resolveEnum", "indexOfTypes", "types2enums", "types", "out", "i", "dispatch", "fcns", "data", "nargs", "nin", "nout", "narrays", "nfcns", "fcn", "dispatcher", "arrays", "dtypes", "argc", "idx", "v", "f", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 02fe150..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,87 +0,0 @@ - -{{alias}}( fcns, types, data, nargs, nin, nout ) - Returns an ndarray function interface which performs multiple dispatch. - - An ndarray function interface has the following signature: - - f( x, y, ... ) - - where - - - x: ndarray. - - y: ndarray. - - ...: additional ndarrays. - - The number of parameters is derived from `nargs`, the number of input - ndarrays is derived from `nin`, and the number of output ndarrays is derived - from `nout`. - - Parameters - ---------- - fcns: Function|ArrayLikeObject - List of ndarray functions. An ndarray function should have the following - signature: - - f( arrays, data ) - - where - - - arrays: array containing input and output ndarrays. - - data: ndarray function data (e.g., a callback). - - For convenience, a single ndarray function may be provided which will be - invoked whenever the ndarray argument data types match a sequence of - types in `types`. Providing a single ndarray function is particularly - convenient for the case where, regardless of array data types, - traversing arrays remains the same, but the ndarray function `data` - differs (e.g., callbacks which differ based on the array data types). - - types: ArrayLikeObject - One-dimensional list of ndarray argument data types. - - data: ArrayLikeObject|null - ndarray function data (e.g., callbacks). If `null`, a returned ndarray - function interface does **not** provide a `data` argument to an invoked - ndarray function. - - nargs: integer - Total number of ndarray function interface arguments. - - nin: integer - Number of input ndarrays. - - nout: integer - Number of output ndarrays. - - Returns - ------- - fcn: Function - ndarray function interface. - - Examples - -------- - // Define ndarray argument data types: - > var t = [ 'float64', 'float64', 'float32', 'float32' ]; - - // Define a list of ndarray function data (callbacks): - > var d = [ {{alias:@stdlib/math/base/special/abs}}, {{alias:@stdlib/math/base/special/absf}} ]; - - // Create an ndarray function interface for applying unary callbacks: - > var f = {{alias}}( {{alias:@stdlib/ndarray/base/unary}}, t, d, 2, 1, 1 ); - - // Create an input ndarray: - > var xbuf = new {{alias:@stdlib/array/float64}}( [ -1.0, -2.0, -3.0, -4.0 ] ); - > var x = {{alias:@stdlib/ndarray/ctor}}( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Create an output ndarray: - > var ybuf = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 0.0, 0.0 ] ); - > var y = {{alias:@stdlib/ndarray/ctor}}( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Compute the element-wise absolute value: - > f( x, y ); - > ybuf - [ 1.0, 2.0, 3.0, 4.0 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index edd6866..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,641 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable max-lines */ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import dispatch = require( './index' ); - - -// FUNCTIONS // - -/** -* Nullary callback. -* -* @returns input value -*/ -function nullary(): any { - return 5.0; -} - -/** -* Unary callback. -* -* @param x - input value -* @returns input value -*/ -function unary( x: any ): any { - return x; -} - -/** -* Binary callback. -* -* @param x - input value -* @param y - input value -* @returns output value -*/ -function binary( x: number, y: number ): number { - return x + y; -} - -/** -* Ternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @returns output value -*/ -function ternary( x: number, y: number, z: number ): number { - return x + y + z; -} - -/** -* Quaternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @param w - input value -* @returns output value -*/ -function quaternary( x: number, y: number, z: number, w: number ): number { - return x + y + z + w; -} - -/** -* Mock `ind2sub` function. -* -* @param shape - dimensions -* @param idx - linear index -* @param opts - options -* @returns subscripts -*/ -function ind2sub( shape: ArrayLike, idx: number, opts?: any ): Array { - let out; - let i; - - out = []; - if ( typeof opts === 'object' && opts !== null && opts.order === 'row-major' ) { no-unsafe-any - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } else { - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } - return out; -} - -/** -* Mock ndarray function. -* -* @param arrays - ndarrays -* @param fcn - callback -*/ -function ndarrayFcn( arrays: Array, fcn: ( x: any ) => any ): void { - let xord; - let yord; - let opts; - let sub; - let sh; - let N; - let x; - let y; - let v; - let i; - - x = arrays[ 0 ]; - y = arrays[ 1 ]; - sh = x.shape; - if ( sh.length === 0 ) { - return; - } - N = 1; - for ( i = 0; i < sh.length; i += 1 ) { - N *= sh[ i ]; - } - xord = x.order; - yord = y.order; - opts = { - 'order': '' - }; - opts.order = xord; - for ( i = 0; i < N; i += 1 ) { - // Convert a linear index to subscripts: - opts.order = xord; - sub = ind2sub( sh, i, opts ); - - // Retrieve an element from `x`: - v = x.get.apply( x, sub ); - - // Convert a linear index to subscripts: - opts.order = yord; - sub = ind2sub( sh, i, opts ); - - // Append the result of applying the callback: - sub[ sub.length ] = fcn( v ) as number; - - // Assign the result to an element in `y`: - y.set.apply( y, sub ); - } -} - -/** -* Mock function to create an ndarray-like object. -* -* @returns ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a dispatch function... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, 1 ); // $ExpectType Dispatcher - dispatch( [ ndarrayFcn ], types, data, 2, 1, 1 ); // $ExpectType Dispatcher -} - -// The compiler throws an error if the function is provided a first argument which is not either an ndarray function or an array-like object containing ndarray functions... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( '10', types, data, 2, 1, 1 ); // $ExpectError - dispatch( 10, types, data, 2, 1, 1 ); // $ExpectError - dispatch( true, types, data, 2, 1, 1 ); // $ExpectError - dispatch( false, types, data, 2, 1, 1 ); // $ExpectError - dispatch( null, types, data, 2, 1, 1 ); // $ExpectError - dispatch( undefined, types, data, 2, 1, 1 ); // $ExpectError - dispatch( [ '1' ], types, data, 2, 1, 1 ); // $ExpectError - dispatch( {}, types, data, 2, 1, 1 ); // $ExpectError - dispatch( ( x: number ): number => x, types, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object... -{ - const data = [ unary ]; - - dispatch( ndarrayFcn, 10, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, true, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, false, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, null, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, undefined, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, {}, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object or null... -{ - const types = [ 'float64', 'float64' ]; - - dispatch( ndarrayFcn, types, 10, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, true, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, false, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, undefined, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, {}, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, '10', 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, true, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, false, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, null, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, undefined, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, [ '1' ], 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, {}, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, ( x: number ): number => x, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, '10', 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, true, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, false, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, null, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, undefined, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, [ '1' ], 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, {}, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, ( x: number ): number => x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, '10' ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, true ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, false ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, null ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, undefined ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, [ '1' ] ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, {} ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch(); // $ExpectError - dispatch( ndarrayFcn ); // $ExpectError - dispatch( ndarrayFcn, types ); // $ExpectError - dispatch( ndarrayFcn, types, data ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, 1, 0 ); // $ExpectError -} - -// The function returns a dispatch function... -{ - const x = array(); - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const t1 = [ 'float64' ]; - const d1 = [ nullary ]; - const f1 = dispatch( ndarrayFcn, t1, d1, 1, 1, 0 ); - f1( x ); // $ExpectType void | ndarray - - const t2 = [ 'float64', 'float64' ]; - const d2 = [ unary ]; - const f2 = dispatch( ndarrayFcn, t2, d2, 2, 1, 1 ); - f2( x, y ); // $ExpectType void | ndarray - - const t3 = [ 'float64', 'float64', 'float64' ]; - const d3 = [ binary ]; - const f3 = dispatch( ndarrayFcn, t3, d3, 3, 2, 1 ); - f3( x, y, z ); // $ExpectType void | ndarray - - const t4 = [ 'float64', 'float64', 'float64', 'float64' ]; - const d4 = [ ternary ]; - const f4 = dispatch( ndarrayFcn, t4, d4, 4, 3, 1 ); - f4( x, y, z, w ); // $ExpectType void | ndarray - - const t5 = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const d5 = [ quaternary ]; - const f5 = dispatch( ndarrayFcn, t5, d5, 5, 4, 1 ); - f5( x, y, z, w, u ); // $ExpectType void | ndarray -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (1 ndarray)... -{ - const types = [ 'float64' ]; - const data = [ nullary ]; - - const f = dispatch( ndarrayFcn, types, data, 1, 0, 1 ); - f( '10' ); // $ExpectError - f( 10 ); // $ExpectError - f( true ); // $ExpectError - f( false ); // $ExpectError - f( null ); // $ExpectError - f( undefined ); // $ExpectError - f( [ '1' ] ); // $ExpectError - f( {} ); // $ExpectError - f( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( 10, y ); // $ExpectError - f( '10', y ); // $ExpectError - f( true, y ); // $ExpectError - f( false, y ); // $ExpectError - f( null, y ); // $ExpectError - f( undefined, y ); // $ExpectError - f( [ '1' ], y ); // $ExpectError - f( {}, y ); // $ExpectError - f( ( x: number ): number => x, y ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const x = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( x, 10 ); // $ExpectError - f( x, '10' ); // $ExpectError - f( x, true ); // $ExpectError - f( x, false ); // $ExpectError - f( x, null ); // $ExpectError - f( x, undefined ); // $ExpectError - f( x, [ '1' ] ); // $ExpectError - f( x, {} ); // $ExpectError - f( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( 10, y, z ); // $ExpectError - f( '10', y, z ); // $ExpectError - f( true, y, z ); // $ExpectError - f( false, y, z ); // $ExpectError - f( null, y, z ); // $ExpectError - f( undefined, y, z ); // $ExpectError - f( [ '1' ], y, z ); // $ExpectError - f( {}, y, z ); // $ExpectError - f( ( x: number ): number => x, y, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, 10, z ); // $ExpectError - f( x, '10', z ); // $ExpectError - f( x, true, z ); // $ExpectError - f( x, false, z ); // $ExpectError - f( x, null, z ); // $ExpectError - f( x, undefined, z ); // $ExpectError - f( x, [ '1' ], z ); // $ExpectError - f( x, {}, z ); // $ExpectError - f( x, ( x: number ): number => x, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, y, '10' ); // $ExpectError - f( x, y, true ); // $ExpectError - f( x, y, false ); // $ExpectError - f( x, y, null ); // $ExpectError - f( x, y, undefined ); // $ExpectError - f( x, y, [ '1' ] ); // $ExpectError - f( x, y, {} ); // $ExpectError - f( x, y, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( 10, y, z, w ); // $ExpectError - f( '10', y, z, w ); // $ExpectError - f( true, y, z, w ); // $ExpectError - f( false, y, z, w ); // $ExpectError - f( null, y, z, w ); // $ExpectError - f( undefined, y, z, w ); // $ExpectError - f( [ '1' ], y, z, w ); // $ExpectError - f( {}, y, z, w ); // $ExpectError - f( ( x: number ): number => x, y, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, 10, z, w ); // $ExpectError - f( x, '10', z, w ); // $ExpectError - f( x, true, z, w ); // $ExpectError - f( x, false, z, w ); // $ExpectError - f( x, null, z, w ); // $ExpectError - f( x, undefined, z, w ); // $ExpectError - f( x, [ '1' ], z, w ); // $ExpectError - f( x, {}, z, w ); // $ExpectError - f( x, ( x: number ): number => x, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, 10, w ); // $ExpectError - f( x, y, '10', w ); // $ExpectError - f( x, y, true, w ); // $ExpectError - f( x, y, false, w ); // $ExpectError - f( x, y, null, w ); // $ExpectError - f( x, y, undefined, w ); // $ExpectError - f( x, y, [ '1' ], w ); // $ExpectError - f( x, y, {}, w ); // $ExpectError - f( x, y, ( x: number ): number => x, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, z, 10 ); // $ExpectError - f( x, y, z, '10' ); // $ExpectError - f( x, y, z, true ); // $ExpectError - f( x, y, z, false ); // $ExpectError - f( x, y, z, null ); // $ExpectError - f( x, y, z, undefined ); // $ExpectError - f( x, y, z, [ '1' ] ); // $ExpectError - f( x, y, z, {} ); // $ExpectError - f( x, y, z, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( 10, y, z, w, u ); // $ExpectError - f( '10', y, z, w, u ); // $ExpectError - f( true, y, z, w, u ); // $ExpectError - f( false, y, z, w, u ); // $ExpectError - f( null, y, z, w, u ); // $ExpectError - f( undefined, y, z, w, u ); // $ExpectError - f( [ '1' ], y, z, w, u ); // $ExpectError - f( {}, y, z, w, u ); // $ExpectError - f( ( x: number ): number => x, y, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, 10, z, w, u ); // $ExpectError - f( x, '10', z, w, u ); // $ExpectError - f( x, true, z, w, u ); // $ExpectError - f( x, false, z, w, u ); // $ExpectError - f( x, null, z, w, u ); // $ExpectError - f( x, undefined, z, w, u ); // $ExpectError - f( x, [ '1' ], z, w, u ); // $ExpectError - f( x, {}, z, w, u ); // $ExpectError - f( x, ( x: number ): number => x, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, 10, w, u ); // $ExpectError - f( x, y, '10', w, u ); // $ExpectError - f( x, y, true, w, u ); // $ExpectError - f( x, y, false, w, u ); // $ExpectError - f( x, y, null, w, u ); // $ExpectError - f( x, y, undefined, w, u ); // $ExpectError - f( x, y, [ '1' ], w, u ); // $ExpectError - f( x, y, {}, w, u ); // $ExpectError - f( x, y, ( x: number ): number => x, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, 10, u ); // $ExpectError - f( x, y, z, '10', u ); // $ExpectError - f( x, y, z, true, u ); // $ExpectError - f( x, y, z, false, u ); // $ExpectError - f( x, y, z, null, u ); // $ExpectError - f( x, y, z, undefined, u ); // $ExpectError - f( x, y, z, [ '1' ], u ); // $ExpectError - f( x, y, z, {}, u ); // $ExpectError - f( x, y, z, ( x: number ): number => x, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fifth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, w, 10 ); // $ExpectError - f( x, y, z, w, '10' ); // $ExpectError - f( x, y, z, w, true ); // $ExpectError - f( x, y, z, w, false ); // $ExpectError - f( x, y, z, w, null ); // $ExpectError - f( x, y, z, w, undefined ); // $ExpectError - f( x, y, z, w, [ '1' ] ); // $ExpectError - f( x, y, z, w, {} ); // $ExpectError - f( x, y, z, w, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/add.js b/examples/add.js deleted file mode 100644 index 775b711..0000000 --- a/examples/add.js +++ /dev/null @@ -1,121 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var dispatch = require( './../lib' ); - -function add2( arrays ) { - var opts; - var xo; - var yo; - var zo; - var sx; - var sy; - var sz; - var sh; - var N; - var x; - var y; - var z; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - z = arrays[ 2 ]; - xo = x.order; - yo = y.order; - zo = z.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - opts.order = yo; - sy = ind2sub( sh, i, opts ); - v = x.get.apply( x, sx ) + y.get.apply( y, sy ); - - opts.order = zo; - sz = ind2sub( sh, i, opts ); - sz.push( v ); - z.set.apply( z, sz ); - } -} - -var fcns = [ - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2 -]; - -var types = [ - dtypes.float64, dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.int32, dtypes.int32, - dtypes.uint32, dtypes.uint32, dtypes.uint32, - dtypes.int16, dtypes.int16, dtypes.int16, - dtypes.uint16, dtypes.uint16, dtypes.uint16, - dtypes.int8, dtypes.int8, dtypes.int8, - dtypes.uint8, dtypes.uint8, dtypes.uint8, - dtypes.uint8c, dtypes.uint8c, dtypes.uint8c -]; - -var add = dispatch( fcns, types, null, 3, 2, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var zbuf = new Float64Array( xbuf.length ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var z = ndarray( 'float64', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); - -xbuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -ybuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -zbuf = new Int32Array( xbuf.length ); - -x = ndarray( 'int32', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'int32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -z = ndarray( 'int32', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); diff --git a/examples/sin.js b/examples/sin.js deleted file mode 100644 index 8cd4871..0000000 --- a/examples/sin.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int8Array = require( '@stdlib/array-int8' ); -var sin = require( '@stdlib/math-base-special-sin' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/strided-dtypes' ); -var dispatch = require( './../lib' ); - -function apply( arrays, fcn ) { - var opts; - var xo; - var yo; - var sx; - var sy; - var sh; - var N; - var x; - var y; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - xo = x.order; - yo = y.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - v = fcn( x.get.apply( x, sx ) ); - - opts.order = yo; - sy = ind2sub( sh, i, opts ); - sy.push( v ); - y.set.apply( y, sy ); - } -} - -var fcns = [ - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply -]; - -var types = [ - dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float64, - dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.float64, - dtypes.uint32, dtypes.float64, - dtypes.int16, dtypes.float64, - dtypes.int16, dtypes.float32, - dtypes.uint16, dtypes.float64, - dtypes.uint16, dtypes.float32, - dtypes.int8, dtypes.float64, - dtypes.int8, dtypes.float32, - dtypes.uint8, dtypes.float64, - dtypes.uint8, dtypes.float32, - dtypes.uint8c, dtypes.float64, - dtypes.uint8c, dtypes.float32 -]; - -var data = [ - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin -]; - -var sine = dispatch( fcns, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); - -xbuf = new Int8Array( [ 1, 2, 3, 4, 5 ] ); -ybuf = new Float32Array( xbuf.length ); - -x = ndarray( 'int8', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'float32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); diff --git a/examples/unary.js b/examples/unary.js deleted file mode 100644 index e9c3fb4..0000000 --- a/examples/unary.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -var unary = require( '@stdlib/ndarray-base-unary' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var dispatch = require( './../lib' ); - -var types = [ 'float64', 'float64' ]; - -var data = [ - abs -]; - -var absolute = dispatch( unary, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -absolute( x, y ); -console.log( ybuf ); -// => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 5f280a1..c49a4e4 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..17b911b --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@v0.2.2-esm/index.mjs";function m(m,f,l,p,w,v){var a,g,c;if(i(m))c=m;else if(!s(m))throw new TypeError(d("0jr5d",m));if(!n(f))throw new TypeError(d("0jr2y",f));if(!n(l)&&null!==l)throw new TypeError(d("0jr5e",l));if(!e(p))throw new TypeError(d("0jr5f",p));if(!r(w))throw new TypeError(d("0jr5X",w));if(!r(v))throw new TypeError(d("0jr5g",v));if(0===(a=w+v))throw new Error(d("0jr0h"));if(p!==a)throw new Error(d("0jr0i"));if(c){if(g=f.length/a,!t(g))throw new Error(d("0jr0j"))}else if(g=m.length,f.length!==g*a)throw new Error(d("0jr0j"));if(l&&l.length!==g)throw new Error(d("0jr0k"));return f=function(r){var e,t;for(e=[],t=0;t [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0jr5d', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0jr2y', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( '0jr5e', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0jr5f', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0jr5X', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0jr5g', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format('0jr0h') );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format('0jr0i') );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format('0jr0k') );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format('0jr0l') );\n\t\t\t}\n\t\t\tthrow new Error( format('0jr0m') );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( '0jr5h', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( '0jr5i', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format('0jr0n') );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found).\n*\n* ## Notes\n*\n* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types).\n* - The function assumes that `x` is stored in row-major order.\n* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`.\n* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value.\n*\n* @private\n* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension)\n* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension)\n* @param {ArrayLikeObject} x - input two-dimensional reference array\n* @param {integer} strideX1 - `x` stride length along first dimension\n* @param {integer} strideX2 - `x` stride length along second dimension\n* @param {NonNegativeInteger} offsetX - `x` starting index\n* @param {ArrayLikeObject} y - search array\n* @param {integer} strideY - `y` stride length\n* @param {NonNegativeInteger} offsetY - `y` starting index\n* @returns {integer} row index (if found) and `-1` otherwise\n*\n* @example\n* // Define a reference array to search:\n* var types = [\n* 'float64', 'float64', 'float64',\n* 'float32', 'float32', 'float32',\n* 'uint32', 'uint32', 'float64',\n* 'int32', 'int32', 'float64',\n* 'uint16', 'uint16', 'float64',\n* 'int16', 'int16', 'float64',\n* 'uint8', 'uint8', 'float64',\n* 'int8', 'int8', 'float64'\n* ];\n*\n* // Define reference array dimensions:\n* var N = 8; // rows\n* var M = 3; // columns\n*\n* // Define a search array:\n* y1 = [\n* 'float32', 'float32', 'float32',\n* ];\n*\n* // Find the list of types:\n* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 );\n* // returns 1\n*\n// Define a search array:\n* y2 = [\n* 'float32', 'float32', 'float64',\n* ];\n*\n* // Find the list of types:\n* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 );\n* // returns -1\n*/\nfunction indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len\n\tvar ix;\n\tvar iy;\n\tvar i;\n\tvar j;\n\n\t// Search for the first row which matches `y`...\n\tix = offsetX;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tiy = offsetY;\n\t\tfor ( j = 0; j < M; j++ ) {\n\t\t\tif ( x[ ix+(j*strideX2) ] !== y[ iy ] ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tiy += strideY;\n\t\t}\n\t\t// If we successfully iterated over all columns, then that means we've found a match...\n\t\tif ( j === M ) {\n\t\t\treturn i;\n\t\t}\n\t\tix += strideX1;\n\t}\n\treturn -1;\n}\n\n\n// EXPORTS //\n\nexport default indexOfTypes;\n"],"names":["dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","out","i","push","resolveEnum","types2enums","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","getDType","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","j","indexOfTypes","slice"],"mappings":";;0+BA0GA,SAASA,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAO,UAEzB,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAO,UAEzB,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAO,eAIzB,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAO,UAG1B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAO,UAGzB,OADAX,EA5GD,SAAsBA,GACrB,IAAIkB,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAInB,EAAMgB,OAAQG,IAC9BD,EAAIE,KAAMC,EAAarB,EAAOmB,KAE/B,OAAOD,CACR,CAmGSI,CAAatB,GAgBrB,WACC,IAAIuB,EACAC,EACAC,EACAC,EACAC,EACAC,EACAT,EAGJ,GADAM,EAAOI,UAAUb,OACZS,IAASvB,EAAQ,CACrB,GAAKuB,EAAOvB,EACX,MAAM,IAAIa,MAAOJ,EAAO,UAEzB,MAAM,IAAII,MAAOJ,EAAO,SACxB,CAGD,IAFAY,EAAS,GACTC,EAAS,GACHL,EAAI,EAAGA,EAAIjB,EAAOiB,IAAM,CAE7B,IAAMW,EADNH,EAAIE,UAAWV,IAEd,MAAKA,EAAIhB,EACF,IAAIO,UAAWC,EAAQ,QAASgB,IAEhC,IAAIjB,UAAWC,EAAQ,QAASgB,IAGxCJ,EAAOH,KAAMO,GACbH,EAAOJ,KAAMC,EAAaU,EAAUJ,IACpC,CAKD,IAHAD,EC1HF,SAAuBM,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAvB,EACAwB,EAIJ,IADAF,EAAKJ,EACClB,EAAI,EAAGA,EAAIa,EAAGb,IAAM,CAEzB,IADAuB,EAAKF,EACCG,EAAI,EAAGA,EAAIV,GACXC,EAAGO,EAAIE,EAAEP,KAAgBE,EAAGI,GADdC,IAInBD,GAAMH,EAGP,GAAKI,IAAMV,EACV,OAAOd,EAERsB,GAAMN,CACN,CACD,OAAQ,CACT,CDmGQS,CAActC,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGmB,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAId,UAAWC,EAAO,UAI5BiB,EADIrB,GAGAR,EAAM2B,GAGNzB,EACJ2B,EAAGL,EAAQtB,EAAMyB,IAEjBE,EAAGL,GAEJ,GAAc,IAATnB,EACJ,OAAOmB,EAAQlB,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOmB,EAAOsB,MAAO1C,EACrB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 88f0e3e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Create an ndarray function interface which performs multiple dispatch. -* -* @module @stdlib/ndarray-dispatch -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var dispatch = require( '@stdlib/ndarray-dispatch' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/index_of_types.js b/lib/index_of_types.js deleted file mode 100644 index fda2297..0000000 --- a/lib/index_of_types.js +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found). -* -* ## Notes -* -* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types). -* - The function assumes that `x` is stored in row-major order. -* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`. -* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value. -* -* @private -* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension) -* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension) -* @param {ArrayLikeObject} x - input two-dimensional reference array -* @param {integer} strideX1 - `x` stride length along first dimension -* @param {integer} strideX2 - `x` stride length along second dimension -* @param {NonNegativeInteger} offsetX - `x` starting index -* @param {ArrayLikeObject} y - search array -* @param {integer} strideY - `y` stride length -* @param {NonNegativeInteger} offsetY - `y` starting index -* @returns {integer} row index (if found) and `-1` otherwise -* -* @example -* // Define a reference array to search: -* var types = [ -* 'float64', 'float64', 'float64', -* 'float32', 'float32', 'float32', -* 'uint32', 'uint32', 'float64', -* 'int32', 'int32', 'float64', -* 'uint16', 'uint16', 'float64', -* 'int16', 'int16', 'float64', -* 'uint8', 'uint8', 'float64', -* 'int8', 'int8', 'float64' -* ]; -* -* // Define reference array dimensions: -* var N = 8; // rows -* var M = 3; // columns -* -* // Define a search array: -* y1 = [ -* 'float32', 'float32', 'float32', -* ]; -* -* // Find the list of types: -* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 ); -* // returns 1 -* -// Define a search array: -* y2 = [ -* 'float32', 'float32', 'float64', -* ]; -* -* // Find the list of types: -* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 ); -* // returns -1 -*/ -function indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len - var ix; - var iy; - var i; - var j; - - // Search for the first row which matches `y`... - ix = offsetX; - for ( i = 0; i < N; i++ ) { - iy = offsetY; - for ( j = 0; j < M; j++ ) { - if ( x[ ix+(j*strideX2) ] !== y[ iy ] ) { - break; - } - iy += strideY; - } - // If we successfully iterated over all columns, then that means we've found a match... - if ( j === M ) { - return i; - } - ix += strideX1; - } - return -1; -} - - -// EXPORTS // - -module.exports = indexOfTypes; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4648598..0000000 --- a/lib/main.js +++ /dev/null @@ -1,231 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isFunctionArray = require( '@stdlib/assert-is-function-array' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var resolveEnum = require( '@stdlib/ndarray-base-dtype-resolve-enum' ); -var indexOfTypes = require( './index_of_types.js' ); - - -// FUNCTIONS // - -/** -* Returns a list of data type enumeration constants. -* -* @private -* @param {Collection} types - list of types -* @returns {IntegerArray} list of data type enumeration constants -*/ -function types2enums( types ) { - var out; - var i; - - out = []; - for ( i = 0; i < types.length; i++ ) { - out.push( resolveEnum( types[ i ] ) ); - } - return out; -} - - -// MAIN // - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param {(FunctionArray|Function)} fcns - list of ndarray functions -* @param {Collection} types - one-dimensional list of ndarray argument data types -* @param {(Collection|null)} data - ndarray function data (e.g., callbacks) -* @param {PositiveInteger} nargs - total number of ndarray function interface arguments -* @param {NonNegativeInteger} nin - number of input ndarrays -* @param {NonNegativeInteger} nout - number of output ndarrays -* @throws {TypeError} first argument must be either a function or an array of functions -* @throws {TypeError} second argument must be an array-like object -* @throws {TypeError} third argument must be an array-like object or `null` -* @throws {Error} third and first arguments must have the same number of elements -* @throws {TypeError} fourth argument must be a positive integer -* @throws {TypeError} fifth argument must be a nonnegative integer -* @throws {TypeError} sixth argument must be a nonnegative integer -* @throws {Error} fourth argument must equal the specified number of input and output arrays -* @throws {Error} number of types must match the number of functions times the total number of array arguments for each function -* @throws {Error} interface must accept at least one input and/or output ndarray -* @returns {Function} ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function dispatch( fcns, types, data, nargs, nin, nout ) { - var narrays; - var nfcns; - var fcn; - - if ( isFunction( fcns ) ) { - fcn = fcns; - } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( '0jr5d', fcns ) ); - } - if ( !isCollection( types ) ) { - throw new TypeError( format( '0jr2y', types ) ); - } - if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( '0jr5e', data ) ); - } - if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( '0jr5f', nargs ) ); - } - if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( '0jr5X', nin ) ); - } - if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( '0jr5g', nout ) ); - } - narrays = nin + nout; - if ( narrays === 0 ) { - throw new Error( format('0jr0h') ); - } - if ( nargs !== narrays ) { - throw new Error( format('0jr0i') ); - } - if ( fcn ) { - nfcns = types.length / narrays; - if ( !isInteger( nfcns ) ) { - throw new Error( format('0jr0j') ); - } - } else { - nfcns = fcns.length; - if ( types.length !== nfcns*narrays ) { - throw new Error( format('0jr0j') ); - } - } - if ( data && data.length !== nfcns ) { - throw new Error( format('0jr0k') ); - } - types = types2enums( types ); - return dispatcher; - - /** - * ndarray function interface which performs multiple dispatch. - * - * @private - * @param {ndarrayLike} x - ndarray - * @param {...ndarrayLike} args - ndarray arguments - * @throws {Error} insufficient arguments - * @throws {Error} too many arguments - * @throws {TypeError} input array arguments must be ndarray-like objects - * @throws {TypeError} output array arguments must be ndarray-like objects - * @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types - * @returns {(ndarrayLike|Array|void)} destination array(s) - */ - function dispatcher() { - var arrays; - var dtypes; - var argc; - var idx; - var v; - var f; - var i; - - argc = arguments.length; - if ( argc !== nargs ) { - if ( argc < nargs ) { - throw new Error( format('0jr0l') ); - } - throw new Error( format('0jr0m') ); - } - arrays = []; - dtypes = []; - for ( i = 0; i < nargs; i++ ) { - v = arguments[ i ]; - if ( !isndarrayLike( v ) ) { - if ( i < nin ) { - throw new TypeError( format( '0jr5h', v ) ); - } else { - throw new TypeError( format( '0jr5i', v ) ); - } - } - arrays.push( v ); - dtypes.push( resolveEnum( getDType( v ) ) ); - } - // Resolve the ndarray function satisfying the input array types: - idx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len - - // Check whether we were able to successfully resolve an ndarray function: - if ( idx < 0 ) { - throw new TypeError( format('0jr0n') ); - } - // Retrieve the ndarray function: - if ( fcn ) { - f = fcn; - } else { - f = fcns[ idx ]; - } - // Evaluate the ndarray function: - if ( data ) { - f( arrays, data[ idx ] ); - } else { - f( arrays ); - } - if ( nout === 1 ) { - return arrays[ narrays-1 ]; - } - if ( nout === 0 ) { - return; - } - return arrays.slice( nin ); - } -} - - -// EXPORTS // - -module.exports = dispatch; diff --git a/package.json b/package.json index 16afec6..e6c8bad 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Create an ndarray function interface which performs multiple dispatch.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,57 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-function-array": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer": "^0.2.2", - "@stdlib/assert-is-positive-integer": "^0.2.2", - "@stdlib/ndarray-base-dtype-resolve-enum": "^0.2.2", - "@stdlib/ndarray-dtype": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.2.2", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/array-int8": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/math-base-assert-is-nan": "^0.2.2", - "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/math-base-special-pow": "^0.3.0", - "@stdlib/math-base-special-sin": "^0.3.0", - "@stdlib/ndarray-base-buffer-dtype": "^0.3.0", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-unary": "^0.2.1", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-dtypes": "^0.3.0", - "@stdlib/ndarray-ind2sub": "^0.2.2", - "@stdlib/strided-dtypes": "^0.3.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "ndarray", @@ -100,7 +26,6 @@ "multimethod", "multimethods" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..252182f --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/fixtures/binary.js b/test/fixtures/binary.js deleted file mode 100644 index a60dfa2..0000000 --- a/test/fixtures/binary.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Binary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @returns {number} sum -*/ -function binary( x, y ) { - return x + y; -} - - -// EXPORTS // - -module.exports = binary; diff --git a/test/fixtures/fill.js b/test/fixtures/fill.js deleted file mode 100644 index 41b2958..0000000 --- a/test/fixtures/fill.js +++ /dev/null @@ -1,76 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which fills one or more ndarrays. -* -* @private -* @param {*} value - fill value -* @returns {Function} ndarray function -*/ -function fill( value ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - */ - function ndarrayFcn( arrays ) { - var opts; - var sub; - var arr; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - opts = { - 'order': '' - }; - for ( j = 0; j < M; j++ ) { - arr = arrays[ j ]; - opts.order = arrays[ j ].order; - for ( i = 0; i < N; i++ ) { - sub = ind2sub( sh, i, opts ); - sub.push( value ); - arr.set.apply( arr, sub ); - } - } - } -} - - -// EXPORTS // - -module.exports = fill; diff --git a/test/fixtures/foreach.js b/test/fixtures/foreach.js deleted file mode 100644 index a426290..0000000 --- a/test/fixtures/foreach.js +++ /dev/null @@ -1,72 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function forEach( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - fcn.apply( null, args ); - } -} - - -// EXPORTS // - -module.exports = forEach; diff --git a/test/fixtures/map1n.js b/test/fixtures/map1n.js deleted file mode 100644 index 614196b..0000000 --- a/test/fixtures/map1n.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function which maps the return value of a callback to `N` arrays. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function map1N( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var v; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - v = fcn(); - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - sub.push( v ); - arrays[ j ].set.apply( arrays[ j ], sub ); - } - } -} - - -// EXPORTS // - -module.exports = map1N; diff --git a/test/fixtures/nullary.js b/test/fixtures/nullary.js deleted file mode 100644 index 4f22126..0000000 --- a/test/fixtures/nullary.js +++ /dev/null @@ -1,36 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Nullary callback. -* -* @private -* @returns {number} value -*/ -function nullary() { - return 3.0; -} - - -// EXPORTS // - -module.exports = nullary; diff --git a/test/fixtures/quaternary.js b/test/fixtures/quaternary.js deleted file mode 100644 index 548437b..0000000 --- a/test/fixtures/quaternary.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quaternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @returns {number} sum -*/ -function quaternary( x, y, z, w ) { - return x + y + z + w; -} - - -// EXPORTS // - -module.exports = quaternary; diff --git a/test/fixtures/quinary.js b/test/fixtures/quinary.js deleted file mode 100644 index 36068de..0000000 --- a/test/fixtures/quinary.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quinary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @param {number} u - input value -* @returns {number} sum -*/ -function quinary( x, y, z, w, u ) { - return x + y + z + w + u; -} - - -// EXPORTS // - -module.exports = quinary; diff --git a/test/fixtures/sum.js b/test/fixtures/sum.js deleted file mode 100644 index efdbb1b..0000000 --- a/test/fixtures/sum.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which computes the sum across one or more ndarrays. -* -* @private -* @param {Object} ctx - context -* @param {number} ctx.sum - initial sum -* @returns {Function} ndarray function -*/ -function wrapper( ctx ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - * @param {Function} [fcn] - callback - */ - function ndarrayFcn( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var f; - var i; - var j; - - if ( arguments.length > 1 ) { - f = fcn; - } - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - if ( f ) { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - ctx.sum += f.apply( null, args ); - } - } else { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - ctx.sum += arrays[ j ].get.apply( arrays[ j ], sub ); - } - } - } - } -} - - -// EXPORTS // - -module.exports = wrapper; diff --git a/test/fixtures/ternary.js b/test/fixtures/ternary.js deleted file mode 100644 index 0595d5f..0000000 --- a/test/fixtures/ternary.js +++ /dev/null @@ -1,39 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Ternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @returns {number} sum -*/ -function ternary( x, y, z ) { - return x + y + z; -} - - -// EXPORTS // - -module.exports = ternary; diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d6c2c8e..0000000 --- a/test/test.js +++ /dev/null @@ -1,363 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var fill = require( './fixtures/fill.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either a function or an array of functions as a first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( value, types, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object as a second argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided either an array-like object or `null` as a third argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - dispatch( unary, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a positive integer for a fourth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 0, - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a fifth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, value, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a sixth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, 1, value ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function array)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var fcns = [ unary, unary, unary ]; - var data = [ abs, abs, abs ]; - dispatch( fcns, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function argument)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs, abs, abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the length of `data` argument does not match the number of ndarray functions', function test( t ) { - var values; - var i; - - values = [ - [], - [ abs, abs ], - [ abs, abs, abs ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var fcns = [ unary ]; - dispatch( fcns, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the fourth argument is incompatible with the number of input and output ndarrays', function test( t ) { - var values; - var i; - - values = [ - 0, - 1, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of specified input and output ndarrays is zero', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var types = [ 'float64' ]; - dispatch( fill( 3 ), types, null, 1, 0, 0 ); - } -}); - -tape( 'the function returns an ndarray function interface', function test( t ) { - var types; - var data; - var f; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - f = dispatch( unary, types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ unary ], types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( fill( 3 ), types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ fill( 3 ) ], types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.two_arrays.js b/test/test.two_arrays.js deleted file mode 100644 index 16eb61b..0000000 --- a/test/test.two_arrays.js +++ /dev/null @@ -1,814 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var dtype = require( '@stdlib/ndarray-base-buffer-dtype' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var forEach = require( './fixtures/foreach.js' ); -var map1N = require( './fixtures/map1n.js' ); -var fill = require( './fixtures/fill.js' ); -var sum = require( './fixtures/sum.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the first argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var ybuf = new Float64Array( 10 ); - var y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( value, y ); - }; - } -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the second argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var xbuf = new Float64Array( 10 ); - var x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( x, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided insufficient arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var f; - var x; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [], - [ x ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided too many arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var ybuf; - var f; - var x; - var y; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [ x, y, y ], - [ x, y, y, y ], - [ x, y, y, y, y ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if unable to resolve a ndarray function supporting the provided array argument data types', function test( t ) { - var values; - var types; - var data; - var xbuf; - var fcn; - var x; - var i; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ abs, abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 4 ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - values = [ - new Uint8Array( 4 ), - new Int32Array( 4 ), - [ 0, 0, 0, 0 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided an array having data type: ' + dtype( values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var y = ndarray( dtype( value ), value, [ value.length ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - }; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only input arrays)', function test( t ) { - var types; - var xbuf; - var ybuf; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only output arrays)', function test( t ) { - var expected; - var types; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only input arrays)', function test( t ) { - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var ctx; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcns = [ - sum( ctx ), - sum( ctx ) - ]; - fcn = dispatch( fcns, types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only output arrays)', function test( t ) { - var expected; - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcns = [ - fill( 3.0 ), - fill( 4.0 ) - ]; - fcn = dispatch( fcns, types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - - fcn = dispatch( forEach, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - - fcn = dispatch( map1N, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - fcns = [ - forEach, - forEach - ]; - fcn = dispatch( fcns, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - fcns = [ - map1N, - map1N - ]; - fcn = dispatch( fcns, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - fcns = [ - unary, - unary - ]; - fcn = dispatch( fcns, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which returns one or more output arrays, if one or more output arrays is specified, and otherwise returns `undefined`', function test( t ) { - var types; - var data; - var xbuf; - var ybuf; - var out; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - // No output arrays... - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, void 0, 'returns expected value' ); - - // One output array... - data = [ - abs, - abs - ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - fcn = dispatch( fill( 3.0 ), types, null, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - // Two output arrays... - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.end(); -}); From c8884c5df6e46223603b332e131514c451f8d626 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 7 Apr 2025 01:55:05 +0000 Subject: [PATCH 092/109] Transform error messages --- lib/main.js | 34 +++++++++++++++++----------------- package.json | 2 +- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/main.js b/lib/main.js index 5f4bb5d..4648598 100644 --- a/lib/main.js +++ b/lib/main.js @@ -27,7 +27,7 @@ var isFunctionArray = require( '@stdlib/assert-is-function-array' ); var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var getDType = require( '@stdlib/ndarray-dtype' ); var resolveEnum = require( '@stdlib/ndarray-base-dtype-resolve-enum' ); var indexOfTypes = require( './index_of_types.js' ); @@ -112,43 +112,43 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { if ( isFunction( fcns ) ) { fcn = fcns; } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) ); + throw new TypeError( format( '0jr5d', fcns ) ); } if ( !isCollection( types ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) ); + throw new TypeError( format( '0jr2y', types ) ); } if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); + throw new TypeError( format( '0jr5e', data ) ); } if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) ); + throw new TypeError( format( '0jr5f', nargs ) ); } if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) ); + throw new TypeError( format( '0jr5X', nin ) ); } if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) ); + throw new TypeError( format( '0jr5g', nout ) ); } narrays = nin + nout; if ( narrays === 0 ) { - throw new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' ); + throw new Error( format('0jr0h') ); } if ( nargs !== narrays ) { - throw new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' ); + throw new Error( format('0jr0i') ); } if ( fcn ) { nfcns = types.length / narrays; if ( !isInteger( nfcns ) ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format('0jr0j') ); } } else { nfcns = fcns.length; if ( types.length !== nfcns*narrays ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format('0jr0j') ); } } if ( data && data.length !== nfcns ) { - throw new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' ); + throw new Error( format('0jr0k') ); } types = types2enums( types ); return dispatcher; @@ -178,9 +178,9 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { argc = arguments.length; if ( argc !== nargs ) { if ( argc < nargs ) { - throw new Error( 'invalid invocation. Insufficient arguments.' ); + throw new Error( format('0jr0l') ); } - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('0jr0m') ); } arrays = []; dtypes = []; @@ -188,9 +188,9 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { v = arguments[ i ]; if ( !isndarrayLike( v ) ) { if ( i < nin ) { - throw new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) ); + throw new TypeError( format( '0jr5h', v ) ); } else { - throw new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) ); + throw new TypeError( format( '0jr5i', v ) ); } } arrays.push( v ); @@ -201,7 +201,7 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { // Check whether we were able to successfully resolve an ndarray function: if ( idx < 0 ) { - throw new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' ); + throw new TypeError( format('0jr0n') ); } // Retrieve the ndarray function: if ( fcn ) { diff --git a/package.json b/package.json index 12f46eb..5f84ca4 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/assert-is-positive-integer": "^0.2.2", "@stdlib/ndarray-base-dtype-resolve-enum": "^0.2.2", "@stdlib/ndarray-dtype": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 71b214c09dc65303ec6dfcb3d8b53d2024154665 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 7 Apr 2025 01:59:46 +0000 Subject: [PATCH 093/109] Remove files --- index.d.ts | 334 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5181 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index c49a4e4..0000000 --- a/index.d.ts +++ /dev/null @@ -1,334 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* ndarray function. -* -* @param arrays - array containing input and output ndarrays -* @param data - ndarray function data (e.g., a callback) -* -* @example -* var numel = require( '@stdlib/ndarray-base-numel' ); -* var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -* -* function ndarrayFcn( arrays, fcn ) { -* var xord; -* var yord; -* var opts; -* var sub; -* var sh; -* var N; -* var x; -* var y; -* var v; -* var i; -* -* x = arrays[ 0 ]; -* y = arrays[ 1 ]; -* sh = x.shape; -* N = numel( sh ); -* if ( N <= 0 ) { -* return; -* } -* xord = x.order; -* yord = y.order; -* opts = {}; -* opts.order = xord; -* for ( i = 0; i < N; i++ ) { -* // Convert a linear index to subscripts: -* opts.order = xord; -* sub = ind2sub( sh, i, opts ); -* -* // Retrieve an element from `x`: -* v = x.get.apply( x, sub ); -* -* // Convert a linear index to subscripts: -* opts.order = yord; -* sub = ind2sub( sh, i, opts ); -* -* // Append the result of applying the callback: -* sub.push( fcn( v ) ); -* -* // Assign the result to an element in `y`: -* y.set.apply( y, sub ); -* } -* } -*/ -type ndarrayFcn = ( arrays: Array, data?: any ) => void; - -/** -* Interface describing an ndarray function dispatcher. -*/ -interface Dispatcher { - /** - * Invokes an ndarray function based on the provided array data type(s). - * - * @param x - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array - * - * @example - * var nullary = require( '@stdlib/ndarray-base-nullary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function value() { - * return 3.14; - * } - * - * var types = [ 'float64' ]; - * var data = [ value ]; - * - * var fcn = dispatch( nullary, types, data, 1, 0, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( 5 ); - * var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x ); - * // xbuf => [ 3.14, 3.14, 3.14, 3.14, 3.14 ] - */ - ( x: ndarray ): ndarray | void; - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var unary = require( '@stdlib/ndarray-base-unary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * var abs = require( '@stdlib/math-base-special-abs' ); - * - * var types = [ 'float64', 'float64' ]; - * var data = [ abs ]; - * - * var fcn = dispatch( unary, types, data, 2, 1, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - * var ybuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y ); - * // ybuf => [ 1.0, 2.0, 3.0 ] - */ - ( x: ndarray, y: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var ternary = require( '@stdlib/ndarray-base-ternary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function add2( x, y ) { - * return x + y; - * } - * - * var types = [ 'float64', 'float64', 'float64' ]; - * var data = [ add2 ]; - * - * var fcn = dispatch( ternary, types, data, 3, 2, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z ); - * // zbuf => [ 2.0, 4.0, 6.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quaternary = require( '@stdlib/ndarray-base-quaternary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function add3( x, y, z ) { - * return x + y + z; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add3 ]; - * - * var fcn = dispatch( quaternary, types, data, 4, 3, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w ); - * // wbuf => [ 3.0, 6.0, 9.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @param args - ndarray arguments - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quinary = require( '@stdlib/ndarray-base-quinary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function add4( x, y, z, w ) { - * return x + y + z + w; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add4 ]; - * - * var fcn = dispatch( quinary, types, data, 5, 4, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ubuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var u = ndarray( 'float64', ubuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w, u ); - * // ubuf => [ 4.0, 8.0, 12.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray, ...args: Array ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures -} - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param fcns - list of ndarray functions -* @param types - one-dimensional list of ndarray argument data types -* @param data - ndarray function data (e.g., callbacks) -* @param nargs - total number of ndarray function interface arguments -* @param nin - number of input ndarrays -* @param nout - number of output ndarrays -* @throws first argument must be either a function or an array of functions -* @throws second argument must be an array-like object -* @throws third argument must be an array-like object or `null` -* @throws third and first arguments must have the same number of elements -* @throws fourth argument must be a positive integer -* @throws fifth argument must be a nonnegative integer -* @throws sixth argument must be a nonnegative integer -* @throws fourth argument must equal the specified number of input and output arrays -* @throws number of types must match the number of functions times the total number of array arguments for each function -* @throws interface must accept at least one input and/or output ndarray -* @returns ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var fcn = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* fcn( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function dispatch( fcns: ndarrayFcn | ArrayLike, types: ArrayLike, data: ArrayLike | null, nargs: number, nin: number, nout: number ): Dispatcher; - - -// EXPORTS // - -export = dispatch; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 17b911b..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@v0.2.2-esm/index.mjs";function m(m,f,l,p,w,v){var a,g,c;if(i(m))c=m;else if(!s(m))throw new TypeError(d("0jr5d",m));if(!n(f))throw new TypeError(d("0jr2y",f));if(!n(l)&&null!==l)throw new TypeError(d("0jr5e",l));if(!e(p))throw new TypeError(d("0jr5f",p));if(!r(w))throw new TypeError(d("0jr5X",w));if(!r(v))throw new TypeError(d("0jr5g",v));if(0===(a=w+v))throw new Error(d("0jr0h"));if(p!==a)throw new Error(d("0jr0i"));if(c){if(g=f.length/a,!t(g))throw new Error(d("0jr0j"))}else if(g=m.length,f.length!==g*a)throw new Error(d("0jr0j"));if(l&&l.length!==g)throw new Error(d("0jr0k"));return f=function(r){var e,t;for(e=[],t=0;t [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0jr5d', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0jr2y', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( '0jr5e', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0jr5f', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0jr5X', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0jr5g', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format('0jr0h') );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format('0jr0i') );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format('0jr0k') );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format('0jr0l') );\n\t\t\t}\n\t\t\tthrow new Error( format('0jr0m') );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( '0jr5h', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( '0jr5i', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format('0jr0n') );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found).\n*\n* ## Notes\n*\n* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types).\n* - The function assumes that `x` is stored in row-major order.\n* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`.\n* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value.\n*\n* @private\n* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension)\n* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension)\n* @param {ArrayLikeObject} x - input two-dimensional reference array\n* @param {integer} strideX1 - `x` stride length along first dimension\n* @param {integer} strideX2 - `x` stride length along second dimension\n* @param {NonNegativeInteger} offsetX - `x` starting index\n* @param {ArrayLikeObject} y - search array\n* @param {integer} strideY - `y` stride length\n* @param {NonNegativeInteger} offsetY - `y` starting index\n* @returns {integer} row index (if found) and `-1` otherwise\n*\n* @example\n* // Define a reference array to search:\n* var types = [\n* 'float64', 'float64', 'float64',\n* 'float32', 'float32', 'float32',\n* 'uint32', 'uint32', 'float64',\n* 'int32', 'int32', 'float64',\n* 'uint16', 'uint16', 'float64',\n* 'int16', 'int16', 'float64',\n* 'uint8', 'uint8', 'float64',\n* 'int8', 'int8', 'float64'\n* ];\n*\n* // Define reference array dimensions:\n* var N = 8; // rows\n* var M = 3; // columns\n*\n* // Define a search array:\n* y1 = [\n* 'float32', 'float32', 'float32',\n* ];\n*\n* // Find the list of types:\n* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 );\n* // returns 1\n*\n// Define a search array:\n* y2 = [\n* 'float32', 'float32', 'float64',\n* ];\n*\n* // Find the list of types:\n* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 );\n* // returns -1\n*/\nfunction indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len\n\tvar ix;\n\tvar iy;\n\tvar i;\n\tvar j;\n\n\t// Search for the first row which matches `y`...\n\tix = offsetX;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tiy = offsetY;\n\t\tfor ( j = 0; j < M; j++ ) {\n\t\t\tif ( x[ ix+(j*strideX2) ] !== y[ iy ] ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tiy += strideY;\n\t\t}\n\t\t// If we successfully iterated over all columns, then that means we've found a match...\n\t\tif ( j === M ) {\n\t\t\treturn i;\n\t\t}\n\t\tix += strideX1;\n\t}\n\treturn -1;\n}\n\n\n// EXPORTS //\n\nexport default indexOfTypes;\n"],"names":["dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","out","i","push","resolveEnum","types2enums","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","getDType","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","j","indexOfTypes","slice"],"mappings":";;0+BA0GA,SAASA,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAO,UAEzB,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAO,UAEzB,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAO,eAIzB,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAO,UAG1B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAO,UAGzB,OADAX,EA5GD,SAAsBA,GACrB,IAAIkB,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAInB,EAAMgB,OAAQG,IAC9BD,EAAIE,KAAMC,EAAarB,EAAOmB,KAE/B,OAAOD,CACR,CAmGSI,CAAatB,GAgBrB,WACC,IAAIuB,EACAC,EACAC,EACAC,EACAC,EACAC,EACAT,EAGJ,GADAM,EAAOI,UAAUb,OACZS,IAASvB,EAAQ,CACrB,GAAKuB,EAAOvB,EACX,MAAM,IAAIa,MAAOJ,EAAO,UAEzB,MAAM,IAAII,MAAOJ,EAAO,SACxB,CAGD,IAFAY,EAAS,GACTC,EAAS,GACHL,EAAI,EAAGA,EAAIjB,EAAOiB,IAAM,CAE7B,IAAMW,EADNH,EAAIE,UAAWV,IAEd,MAAKA,EAAIhB,EACF,IAAIO,UAAWC,EAAQ,QAASgB,IAEhC,IAAIjB,UAAWC,EAAQ,QAASgB,IAGxCJ,EAAOH,KAAMO,GACbH,EAAOJ,KAAMC,EAAaU,EAAUJ,IACpC,CAKD,IAHAD,EC1HF,SAAuBM,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAvB,EACAwB,EAIJ,IADAF,EAAKJ,EACClB,EAAI,EAAGA,EAAIa,EAAGb,IAAM,CAEzB,IADAuB,EAAKF,EACCG,EAAI,EAAGA,EAAIV,GACXC,EAAGO,EAAIE,EAAEP,KAAgBE,EAAGI,GADdC,IAInBD,GAAMH,EAGP,GAAKI,IAAMV,EACV,OAAOd,EAERsB,GAAMN,CACN,CACD,OAAQ,CACT,CDmGQS,CAActC,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGmB,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAId,UAAWC,EAAO,UAI5BiB,EADIrB,GAGAR,EAAM2B,GAGNzB,EACJ2B,EAAGL,EAAQtB,EAAMyB,IAEjBE,EAAGL,GAEJ,GAAc,IAATnB,EACJ,OAAOmB,EAAQlB,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOmB,EAAOsB,MAAO1C,EACrB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 252182f..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 20917e445ba2e11fb64406251b63d8704342a0dd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 7 Apr 2025 02:00:10 +0000 Subject: [PATCH 094/109] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 194 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 255 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 61 +- SECURITY.md | 5 - benchmark/benchmark.dispatch_size.js | 156 - benchmark/benchmark.js | 81 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 87 - docs/types/test.ts | 641 --- examples/add.js | 121 - examples/sin.js | 142 - examples/unary.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/index_of_types.js | 106 - lib/main.js | 231 - package.json | 79 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/binary.js | 38 - test/fixtures/fill.js | 76 - test/fixtures/foreach.js | 72 - test/fixtures/map1n.js | 74 - test/fixtures/nullary.js | 36 - test/fixtures/quaternary.js | 40 - test/fixtures/quinary.js | 41 - test/fixtures/sum.js | 98 - test/fixtures/ternary.js | 39 - test/test.js | 363 -- test/test.two_arrays.js | 814 --- 58 files changed, 4876 insertions(+), 7136 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.dispatch_size.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/add.js delete mode 100644 examples/sin.js delete mode 100644 examples/unary.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/index_of_types.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/fixtures/binary.js delete mode 100644 test/fixtures/fill.js delete mode 100644 test/fixtures/foreach.js delete mode 100644 test/fixtures/map1n.js delete mode 100644 test/fixtures/nullary.js delete mode 100644 test/fixtures/quaternary.js delete mode 100644 test/fixtures/quinary.js delete mode 100644 test/fixtures/sum.js delete mode 100644 test/fixtures/ternary.js delete mode 100644 test/test.js delete mode 100644 test/test.two_arrays.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 9886183..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-04-07T01:43:02.751Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 731bd4f..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/contributing/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 5e92c3e..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2b4fac7..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '43 7 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -304,7 +295,7 @@ console.log( ybuf ); ## 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. +This package is part of [stdlib][stdlib], a standard library 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]. @@ -367,11 +358,11 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-dispatch/main/LICENSE -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.dispatch_size.js b/benchmark/benchmark.dispatch_size.js deleted file mode 100644 index 15805ba..0000000 --- a/benchmark/benchmark.dispatch_size.js +++ /dev/null @@ -1,156 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib/main.js' ); - - -// FUNCTIONS // - -/** -* Evaluates the identity function. -* -* @private -* @param {*} v - value -* @returns {*} input value -*/ -function identity( v ) { - return v; -} - -/** -* Dummy function which throws an error. -* -* @private -* @throws {Error} unexpected error -*/ -function throwError() { - throw new Error( 'unexpected error' ); -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} size - dispatch size -* @returns {Function} benchmark function -*/ -function createBenchmark( size ) { - var types; - var data; - var fcn; - var x; - var y; - var t; - var i; - - types = []; - - // Create dummy types... - for ( i = 0; i < (size-1)*2; i += 2 ) { - t = 'foo' + i; - types.push( t ); - types.push( t ); - } - // Append test types: - types.push( 'float64' ); - types.push( 'float64' ); - - // Define a list of callbacks: - data = []; - for ( i = 0; i < size-1; i++ ) { - data.push( throwError ); - } - // Append a test callback: - data.push( identity ); - - // Create the dispatcher: - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - // Create sample arrays: - x = new Float64Array( 1 ); - y = new Float64Array( x.length ); - - x = ndarray( 'float64', x, [ 1 ], [ 1 ], 0, 'row-major' ); - y = ndarray( 'float64', y, [ 1 ], [ 1 ], 0, 'row-major' ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var z; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x.data[ 0 ] = i; - z = fcn( x, y ); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var size; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - size = pow( 2, i ); - f = createBenchmark( size ); - bench( pkg+':size='+size, f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 3c6f450..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::fcns_array', function benchmark( b ) { - var types; - var fcns; - var data; - var out; - var i; - - fcns = [ unary ]; - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( fcns, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::fcn_arg', function benchmark( b ) { - var types; - var data; - var out; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( unary, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0aae4af..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch" -%% click B href "https://github.com/stdlib-js/ndarray-dispatch/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-dispatch/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-dispatch/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-dispatch/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-dispatch/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch -[production-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 1295a44..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import dispatch from '../docs/types/index'; -export = dispatch; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c23dc5d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var y=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var b=y(function(D,w){"use strict";function k(i,r,e,u,f,m,n,o,l){var h,t,s,a;for(h=m,s=0;s [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( 'invalid invocation. Insufficient arguments.' );\n\t\t\t}\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = dispatch;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an ndarray function interface which performs multiple dispatch.\n*\n* @module @stdlib/ndarray-dispatch\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var unary = require( '@stdlib/ndarray-base-unary' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var Float64Array = require( '@stdlib/array-float64' );\n* var dispatch = require( '@stdlib/ndarray-dispatch' );\n*\n* var types = [\n* 'float64', 'float64'\n* ];\n*\n* var data = [\n* abs\n* ];\n*\n* var absolute = dispatch( unary, types, data, 2, 1, 1 );\n*\n* // ...\n*\n* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] );\n* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] );\n*\n* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' );\n* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' );\n*\n* absolute( x, y );\n* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA6EA,SAASC,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,EAAU,CAClF,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,CAAU,IAAME,EAAGI,CAAG,EADjBE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,CACP,CACA,MAAO,EACR,CAKAL,EAAO,QAAUC,ICzGjB,IAAAc,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAoB,QAAS,oCAAqC,EAClEC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAkB,QAAS,kCAAmC,EAC9DC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAc,QAAS,yCAA0C,EACjEC,EAAe,IAYnB,SAASC,EAAaC,EAAQ,CAC7B,IAAIC,EACAC,EAGJ,IADAD,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIF,EAAM,OAAQE,IAC9BD,EAAI,KAAMJ,EAAaG,EAAOE,CAAE,CAAE,CAAE,EAErC,OAAOD,CACR,CAqDA,SAASE,EAAUC,EAAMJ,EAAOK,EAAMC,EAAOC,EAAKC,EAAO,CACxD,IAAIC,EACAC,EACAC,EAEJ,GAAKnB,EAAYY,CAAK,EACrBO,EAAMP,UACK,CAACb,EAAiBa,CAAK,EAClC,MAAM,IAAI,UAAWT,EAAQ,oGAAqGS,CAAK,CAAE,EAE1I,GAAK,CAACX,EAAcO,CAAM,EACzB,MAAM,IAAI,UAAWL,EAAQ,+EAAgFK,CAAM,CAAE,EAEtH,GAAK,CAACP,EAAcY,CAAK,GAAKA,IAAS,KACtC,MAAM,IAAI,UAAWV,EAAQ,sFAAuFU,CAAK,CAAE,EAE5H,GAAK,CAAChB,EAAmBiB,CAAM,EAC9B,MAAM,IAAI,UAAWX,EAAQ,6EAA8EW,CAAM,CAAE,EAEpH,GAAK,CAAClB,EAAsBmB,CAAI,EAC/B,MAAM,IAAI,UAAWZ,EAAQ,+EAAgFY,CAAI,CAAE,EAEpH,GAAK,CAACnB,EAAsBoB,CAAK,EAChC,MAAM,IAAI,UAAWb,EAAQ,+EAAgFa,CAAK,CAAE,EAGrH,GADAC,EAAUF,EAAMC,EACXC,IAAY,EAChB,MAAM,IAAI,MAAO,4IAA6I,EAE/J,GAAKH,IAAUG,EACd,MAAM,IAAI,MAAO,4FAA6F,EAE/G,GAAKE,GAEJ,GADAD,EAAQV,EAAM,OAASS,EAClB,CAACnB,EAAWoB,CAAM,EACtB,MAAM,IAAI,MAAO,8IAA+I,UAGjKA,EAAQN,EAAK,OACRJ,EAAM,SAAWU,EAAMD,EAC3B,MAAM,IAAI,MAAO,8IAA+I,EAGlK,GAAKJ,GAAQA,EAAK,SAAWK,EAC5B,MAAM,IAAI,MAAO,mGAAoG,EAEtH,OAAAV,EAAQD,EAAaC,CAAM,EACpBY,EAeP,SAASA,GAAa,CACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EAGJ,GADAa,EAAO,UAAU,OACZA,IAAST,EACb,MAAKS,EAAOT,EACL,IAAI,MAAO,6CAA8C,EAE1D,IAAI,MAAO,yCAA0C,EAI5D,IAFAO,EAAS,CAAC,EACVC,EAAS,CAAC,EACJZ,EAAI,EAAGA,EAAII,EAAOJ,IAAM,CAE7B,GADAe,EAAI,UAAWf,CAAE,EACZ,CAACR,EAAeuB,CAAE,EACtB,MAAKf,EAAIK,EACF,IAAI,UAAWZ,EAAQ,6EAA8EsB,CAAE,CAAE,EAEzG,IAAI,UAAWtB,EAAQ,8EAA+EsB,CAAE,CAAE,EAGlHJ,EAAO,KAAMI,CAAE,EACfH,EAAO,KAAMjB,EAAaD,EAAUqB,CAAE,CAAE,CAAE,CAC3C,CAKA,GAHAD,EAAMlB,EAAcY,EAAOD,EAAST,EAAOS,EAAS,EAAG,EAAGK,EAAQ,EAAG,CAAE,EAGlEE,EAAM,EACV,MAAM,IAAI,UAAW,6GAA8G,EAcpI,GAXKL,EACJO,EAAIP,EAEJO,EAAId,EAAMY,CAAI,EAGVX,EACJa,EAAGL,EAAQR,EAAMW,CAAI,CAAE,EAEvBE,EAAGL,CAAO,EAENL,IAAS,EACb,OAAOK,EAAQJ,EAAQ,CAAE,EAE1B,GAAKD,IAAS,EAGd,OAAOK,EAAO,MAAON,CAAI,CAC1B,CACD,CAKApB,EAAO,QAAUgB,IC9KjB,IAAIgB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_index_of_types", "__commonJSMin", "exports", "module", "indexOfTypes", "N", "M", "x", "strideX1", "strideX2", "offsetX", "y", "strideY", "offsetY", "ix", "iy", "i", "j", "require_main", "__commonJSMin", "exports", "module", "isNonNegativeInteger", "isPositiveInteger", "isInteger", "isFunctionArray", "isFunction", "isCollection", "isndarrayLike", "format", "getDType", "resolveEnum", "indexOfTypes", "types2enums", "types", "out", "i", "dispatch", "fcns", "data", "nargs", "nin", "nout", "narrays", "nfcns", "fcn", "dispatcher", "arrays", "dtypes", "argc", "idx", "v", "f", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 02fe150..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,87 +0,0 @@ - -{{alias}}( fcns, types, data, nargs, nin, nout ) - Returns an ndarray function interface which performs multiple dispatch. - - An ndarray function interface has the following signature: - - f( x, y, ... ) - - where - - - x: ndarray. - - y: ndarray. - - ...: additional ndarrays. - - The number of parameters is derived from `nargs`, the number of input - ndarrays is derived from `nin`, and the number of output ndarrays is derived - from `nout`. - - Parameters - ---------- - fcns: Function|ArrayLikeObject - List of ndarray functions. An ndarray function should have the following - signature: - - f( arrays, data ) - - where - - - arrays: array containing input and output ndarrays. - - data: ndarray function data (e.g., a callback). - - For convenience, a single ndarray function may be provided which will be - invoked whenever the ndarray argument data types match a sequence of - types in `types`. Providing a single ndarray function is particularly - convenient for the case where, regardless of array data types, - traversing arrays remains the same, but the ndarray function `data` - differs (e.g., callbacks which differ based on the array data types). - - types: ArrayLikeObject - One-dimensional list of ndarray argument data types. - - data: ArrayLikeObject|null - ndarray function data (e.g., callbacks). If `null`, a returned ndarray - function interface does **not** provide a `data` argument to an invoked - ndarray function. - - nargs: integer - Total number of ndarray function interface arguments. - - nin: integer - Number of input ndarrays. - - nout: integer - Number of output ndarrays. - - Returns - ------- - fcn: Function - ndarray function interface. - - Examples - -------- - // Define ndarray argument data types: - > var t = [ 'float64', 'float64', 'float32', 'float32' ]; - - // Define a list of ndarray function data (callbacks): - > var d = [ {{alias:@stdlib/math/base/special/abs}}, {{alias:@stdlib/math/base/special/absf}} ]; - - // Create an ndarray function interface for applying unary callbacks: - > var f = {{alias}}( {{alias:@stdlib/ndarray/base/unary}}, t, d, 2, 1, 1 ); - - // Create an input ndarray: - > var xbuf = new {{alias:@stdlib/array/float64}}( [ -1.0, -2.0, -3.0, -4.0 ] ); - > var x = {{alias:@stdlib/ndarray/ctor}}( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Create an output ndarray: - > var ybuf = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 0.0, 0.0 ] ); - > var y = {{alias:@stdlib/ndarray/ctor}}( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Compute the element-wise absolute value: - > f( x, y ); - > ybuf - [ 1.0, 2.0, 3.0, 4.0 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index edd6866..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,641 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable max-lines */ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import { ArrayLike } from '@stdlib/types/array'; -import dispatch = require( './index' ); - - -// FUNCTIONS // - -/** -* Nullary callback. -* -* @returns input value -*/ -function nullary(): any { - return 5.0; -} - -/** -* Unary callback. -* -* @param x - input value -* @returns input value -*/ -function unary( x: any ): any { - return x; -} - -/** -* Binary callback. -* -* @param x - input value -* @param y - input value -* @returns output value -*/ -function binary( x: number, y: number ): number { - return x + y; -} - -/** -* Ternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @returns output value -*/ -function ternary( x: number, y: number, z: number ): number { - return x + y + z; -} - -/** -* Quaternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @param w - input value -* @returns output value -*/ -function quaternary( x: number, y: number, z: number, w: number ): number { - return x + y + z + w; -} - -/** -* Mock `ind2sub` function. -* -* @param shape - dimensions -* @param idx - linear index -* @param opts - options -* @returns subscripts -*/ -function ind2sub( shape: ArrayLike, idx: number, opts?: any ): Array { - let out; - let i; - - out = []; - if ( typeof opts === 'object' && opts !== null && opts.order === 'row-major' ) { no-unsafe-any - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } else { - for ( i = 0; i < shape.length; i += 1 ) { - out.push( idx % shape[ i ] ); - } - } - return out; -} - -/** -* Mock ndarray function. -* -* @param arrays - ndarrays -* @param fcn - callback -*/ -function ndarrayFcn( arrays: Array, fcn: ( x: any ) => any ): void { - let xord; - let yord; - let opts; - let sub; - let sh; - let N; - let x; - let y; - let v; - let i; - - x = arrays[ 0 ]; - y = arrays[ 1 ]; - sh = x.shape; - if ( sh.length === 0 ) { - return; - } - N = 1; - for ( i = 0; i < sh.length; i += 1 ) { - N *= sh[ i ]; - } - xord = x.order; - yord = y.order; - opts = { - 'order': '' - }; - opts.order = xord; - for ( i = 0; i < N; i += 1 ) { - // Convert a linear index to subscripts: - opts.order = xord; - sub = ind2sub( sh, i, opts ); - - // Retrieve an element from `x`: - v = x.get.apply( x, sub ); - - // Convert a linear index to subscripts: - opts.order = yord; - sub = ind2sub( sh, i, opts ); - - // Append the result of applying the callback: - sub[ sub.length ] = fcn( v ) as number; - - // Assign the result to an element in `y`: - y.set.apply( y, sub ); - } -} - -/** -* Mock function to create an ndarray-like object. -* -* @returns ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a dispatch function... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, 1 ); // $ExpectType Dispatcher - dispatch( [ ndarrayFcn ], types, data, 2, 1, 1 ); // $ExpectType Dispatcher -} - -// The compiler throws an error if the function is provided a first argument which is not either an ndarray function or an array-like object containing ndarray functions... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( '10', types, data, 2, 1, 1 ); // $ExpectError - dispatch( 10, types, data, 2, 1, 1 ); // $ExpectError - dispatch( true, types, data, 2, 1, 1 ); // $ExpectError - dispatch( false, types, data, 2, 1, 1 ); // $ExpectError - dispatch( null, types, data, 2, 1, 1 ); // $ExpectError - dispatch( undefined, types, data, 2, 1, 1 ); // $ExpectError - dispatch( [ '1' ], types, data, 2, 1, 1 ); // $ExpectError - dispatch( {}, types, data, 2, 1, 1 ); // $ExpectError - dispatch( ( x: number ): number => x, types, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object... -{ - const data = [ unary ]; - - dispatch( ndarrayFcn, 10, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, true, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, false, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, null, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, undefined, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, {}, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object or null... -{ - const types = [ 'float64', 'float64' ]; - - dispatch( ndarrayFcn, types, 10, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, true, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, false, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, undefined, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, {}, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, '10', 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, true, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, false, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, null, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, undefined, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, [ '1' ], 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, {}, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, ( x: number ): number => x, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, '10', 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, true, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, false, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, null, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, undefined, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, [ '1' ], 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, {}, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, ( x: number ): number => x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, '10' ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, true ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, false ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, null ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, undefined ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, [ '1' ] ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, {} ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch(); // $ExpectError - dispatch( ndarrayFcn ); // $ExpectError - dispatch( ndarrayFcn, types ); // $ExpectError - dispatch( ndarrayFcn, types, data ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, 1, 0 ); // $ExpectError -} - -// The function returns a dispatch function... -{ - const x = array(); - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const t1 = [ 'float64' ]; - const d1 = [ nullary ]; - const f1 = dispatch( ndarrayFcn, t1, d1, 1, 1, 0 ); - f1( x ); // $ExpectType void | ndarray - - const t2 = [ 'float64', 'float64' ]; - const d2 = [ unary ]; - const f2 = dispatch( ndarrayFcn, t2, d2, 2, 1, 1 ); - f2( x, y ); // $ExpectType void | ndarray - - const t3 = [ 'float64', 'float64', 'float64' ]; - const d3 = [ binary ]; - const f3 = dispatch( ndarrayFcn, t3, d3, 3, 2, 1 ); - f3( x, y, z ); // $ExpectType void | ndarray - - const t4 = [ 'float64', 'float64', 'float64', 'float64' ]; - const d4 = [ ternary ]; - const f4 = dispatch( ndarrayFcn, t4, d4, 4, 3, 1 ); - f4( x, y, z, w ); // $ExpectType void | ndarray - - const t5 = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const d5 = [ quaternary ]; - const f5 = dispatch( ndarrayFcn, t5, d5, 5, 4, 1 ); - f5( x, y, z, w, u ); // $ExpectType void | ndarray -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (1 ndarray)... -{ - const types = [ 'float64' ]; - const data = [ nullary ]; - - const f = dispatch( ndarrayFcn, types, data, 1, 0, 1 ); - f( '10' ); // $ExpectError - f( 10 ); // $ExpectError - f( true ); // $ExpectError - f( false ); // $ExpectError - f( null ); // $ExpectError - f( undefined ); // $ExpectError - f( [ '1' ] ); // $ExpectError - f( {} ); // $ExpectError - f( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( 10, y ); // $ExpectError - f( '10', y ); // $ExpectError - f( true, y ); // $ExpectError - f( false, y ); // $ExpectError - f( null, y ); // $ExpectError - f( undefined, y ); // $ExpectError - f( [ '1' ], y ); // $ExpectError - f( {}, y ); // $ExpectError - f( ( x: number ): number => x, y ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const x = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( x, 10 ); // $ExpectError - f( x, '10' ); // $ExpectError - f( x, true ); // $ExpectError - f( x, false ); // $ExpectError - f( x, null ); // $ExpectError - f( x, undefined ); // $ExpectError - f( x, [ '1' ] ); // $ExpectError - f( x, {} ); // $ExpectError - f( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( 10, y, z ); // $ExpectError - f( '10', y, z ); // $ExpectError - f( true, y, z ); // $ExpectError - f( false, y, z ); // $ExpectError - f( null, y, z ); // $ExpectError - f( undefined, y, z ); // $ExpectError - f( [ '1' ], y, z ); // $ExpectError - f( {}, y, z ); // $ExpectError - f( ( x: number ): number => x, y, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, 10, z ); // $ExpectError - f( x, '10', z ); // $ExpectError - f( x, true, z ); // $ExpectError - f( x, false, z ); // $ExpectError - f( x, null, z ); // $ExpectError - f( x, undefined, z ); // $ExpectError - f( x, [ '1' ], z ); // $ExpectError - f( x, {}, z ); // $ExpectError - f( x, ( x: number ): number => x, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, y, '10' ); // $ExpectError - f( x, y, true ); // $ExpectError - f( x, y, false ); // $ExpectError - f( x, y, null ); // $ExpectError - f( x, y, undefined ); // $ExpectError - f( x, y, [ '1' ] ); // $ExpectError - f( x, y, {} ); // $ExpectError - f( x, y, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( 10, y, z, w ); // $ExpectError - f( '10', y, z, w ); // $ExpectError - f( true, y, z, w ); // $ExpectError - f( false, y, z, w ); // $ExpectError - f( null, y, z, w ); // $ExpectError - f( undefined, y, z, w ); // $ExpectError - f( [ '1' ], y, z, w ); // $ExpectError - f( {}, y, z, w ); // $ExpectError - f( ( x: number ): number => x, y, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, 10, z, w ); // $ExpectError - f( x, '10', z, w ); // $ExpectError - f( x, true, z, w ); // $ExpectError - f( x, false, z, w ); // $ExpectError - f( x, null, z, w ); // $ExpectError - f( x, undefined, z, w ); // $ExpectError - f( x, [ '1' ], z, w ); // $ExpectError - f( x, {}, z, w ); // $ExpectError - f( x, ( x: number ): number => x, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, 10, w ); // $ExpectError - f( x, y, '10', w ); // $ExpectError - f( x, y, true, w ); // $ExpectError - f( x, y, false, w ); // $ExpectError - f( x, y, null, w ); // $ExpectError - f( x, y, undefined, w ); // $ExpectError - f( x, y, [ '1' ], w ); // $ExpectError - f( x, y, {}, w ); // $ExpectError - f( x, y, ( x: number ): number => x, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, z, 10 ); // $ExpectError - f( x, y, z, '10' ); // $ExpectError - f( x, y, z, true ); // $ExpectError - f( x, y, z, false ); // $ExpectError - f( x, y, z, null ); // $ExpectError - f( x, y, z, undefined ); // $ExpectError - f( x, y, z, [ '1' ] ); // $ExpectError - f( x, y, z, {} ); // $ExpectError - f( x, y, z, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( 10, y, z, w, u ); // $ExpectError - f( '10', y, z, w, u ); // $ExpectError - f( true, y, z, w, u ); // $ExpectError - f( false, y, z, w, u ); // $ExpectError - f( null, y, z, w, u ); // $ExpectError - f( undefined, y, z, w, u ); // $ExpectError - f( [ '1' ], y, z, w, u ); // $ExpectError - f( {}, y, z, w, u ); // $ExpectError - f( ( x: number ): number => x, y, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, 10, z, w, u ); // $ExpectError - f( x, '10', z, w, u ); // $ExpectError - f( x, true, z, w, u ); // $ExpectError - f( x, false, z, w, u ); // $ExpectError - f( x, null, z, w, u ); // $ExpectError - f( x, undefined, z, w, u ); // $ExpectError - f( x, [ '1' ], z, w, u ); // $ExpectError - f( x, {}, z, w, u ); // $ExpectError - f( x, ( x: number ): number => x, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, 10, w, u ); // $ExpectError - f( x, y, '10', w, u ); // $ExpectError - f( x, y, true, w, u ); // $ExpectError - f( x, y, false, w, u ); // $ExpectError - f( x, y, null, w, u ); // $ExpectError - f( x, y, undefined, w, u ); // $ExpectError - f( x, y, [ '1' ], w, u ); // $ExpectError - f( x, y, {}, w, u ); // $ExpectError - f( x, y, ( x: number ): number => x, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, 10, u ); // $ExpectError - f( x, y, z, '10', u ); // $ExpectError - f( x, y, z, true, u ); // $ExpectError - f( x, y, z, false, u ); // $ExpectError - f( x, y, z, null, u ); // $ExpectError - f( x, y, z, undefined, u ); // $ExpectError - f( x, y, z, [ '1' ], u ); // $ExpectError - f( x, y, z, {}, u ); // $ExpectError - f( x, y, z, ( x: number ): number => x, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fifth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, w, 10 ); // $ExpectError - f( x, y, z, w, '10' ); // $ExpectError - f( x, y, z, w, true ); // $ExpectError - f( x, y, z, w, false ); // $ExpectError - f( x, y, z, w, null ); // $ExpectError - f( x, y, z, w, undefined ); // $ExpectError - f( x, y, z, w, [ '1' ] ); // $ExpectError - f( x, y, z, w, {} ); // $ExpectError - f( x, y, z, w, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/add.js b/examples/add.js deleted file mode 100644 index 775b711..0000000 --- a/examples/add.js +++ /dev/null @@ -1,121 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var dispatch = require( './../lib' ); - -function add2( arrays ) { - var opts; - var xo; - var yo; - var zo; - var sx; - var sy; - var sz; - var sh; - var N; - var x; - var y; - var z; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - z = arrays[ 2 ]; - xo = x.order; - yo = y.order; - zo = z.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - opts.order = yo; - sy = ind2sub( sh, i, opts ); - v = x.get.apply( x, sx ) + y.get.apply( y, sy ); - - opts.order = zo; - sz = ind2sub( sh, i, opts ); - sz.push( v ); - z.set.apply( z, sz ); - } -} - -var fcns = [ - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2 -]; - -var types = [ - dtypes.float64, dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.int32, dtypes.int32, - dtypes.uint32, dtypes.uint32, dtypes.uint32, - dtypes.int16, dtypes.int16, dtypes.int16, - dtypes.uint16, dtypes.uint16, dtypes.uint16, - dtypes.int8, dtypes.int8, dtypes.int8, - dtypes.uint8, dtypes.uint8, dtypes.uint8, - dtypes.uint8c, dtypes.uint8c, dtypes.uint8c -]; - -var add = dispatch( fcns, types, null, 3, 2, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var zbuf = new Float64Array( xbuf.length ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var z = ndarray( 'float64', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); - -xbuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -ybuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -zbuf = new Int32Array( xbuf.length ); - -x = ndarray( 'int32', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'int32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -z = ndarray( 'int32', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); diff --git a/examples/sin.js b/examples/sin.js deleted file mode 100644 index 8cd4871..0000000 --- a/examples/sin.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int8Array = require( '@stdlib/array-int8' ); -var sin = require( '@stdlib/math-base-special-sin' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/strided-dtypes' ); -var dispatch = require( './../lib' ); - -function apply( arrays, fcn ) { - var opts; - var xo; - var yo; - var sx; - var sy; - var sh; - var N; - var x; - var y; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - xo = x.order; - yo = y.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - v = fcn( x.get.apply( x, sx ) ); - - opts.order = yo; - sy = ind2sub( sh, i, opts ); - sy.push( v ); - y.set.apply( y, sy ); - } -} - -var fcns = [ - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply -]; - -var types = [ - dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float64, - dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.float64, - dtypes.uint32, dtypes.float64, - dtypes.int16, dtypes.float64, - dtypes.int16, dtypes.float32, - dtypes.uint16, dtypes.float64, - dtypes.uint16, dtypes.float32, - dtypes.int8, dtypes.float64, - dtypes.int8, dtypes.float32, - dtypes.uint8, dtypes.float64, - dtypes.uint8, dtypes.float32, - dtypes.uint8c, dtypes.float64, - dtypes.uint8c, dtypes.float32 -]; - -var data = [ - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin -]; - -var sine = dispatch( fcns, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); - -xbuf = new Int8Array( [ 1, 2, 3, 4, 5 ] ); -ybuf = new Float32Array( xbuf.length ); - -x = ndarray( 'int8', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'float32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); diff --git a/examples/unary.js b/examples/unary.js deleted file mode 100644 index e9c3fb4..0000000 --- a/examples/unary.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -var unary = require( '@stdlib/ndarray-base-unary' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var dispatch = require( './../lib' ); - -var types = [ 'float64', 'float64' ]; - -var data = [ - abs -]; - -var absolute = dispatch( unary, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -absolute( x, y ); -console.log( ybuf ); -// => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 5f280a1..c49a4e4 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..d798c10 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@v0.2.2-esm/index.mjs";function m(m,f,l,p,w,v){var a,g,c;if(i(m))c=m;else if(!s(m))throw new TypeError(d("0jr5d",m));if(!n(f))throw new TypeError(d("0jr2y",f));if(!n(l)&&null!==l)throw new TypeError(d("0jr5e",l));if(!e(p))throw new TypeError(d("0jr5f",p));if(!r(w))throw new TypeError(d("0jr5X",w));if(!r(v))throw new TypeError(d("0jr5g",v));if(0===(a=w+v))throw new Error(d("0jr0h"));if(p!==a)throw new Error(d("0jr0i"));if(c){if(g=f.length/a,!t(g))throw new Error(d("0jr0j"))}else if(g=m.length,f.length!==g*a)throw new Error(d("0jr0j"));if(l&&l.length!==g)throw new Error(d("0jr0k"));return f=function(r){var e,t;for(e=[],t=0;t [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0jr5d', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0jr2y', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( '0jr5e', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0jr5f', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0jr5X', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0jr5g', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format('0jr0h') );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format('0jr0i') );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format('0jr0k') );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format('0jr0l') );\n\t\t\t}\n\t\t\tthrow new Error( format('0jr0m') );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( '0jr5h', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( '0jr5i', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format('0jr0n') );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found).\n*\n* ## Notes\n*\n* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types).\n* - The function assumes that `x` is stored in row-major order.\n* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`.\n* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value.\n*\n* @private\n* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension)\n* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension)\n* @param {ArrayLikeObject} x - input two-dimensional reference array\n* @param {integer} strideX1 - `x` stride length along first dimension\n* @param {integer} strideX2 - `x` stride length along second dimension\n* @param {NonNegativeInteger} offsetX - `x` starting index\n* @param {ArrayLikeObject} y - search array\n* @param {integer} strideY - `y` stride length\n* @param {NonNegativeInteger} offsetY - `y` starting index\n* @returns {integer} row index (if found) and `-1` otherwise\n*\n* @example\n* // Define a reference array to search:\n* var types = [\n* 'float64', 'float64', 'float64',\n* 'float32', 'float32', 'float32',\n* 'uint32', 'uint32', 'float64',\n* 'int32', 'int32', 'float64',\n* 'uint16', 'uint16', 'float64',\n* 'int16', 'int16', 'float64',\n* 'uint8', 'uint8', 'float64',\n* 'int8', 'int8', 'float64'\n* ];\n*\n* // Define reference array dimensions:\n* var N = 8; // rows\n* var M = 3; // columns\n*\n* // Define a search array:\n* y1 = [\n* 'float32', 'float32', 'float32',\n* ];\n*\n* // Find the list of types:\n* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 );\n* // returns 1\n*\n// Define a search array:\n* y2 = [\n* 'float32', 'float32', 'float64',\n* ];\n*\n* // Find the list of types:\n* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 );\n* // returns -1\n*/\nfunction indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len\n\tvar ix;\n\tvar iy;\n\tvar i;\n\tvar j;\n\n\t// Search for the first row which matches `y`...\n\tix = offsetX;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tiy = offsetY;\n\t\tfor ( j = 0; j < M; j++ ) {\n\t\t\tif ( x[ ix+(j*strideX2) ] !== y[ iy ] ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tiy += strideY;\n\t\t}\n\t\t// If we successfully iterated over all columns, then that means we've found a match...\n\t\tif ( j === M ) {\n\t\t\treturn i;\n\t\t}\n\t\tix += strideX1;\n\t}\n\treturn -1;\n}\n\n\n// EXPORTS //\n\nexport default indexOfTypes;\n"],"names":["dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","out","i","push","resolveEnum","types2enums","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","getDType","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","j","indexOfTypes","slice"],"mappings":";;0+BA0GA,SAASA,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAO,UAEzB,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAO,UAEzB,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAO,eAIzB,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAO,UAG1B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAO,UAGzB,OADAX,EA5GD,SAAsBA,GACrB,IAAIkB,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAInB,EAAMgB,OAAQG,IAC9BD,EAAIE,KAAMC,EAAarB,EAAOmB,KAE/B,OAAOD,CACR,CAmGSI,CAAatB,GAgBrB,WACC,IAAIuB,EACAC,EACAC,EACAC,EACAC,EACAC,EACAT,EAGJ,GADAM,EAAOI,UAAUb,OACZS,IAASvB,EAAQ,CACrB,GAAKuB,EAAOvB,EACX,MAAM,IAAIa,MAAOJ,EAAO,UAEzB,MAAM,IAAII,MAAOJ,EAAO,SACxB,CAGD,IAFAY,EAAS,GACTC,EAAS,GACHL,EAAI,EAAGA,EAAIjB,EAAOiB,IAAM,CAE7B,IAAMW,EADNH,EAAIE,UAAWV,IAEd,MAAKA,EAAIhB,EACF,IAAIO,UAAWC,EAAQ,QAASgB,IAEhC,IAAIjB,UAAWC,EAAQ,QAASgB,IAGxCJ,EAAOH,KAAMO,GACbH,EAAOJ,KAAMC,EAAaU,EAAUJ,IACpC,CAKD,IAHAD,EC1HF,SAAuBM,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAvB,EACAwB,EAIJ,IADAF,EAAKJ,EACClB,EAAI,EAAGA,EAAIa,EAAGb,IAAM,CAEzB,IADAuB,EAAKF,EACCG,EAAI,EAAGA,EAAIV,GACXC,EAAGO,EAAIE,EAAEP,KAAgBE,EAAGI,GADdC,IAInBD,GAAMH,EAGP,GAAKI,IAAMV,EACV,OAAOd,EAERsB,GAAMN,CACN,CACD,OAAQ,CACT,CDmGQS,CAActC,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGmB,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAId,UAAWC,EAAO,UAI5BiB,EADIrB,GAGAR,EAAM2B,GAGNzB,EACJ2B,EAAGL,EAAQtB,EAAMyB,IAEjBE,EAAGL,GAEJ,GAAc,IAATnB,EACJ,OAAOmB,EAAQlB,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOmB,EAAOsB,MAAO1C,EACrB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 88f0e3e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Create an ndarray function interface which performs multiple dispatch. -* -* @module @stdlib/ndarray-dispatch -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var dispatch = require( '@stdlib/ndarray-dispatch' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/index_of_types.js b/lib/index_of_types.js deleted file mode 100644 index fda2297..0000000 --- a/lib/index_of_types.js +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found). -* -* ## Notes -* -* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types). -* - The function assumes that `x` is stored in row-major order. -* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`. -* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value. -* -* @private -* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension) -* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension) -* @param {ArrayLikeObject} x - input two-dimensional reference array -* @param {integer} strideX1 - `x` stride length along first dimension -* @param {integer} strideX2 - `x` stride length along second dimension -* @param {NonNegativeInteger} offsetX - `x` starting index -* @param {ArrayLikeObject} y - search array -* @param {integer} strideY - `y` stride length -* @param {NonNegativeInteger} offsetY - `y` starting index -* @returns {integer} row index (if found) and `-1` otherwise -* -* @example -* // Define a reference array to search: -* var types = [ -* 'float64', 'float64', 'float64', -* 'float32', 'float32', 'float32', -* 'uint32', 'uint32', 'float64', -* 'int32', 'int32', 'float64', -* 'uint16', 'uint16', 'float64', -* 'int16', 'int16', 'float64', -* 'uint8', 'uint8', 'float64', -* 'int8', 'int8', 'float64' -* ]; -* -* // Define reference array dimensions: -* var N = 8; // rows -* var M = 3; // columns -* -* // Define a search array: -* y1 = [ -* 'float32', 'float32', 'float32', -* ]; -* -* // Find the list of types: -* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 ); -* // returns 1 -* -// Define a search array: -* y2 = [ -* 'float32', 'float32', 'float64', -* ]; -* -* // Find the list of types: -* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 ); -* // returns -1 -*/ -function indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len - var ix; - var iy; - var i; - var j; - - // Search for the first row which matches `y`... - ix = offsetX; - for ( i = 0; i < N; i++ ) { - iy = offsetY; - for ( j = 0; j < M; j++ ) { - if ( x[ ix+(j*strideX2) ] !== y[ iy ] ) { - break; - } - iy += strideY; - } - // If we successfully iterated over all columns, then that means we've found a match... - if ( j === M ) { - return i; - } - ix += strideX1; - } - return -1; -} - - -// EXPORTS // - -module.exports = indexOfTypes; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4648598..0000000 --- a/lib/main.js +++ /dev/null @@ -1,231 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isFunctionArray = require( '@stdlib/assert-is-function-array' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var resolveEnum = require( '@stdlib/ndarray-base-dtype-resolve-enum' ); -var indexOfTypes = require( './index_of_types.js' ); - - -// FUNCTIONS // - -/** -* Returns a list of data type enumeration constants. -* -* @private -* @param {Collection} types - list of types -* @returns {IntegerArray} list of data type enumeration constants -*/ -function types2enums( types ) { - var out; - var i; - - out = []; - for ( i = 0; i < types.length; i++ ) { - out.push( resolveEnum( types[ i ] ) ); - } - return out; -} - - -// MAIN // - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param {(FunctionArray|Function)} fcns - list of ndarray functions -* @param {Collection} types - one-dimensional list of ndarray argument data types -* @param {(Collection|null)} data - ndarray function data (e.g., callbacks) -* @param {PositiveInteger} nargs - total number of ndarray function interface arguments -* @param {NonNegativeInteger} nin - number of input ndarrays -* @param {NonNegativeInteger} nout - number of output ndarrays -* @throws {TypeError} first argument must be either a function or an array of functions -* @throws {TypeError} second argument must be an array-like object -* @throws {TypeError} third argument must be an array-like object or `null` -* @throws {Error} third and first arguments must have the same number of elements -* @throws {TypeError} fourth argument must be a positive integer -* @throws {TypeError} fifth argument must be a nonnegative integer -* @throws {TypeError} sixth argument must be a nonnegative integer -* @throws {Error} fourth argument must equal the specified number of input and output arrays -* @throws {Error} number of types must match the number of functions times the total number of array arguments for each function -* @throws {Error} interface must accept at least one input and/or output ndarray -* @returns {Function} ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function dispatch( fcns, types, data, nargs, nin, nout ) { - var narrays; - var nfcns; - var fcn; - - if ( isFunction( fcns ) ) { - fcn = fcns; - } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( '0jr5d', fcns ) ); - } - if ( !isCollection( types ) ) { - throw new TypeError( format( '0jr2y', types ) ); - } - if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( '0jr5e', data ) ); - } - if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( '0jr5f', nargs ) ); - } - if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( '0jr5X', nin ) ); - } - if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( '0jr5g', nout ) ); - } - narrays = nin + nout; - if ( narrays === 0 ) { - throw new Error( format('0jr0h') ); - } - if ( nargs !== narrays ) { - throw new Error( format('0jr0i') ); - } - if ( fcn ) { - nfcns = types.length / narrays; - if ( !isInteger( nfcns ) ) { - throw new Error( format('0jr0j') ); - } - } else { - nfcns = fcns.length; - if ( types.length !== nfcns*narrays ) { - throw new Error( format('0jr0j') ); - } - } - if ( data && data.length !== nfcns ) { - throw new Error( format('0jr0k') ); - } - types = types2enums( types ); - return dispatcher; - - /** - * ndarray function interface which performs multiple dispatch. - * - * @private - * @param {ndarrayLike} x - ndarray - * @param {...ndarrayLike} args - ndarray arguments - * @throws {Error} insufficient arguments - * @throws {Error} too many arguments - * @throws {TypeError} input array arguments must be ndarray-like objects - * @throws {TypeError} output array arguments must be ndarray-like objects - * @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types - * @returns {(ndarrayLike|Array|void)} destination array(s) - */ - function dispatcher() { - var arrays; - var dtypes; - var argc; - var idx; - var v; - var f; - var i; - - argc = arguments.length; - if ( argc !== nargs ) { - if ( argc < nargs ) { - throw new Error( format('0jr0l') ); - } - throw new Error( format('0jr0m') ); - } - arrays = []; - dtypes = []; - for ( i = 0; i < nargs; i++ ) { - v = arguments[ i ]; - if ( !isndarrayLike( v ) ) { - if ( i < nin ) { - throw new TypeError( format( '0jr5h', v ) ); - } else { - throw new TypeError( format( '0jr5i', v ) ); - } - } - arrays.push( v ); - dtypes.push( resolveEnum( getDType( v ) ) ); - } - // Resolve the ndarray function satisfying the input array types: - idx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len - - // Check whether we were able to successfully resolve an ndarray function: - if ( idx < 0 ) { - throw new TypeError( format('0jr0n') ); - } - // Retrieve the ndarray function: - if ( fcn ) { - f = fcn; - } else { - f = fcns[ idx ]; - } - // Evaluate the ndarray function: - if ( data ) { - f( arrays, data[ idx ] ); - } else { - f( arrays ); - } - if ( nout === 1 ) { - return arrays[ narrays-1 ]; - } - if ( nout === 0 ) { - return; - } - return arrays.slice( nin ); - } -} - - -// EXPORTS // - -module.exports = dispatch; diff --git a/package.json b/package.json index 5f84ca4..e6c8bad 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Create an ndarray function interface which performs multiple dispatch.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,57 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-function-array": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer": "^0.2.2", - "@stdlib/assert-is-positive-integer": "^0.2.2", - "@stdlib/ndarray-base-dtype-resolve-enum": "^0.2.2", - "@stdlib/ndarray-dtype": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.2.2", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/array-int8": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/math-base-assert-is-nan": "^0.2.2", - "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/math-base-special-pow": "^0.3.0", - "@stdlib/math-base-special-sin": "^0.3.0", - "@stdlib/ndarray-base-buffer-dtype": "^0.3.0", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-unary": "^0.2.1", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-dtypes": "^0.3.0", - "@stdlib/ndarray-ind2sub": "^0.2.2", - "@stdlib/strided-dtypes": "^0.3.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "ndarray", @@ -100,7 +26,6 @@ "multimethod", "multimethods" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..252182f --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/fixtures/binary.js b/test/fixtures/binary.js deleted file mode 100644 index a60dfa2..0000000 --- a/test/fixtures/binary.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Binary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @returns {number} sum -*/ -function binary( x, y ) { - return x + y; -} - - -// EXPORTS // - -module.exports = binary; diff --git a/test/fixtures/fill.js b/test/fixtures/fill.js deleted file mode 100644 index 41b2958..0000000 --- a/test/fixtures/fill.js +++ /dev/null @@ -1,76 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which fills one or more ndarrays. -* -* @private -* @param {*} value - fill value -* @returns {Function} ndarray function -*/ -function fill( value ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - */ - function ndarrayFcn( arrays ) { - var opts; - var sub; - var arr; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - opts = { - 'order': '' - }; - for ( j = 0; j < M; j++ ) { - arr = arrays[ j ]; - opts.order = arrays[ j ].order; - for ( i = 0; i < N; i++ ) { - sub = ind2sub( sh, i, opts ); - sub.push( value ); - arr.set.apply( arr, sub ); - } - } - } -} - - -// EXPORTS // - -module.exports = fill; diff --git a/test/fixtures/foreach.js b/test/fixtures/foreach.js deleted file mode 100644 index a426290..0000000 --- a/test/fixtures/foreach.js +++ /dev/null @@ -1,72 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function forEach( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - fcn.apply( null, args ); - } -} - - -// EXPORTS // - -module.exports = forEach; diff --git a/test/fixtures/map1n.js b/test/fixtures/map1n.js deleted file mode 100644 index 614196b..0000000 --- a/test/fixtures/map1n.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function which maps the return value of a callback to `N` arrays. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function map1N( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var v; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - v = fcn(); - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - sub.push( v ); - arrays[ j ].set.apply( arrays[ j ], sub ); - } - } -} - - -// EXPORTS // - -module.exports = map1N; diff --git a/test/fixtures/nullary.js b/test/fixtures/nullary.js deleted file mode 100644 index 4f22126..0000000 --- a/test/fixtures/nullary.js +++ /dev/null @@ -1,36 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Nullary callback. -* -* @private -* @returns {number} value -*/ -function nullary() { - return 3.0; -} - - -// EXPORTS // - -module.exports = nullary; diff --git a/test/fixtures/quaternary.js b/test/fixtures/quaternary.js deleted file mode 100644 index 548437b..0000000 --- a/test/fixtures/quaternary.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quaternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @returns {number} sum -*/ -function quaternary( x, y, z, w ) { - return x + y + z + w; -} - - -// EXPORTS // - -module.exports = quaternary; diff --git a/test/fixtures/quinary.js b/test/fixtures/quinary.js deleted file mode 100644 index 36068de..0000000 --- a/test/fixtures/quinary.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quinary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @param {number} u - input value -* @returns {number} sum -*/ -function quinary( x, y, z, w, u ) { - return x + y + z + w + u; -} - - -// EXPORTS // - -module.exports = quinary; diff --git a/test/fixtures/sum.js b/test/fixtures/sum.js deleted file mode 100644 index efdbb1b..0000000 --- a/test/fixtures/sum.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which computes the sum across one or more ndarrays. -* -* @private -* @param {Object} ctx - context -* @param {number} ctx.sum - initial sum -* @returns {Function} ndarray function -*/ -function wrapper( ctx ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - * @param {Function} [fcn] - callback - */ - function ndarrayFcn( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var f; - var i; - var j; - - if ( arguments.length > 1 ) { - f = fcn; - } - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - if ( f ) { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - ctx.sum += f.apply( null, args ); - } - } else { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - ctx.sum += arrays[ j ].get.apply( arrays[ j ], sub ); - } - } - } - } -} - - -// EXPORTS // - -module.exports = wrapper; diff --git a/test/fixtures/ternary.js b/test/fixtures/ternary.js deleted file mode 100644 index 0595d5f..0000000 --- a/test/fixtures/ternary.js +++ /dev/null @@ -1,39 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Ternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @returns {number} sum -*/ -function ternary( x, y, z ) { - return x + y + z; -} - - -// EXPORTS // - -module.exports = ternary; diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d6c2c8e..0000000 --- a/test/test.js +++ /dev/null @@ -1,363 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var fill = require( './fixtures/fill.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either a function or an array of functions as a first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( value, types, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object as a second argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided either an array-like object or `null` as a third argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - dispatch( unary, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a positive integer for a fourth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 0, - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a fifth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, value, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a sixth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, 1, value ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function array)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var fcns = [ unary, unary, unary ]; - var data = [ abs, abs, abs ]; - dispatch( fcns, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function argument)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs, abs, abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the length of `data` argument does not match the number of ndarray functions', function test( t ) { - var values; - var i; - - values = [ - [], - [ abs, abs ], - [ abs, abs, abs ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var fcns = [ unary ]; - dispatch( fcns, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the fourth argument is incompatible with the number of input and output ndarrays', function test( t ) { - var values; - var i; - - values = [ - 0, - 1, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of specified input and output ndarrays is zero', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var types = [ 'float64' ]; - dispatch( fill( 3 ), types, null, 1, 0, 0 ); - } -}); - -tape( 'the function returns an ndarray function interface', function test( t ) { - var types; - var data; - var f; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - f = dispatch( unary, types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ unary ], types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( fill( 3 ), types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ fill( 3 ) ], types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.two_arrays.js b/test/test.two_arrays.js deleted file mode 100644 index 16eb61b..0000000 --- a/test/test.two_arrays.js +++ /dev/null @@ -1,814 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var dtype = require( '@stdlib/ndarray-base-buffer-dtype' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var forEach = require( './fixtures/foreach.js' ); -var map1N = require( './fixtures/map1n.js' ); -var fill = require( './fixtures/fill.js' ); -var sum = require( './fixtures/sum.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the first argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var ybuf = new Float64Array( 10 ); - var y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( value, y ); - }; - } -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the second argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var xbuf = new Float64Array( 10 ); - var x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( x, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided insufficient arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var f; - var x; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [], - [ x ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided too many arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var ybuf; - var f; - var x; - var y; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [ x, y, y ], - [ x, y, y, y ], - [ x, y, y, y, y ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if unable to resolve a ndarray function supporting the provided array argument data types', function test( t ) { - var values; - var types; - var data; - var xbuf; - var fcn; - var x; - var i; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ abs, abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 4 ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - values = [ - new Uint8Array( 4 ), - new Int32Array( 4 ), - [ 0, 0, 0, 0 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided an array having data type: ' + dtype( values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var y = ndarray( dtype( value ), value, [ value.length ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - }; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only input arrays)', function test( t ) { - var types; - var xbuf; - var ybuf; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only output arrays)', function test( t ) { - var expected; - var types; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only input arrays)', function test( t ) { - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var ctx; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcns = [ - sum( ctx ), - sum( ctx ) - ]; - fcn = dispatch( fcns, types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only output arrays)', function test( t ) { - var expected; - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcns = [ - fill( 3.0 ), - fill( 4.0 ) - ]; - fcn = dispatch( fcns, types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - - fcn = dispatch( forEach, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - - fcn = dispatch( map1N, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - fcns = [ - forEach, - forEach - ]; - fcn = dispatch( fcns, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - fcns = [ - map1N, - map1N - ]; - fcn = dispatch( fcns, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - fcns = [ - unary, - unary - ]; - fcn = dispatch( fcns, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which returns one or more output arrays, if one or more output arrays is specified, and otherwise returns `undefined`', function test( t ) { - var types; - var data; - var xbuf; - var ybuf; - var out; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - // No output arrays... - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, void 0, 'returns expected value' ); - - // One output array... - data = [ - abs, - abs - ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - fcn = dispatch( fill( 3.0 ), types, null, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - // Two output arrays... - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.end(); -}); From 74d998b5d2c132eeb7d30202c56755fcaa6ad24b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 8 May 2025 01:49:52 +0000 Subject: [PATCH 095/109] Transform error messages --- lib/main.js | 34 +++++++++++++++++----------------- package.json | 2 +- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/main.js b/lib/main.js index 5f4bb5d..4648598 100644 --- a/lib/main.js +++ b/lib/main.js @@ -27,7 +27,7 @@ var isFunctionArray = require( '@stdlib/assert-is-function-array' ); var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var getDType = require( '@stdlib/ndarray-dtype' ); var resolveEnum = require( '@stdlib/ndarray-base-dtype-resolve-enum' ); var indexOfTypes = require( './index_of_types.js' ); @@ -112,43 +112,43 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { if ( isFunction( fcns ) ) { fcn = fcns; } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) ); + throw new TypeError( format( '0jr5d', fcns ) ); } if ( !isCollection( types ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) ); + throw new TypeError( format( '0jr2y', types ) ); } if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); + throw new TypeError( format( '0jr5e', data ) ); } if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) ); + throw new TypeError( format( '0jr5f', nargs ) ); } if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) ); + throw new TypeError( format( '0jr5X', nin ) ); } if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) ); + throw new TypeError( format( '0jr5g', nout ) ); } narrays = nin + nout; if ( narrays === 0 ) { - throw new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' ); + throw new Error( format('0jr0h') ); } if ( nargs !== narrays ) { - throw new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' ); + throw new Error( format('0jr0i') ); } if ( fcn ) { nfcns = types.length / narrays; if ( !isInteger( nfcns ) ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format('0jr0j') ); } } else { nfcns = fcns.length; if ( types.length !== nfcns*narrays ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format('0jr0j') ); } } if ( data && data.length !== nfcns ) { - throw new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' ); + throw new Error( format('0jr0k') ); } types = types2enums( types ); return dispatcher; @@ -178,9 +178,9 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { argc = arguments.length; if ( argc !== nargs ) { if ( argc < nargs ) { - throw new Error( 'invalid invocation. Insufficient arguments.' ); + throw new Error( format('0jr0l') ); } - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('0jr0m') ); } arrays = []; dtypes = []; @@ -188,9 +188,9 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { v = arguments[ i ]; if ( !isndarrayLike( v ) ) { if ( i < nin ) { - throw new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) ); + throw new TypeError( format( '0jr5h', v ) ); } else { - throw new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) ); + throw new TypeError( format( '0jr5i', v ) ); } } arrays.push( v ); @@ -201,7 +201,7 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { // Check whether we were able to successfully resolve an ndarray function: if ( idx < 0 ) { - throw new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' ); + throw new TypeError( format('0jr0n') ); } // Retrieve the ndarray function: if ( fcn ) { diff --git a/package.json b/package.json index 12f46eb..5f84ca4 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/assert-is-positive-integer": "^0.2.2", "@stdlib/ndarray-base-dtype-resolve-enum": "^0.2.2", "@stdlib/ndarray-dtype": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 1dcba9f39220fe089b51466ef2d3796659ae1f8d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 8 May 2025 01:50:15 +0000 Subject: [PATCH 096/109] Remove files --- index.d.ts | 334 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5181 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index c49a4e4..0000000 --- a/index.d.ts +++ /dev/null @@ -1,334 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* ndarray function. -* -* @param arrays - array containing input and output ndarrays -* @param data - ndarray function data (e.g., a callback) -* -* @example -* var numel = require( '@stdlib/ndarray-base-numel' ); -* var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -* -* function ndarrayFcn( arrays, fcn ) { -* var xord; -* var yord; -* var opts; -* var sub; -* var sh; -* var N; -* var x; -* var y; -* var v; -* var i; -* -* x = arrays[ 0 ]; -* y = arrays[ 1 ]; -* sh = x.shape; -* N = numel( sh ); -* if ( N <= 0 ) { -* return; -* } -* xord = x.order; -* yord = y.order; -* opts = {}; -* opts.order = xord; -* for ( i = 0; i < N; i++ ) { -* // Convert a linear index to subscripts: -* opts.order = xord; -* sub = ind2sub( sh, i, opts ); -* -* // Retrieve an element from `x`: -* v = x.get.apply( x, sub ); -* -* // Convert a linear index to subscripts: -* opts.order = yord; -* sub = ind2sub( sh, i, opts ); -* -* // Append the result of applying the callback: -* sub.push( fcn( v ) ); -* -* // Assign the result to an element in `y`: -* y.set.apply( y, sub ); -* } -* } -*/ -type ndarrayFcn = ( arrays: Array, data?: any ) => void; - -/** -* Interface describing an ndarray function dispatcher. -*/ -interface Dispatcher { - /** - * Invokes an ndarray function based on the provided array data type(s). - * - * @param x - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array - * - * @example - * var nullary = require( '@stdlib/ndarray-base-nullary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function value() { - * return 3.14; - * } - * - * var types = [ 'float64' ]; - * var data = [ value ]; - * - * var fcn = dispatch( nullary, types, data, 1, 0, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( 5 ); - * var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x ); - * // xbuf => [ 3.14, 3.14, 3.14, 3.14, 3.14 ] - */ - ( x: ndarray ): ndarray | void; - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var unary = require( '@stdlib/ndarray-base-unary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * var abs = require( '@stdlib/math-base-special-abs' ); - * - * var types = [ 'float64', 'float64' ]; - * var data = [ abs ]; - * - * var fcn = dispatch( unary, types, data, 2, 1, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - * var ybuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y ); - * // ybuf => [ 1.0, 2.0, 3.0 ] - */ - ( x: ndarray, y: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var ternary = require( '@stdlib/ndarray-base-ternary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function add2( x, y ) { - * return x + y; - * } - * - * var types = [ 'float64', 'float64', 'float64' ]; - * var data = [ add2 ]; - * - * var fcn = dispatch( ternary, types, data, 3, 2, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z ); - * // zbuf => [ 2.0, 4.0, 6.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quaternary = require( '@stdlib/ndarray-base-quaternary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function add3( x, y, z ) { - * return x + y + z; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add3 ]; - * - * var fcn = dispatch( quaternary, types, data, 4, 3, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w ); - * // wbuf => [ 3.0, 6.0, 9.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @param args - ndarray arguments - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quinary = require( '@stdlib/ndarray-base-quinary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function add4( x, y, z, w ) { - * return x + y + z + w; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add4 ]; - * - * var fcn = dispatch( quinary, types, data, 5, 4, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ubuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var u = ndarray( 'float64', ubuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w, u ); - * // ubuf => [ 4.0, 8.0, 12.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray, ...args: Array ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures -} - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param fcns - list of ndarray functions -* @param types - one-dimensional list of ndarray argument data types -* @param data - ndarray function data (e.g., callbacks) -* @param nargs - total number of ndarray function interface arguments -* @param nin - number of input ndarrays -* @param nout - number of output ndarrays -* @throws first argument must be either a function or an array of functions -* @throws second argument must be an array-like object -* @throws third argument must be an array-like object or `null` -* @throws third and first arguments must have the same number of elements -* @throws fourth argument must be a positive integer -* @throws fifth argument must be a nonnegative integer -* @throws sixth argument must be a nonnegative integer -* @throws fourth argument must equal the specified number of input and output arrays -* @throws number of types must match the number of functions times the total number of array arguments for each function -* @throws interface must accept at least one input and/or output ndarray -* @returns ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var fcn = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* fcn( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function dispatch( fcns: ndarrayFcn | ArrayLike, types: ArrayLike, data: ArrayLike | null, nargs: number, nin: number, nout: number ): Dispatcher; - - -// EXPORTS // - -export = dispatch; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index d798c10..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@v0.2.2-esm/index.mjs";function m(m,f,l,p,w,v){var a,g,c;if(i(m))c=m;else if(!s(m))throw new TypeError(d("0jr5d",m));if(!n(f))throw new TypeError(d("0jr2y",f));if(!n(l)&&null!==l)throw new TypeError(d("0jr5e",l));if(!e(p))throw new TypeError(d("0jr5f",p));if(!r(w))throw new TypeError(d("0jr5X",w));if(!r(v))throw new TypeError(d("0jr5g",v));if(0===(a=w+v))throw new Error(d("0jr0h"));if(p!==a)throw new Error(d("0jr0i"));if(c){if(g=f.length/a,!t(g))throw new Error(d("0jr0j"))}else if(g=m.length,f.length!==g*a)throw new Error(d("0jr0j"));if(l&&l.length!==g)throw new Error(d("0jr0k"));return f=function(r){var e,t;for(e=[],t=0;t [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0jr5d', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0jr2y', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( '0jr5e', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0jr5f', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0jr5X', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0jr5g', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format('0jr0h') );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format('0jr0i') );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format('0jr0k') );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format('0jr0l') );\n\t\t\t}\n\t\t\tthrow new Error( format('0jr0m') );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( '0jr5h', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( '0jr5i', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format('0jr0n') );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found).\n*\n* ## Notes\n*\n* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types).\n* - The function assumes that `x` is stored in row-major order.\n* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`.\n* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value.\n*\n* @private\n* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension)\n* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension)\n* @param {ArrayLikeObject} x - input two-dimensional reference array\n* @param {integer} strideX1 - `x` stride length along first dimension\n* @param {integer} strideX2 - `x` stride length along second dimension\n* @param {NonNegativeInteger} offsetX - `x` starting index\n* @param {ArrayLikeObject} y - search array\n* @param {integer} strideY - `y` stride length\n* @param {NonNegativeInteger} offsetY - `y` starting index\n* @returns {integer} row index (if found) and `-1` otherwise\n*\n* @example\n* // Define a reference array to search:\n* var types = [\n* 'float64', 'float64', 'float64',\n* 'float32', 'float32', 'float32',\n* 'uint32', 'uint32', 'float64',\n* 'int32', 'int32', 'float64',\n* 'uint16', 'uint16', 'float64',\n* 'int16', 'int16', 'float64',\n* 'uint8', 'uint8', 'float64',\n* 'int8', 'int8', 'float64'\n* ];\n*\n* // Define reference array dimensions:\n* var N = 8; // rows\n* var M = 3; // columns\n*\n* // Define a search array:\n* y1 = [\n* 'float32', 'float32', 'float32',\n* ];\n*\n* // Find the list of types:\n* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 );\n* // returns 1\n*\n// Define a search array:\n* y2 = [\n* 'float32', 'float32', 'float64',\n* ];\n*\n* // Find the list of types:\n* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 );\n* // returns -1\n*/\nfunction indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len\n\tvar ix;\n\tvar iy;\n\tvar i;\n\tvar j;\n\n\t// Search for the first row which matches `y`...\n\tix = offsetX;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tiy = offsetY;\n\t\tfor ( j = 0; j < M; j++ ) {\n\t\t\tif ( x[ ix+(j*strideX2) ] !== y[ iy ] ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tiy += strideY;\n\t\t}\n\t\t// If we successfully iterated over all columns, then that means we've found a match...\n\t\tif ( j === M ) {\n\t\t\treturn i;\n\t\t}\n\t\tix += strideX1;\n\t}\n\treturn -1;\n}\n\n\n// EXPORTS //\n\nexport default indexOfTypes;\n"],"names":["dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","out","i","push","resolveEnum","types2enums","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","getDType","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","j","indexOfTypes","slice"],"mappings":";;0+BA0GA,SAASA,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAO,UAEzB,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAO,UAEzB,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAO,eAIzB,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAO,UAG1B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAO,UAGzB,OADAX,EA5GD,SAAsBA,GACrB,IAAIkB,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAInB,EAAMgB,OAAQG,IAC9BD,EAAIE,KAAMC,EAAarB,EAAOmB,KAE/B,OAAOD,CACR,CAmGSI,CAAatB,GAgBrB,WACC,IAAIuB,EACAC,EACAC,EACAC,EACAC,EACAC,EACAT,EAGJ,GADAM,EAAOI,UAAUb,OACZS,IAASvB,EAAQ,CACrB,GAAKuB,EAAOvB,EACX,MAAM,IAAIa,MAAOJ,EAAO,UAEzB,MAAM,IAAII,MAAOJ,EAAO,SACxB,CAGD,IAFAY,EAAS,GACTC,EAAS,GACHL,EAAI,EAAGA,EAAIjB,EAAOiB,IAAM,CAE7B,IAAMW,EADNH,EAAIE,UAAWV,IAEd,MAAKA,EAAIhB,EACF,IAAIO,UAAWC,EAAQ,QAASgB,IAEhC,IAAIjB,UAAWC,EAAQ,QAASgB,IAGxCJ,EAAOH,KAAMO,GACbH,EAAOJ,KAAMC,EAAaU,EAAUJ,IACpC,CAKD,IAHAD,EC1HF,SAAuBM,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAvB,EACAwB,EAIJ,IADAF,EAAKJ,EACClB,EAAI,EAAGA,EAAIa,EAAGb,IAAM,CAEzB,IADAuB,EAAKF,EACCG,EAAI,EAAGA,EAAIV,GACXC,EAAGO,EAAIE,EAAEP,KAAgBE,EAAGI,GADdC,IAInBD,GAAMH,EAGP,GAAKI,IAAMV,EACV,OAAOd,EAERsB,GAAMN,CACN,CACD,OAAQ,CACT,CDmGQS,CAActC,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGmB,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAId,UAAWC,EAAO,UAI5BiB,EADIrB,GAGAR,EAAM2B,GAGNzB,EACJ2B,EAAGL,EAAQtB,EAAMyB,IAEjBE,EAAGL,GAEJ,GAAc,IAATnB,EACJ,OAAOmB,EAAQlB,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOmB,EAAOsB,MAAO1C,EACrB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 252182f..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From a27cf759ba4804f10b47ff48d43750f90dfa3ab2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 8 May 2025 01:50:38 +0000 Subject: [PATCH 097/109] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 194 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 257 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 61 +- SECURITY.md | 5 - benchmark/benchmark.dispatch_size.js | 156 - benchmark/benchmark.js | 81 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 87 - docs/types/test.ts | 615 --- examples/add.js | 121 - examples/sin.js | 142 - examples/unary.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/index_of_types.js | 106 - lib/main.js | 231 - package.json | 79 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/binary.js | 38 - test/fixtures/fill.js | 76 - test/fixtures/foreach.js | 72 - test/fixtures/map1n.js | 74 - test/fixtures/nullary.js | 36 - test/fixtures/quaternary.js | 40 - test/fixtures/quinary.js | 41 - test/fixtures/sum.js | 98 - test/fixtures/ternary.js | 39 - test/test.js | 363 -- test/test.two_arrays.js | 814 --- 57 files changed, 4876 insertions(+), 7111 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.dispatch_size.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/add.js delete mode 100644 examples/sin.js delete mode 100644 examples/unary.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/index_of_types.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/fixtures/binary.js delete mode 100644 test/fixtures/fill.js delete mode 100644 test/fixtures/foreach.js delete mode 100644 test/fixtures/map1n.js delete mode 100644 test/fixtures/nullary.js delete mode 100644 test/fixtures/quaternary.js delete mode 100644 test/fixtures/quinary.js delete mode 100644 test/fixtures/sum.js delete mode 100644 test/fixtures/ternary.js delete mode 100644 test/test.js delete mode 100644 test/test.two_arrays.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 731bd4f..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/contributing/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 5e92c3e..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2b4fac7..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '43 7 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -304,7 +295,7 @@ console.log( ybuf ); ## 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. +This package is part of [stdlib][stdlib], a standard library 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]. @@ -367,11 +358,11 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-dispatch/main/LICENSE -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.dispatch_size.js b/benchmark/benchmark.dispatch_size.js deleted file mode 100644 index 15805ba..0000000 --- a/benchmark/benchmark.dispatch_size.js +++ /dev/null @@ -1,156 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib/main.js' ); - - -// FUNCTIONS // - -/** -* Evaluates the identity function. -* -* @private -* @param {*} v - value -* @returns {*} input value -*/ -function identity( v ) { - return v; -} - -/** -* Dummy function which throws an error. -* -* @private -* @throws {Error} unexpected error -*/ -function throwError() { - throw new Error( 'unexpected error' ); -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} size - dispatch size -* @returns {Function} benchmark function -*/ -function createBenchmark( size ) { - var types; - var data; - var fcn; - var x; - var y; - var t; - var i; - - types = []; - - // Create dummy types... - for ( i = 0; i < (size-1)*2; i += 2 ) { - t = 'foo' + i; - types.push( t ); - types.push( t ); - } - // Append test types: - types.push( 'float64' ); - types.push( 'float64' ); - - // Define a list of callbacks: - data = []; - for ( i = 0; i < size-1; i++ ) { - data.push( throwError ); - } - // Append a test callback: - data.push( identity ); - - // Create the dispatcher: - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - // Create sample arrays: - x = new Float64Array( 1 ); - y = new Float64Array( x.length ); - - x = ndarray( 'float64', x, [ 1 ], [ 1 ], 0, 'row-major' ); - y = ndarray( 'float64', y, [ 1 ], [ 1 ], 0, 'row-major' ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var z; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x.data[ 0 ] = i; - z = fcn( x, y ); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var size; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - size = pow( 2, i ); - f = createBenchmark( size ); - bench( pkg+':size='+size, f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 3c6f450..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::fcns_array', function benchmark( b ) { - var types; - var fcns; - var data; - var out; - var i; - - fcns = [ unary ]; - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( fcns, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::fcn_arg', function benchmark( b ) { - var types; - var data; - var out; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( unary, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0aae4af..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch" -%% click B href "https://github.com/stdlib-js/ndarray-dispatch/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-dispatch/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-dispatch/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-dispatch/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-dispatch/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch -[production-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 1295a44..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import dispatch from '../docs/types/index'; -export = dispatch; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c23dc5d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var y=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var b=y(function(D,w){"use strict";function k(i,r,e,u,f,m,n,o,l){var h,t,s,a;for(h=m,s=0;s [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( 'invalid invocation. Insufficient arguments.' );\n\t\t\t}\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = dispatch;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an ndarray function interface which performs multiple dispatch.\n*\n* @module @stdlib/ndarray-dispatch\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var unary = require( '@stdlib/ndarray-base-unary' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var Float64Array = require( '@stdlib/array-float64' );\n* var dispatch = require( '@stdlib/ndarray-dispatch' );\n*\n* var types = [\n* 'float64', 'float64'\n* ];\n*\n* var data = [\n* abs\n* ];\n*\n* var absolute = dispatch( unary, types, data, 2, 1, 1 );\n*\n* // ...\n*\n* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] );\n* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] );\n*\n* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' );\n* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' );\n*\n* absolute( x, y );\n* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA6EA,SAASC,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,EAAU,CAClF,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,CAAU,IAAME,EAAGI,CAAG,EADjBE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,CACP,CACA,MAAO,EACR,CAKAL,EAAO,QAAUC,ICzGjB,IAAAc,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAoB,QAAS,oCAAqC,EAClEC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAkB,QAAS,kCAAmC,EAC9DC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAc,QAAS,yCAA0C,EACjEC,EAAe,IAYnB,SAASC,EAAaC,EAAQ,CAC7B,IAAIC,EACAC,EAGJ,IADAD,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIF,EAAM,OAAQE,IAC9BD,EAAI,KAAMJ,EAAaG,EAAOE,CAAE,CAAE,CAAE,EAErC,OAAOD,CACR,CAqDA,SAASE,EAAUC,EAAMJ,EAAOK,EAAMC,EAAOC,EAAKC,EAAO,CACxD,IAAIC,EACAC,EACAC,EAEJ,GAAKnB,EAAYY,CAAK,EACrBO,EAAMP,UACK,CAACb,EAAiBa,CAAK,EAClC,MAAM,IAAI,UAAWT,EAAQ,oGAAqGS,CAAK,CAAE,EAE1I,GAAK,CAACX,EAAcO,CAAM,EACzB,MAAM,IAAI,UAAWL,EAAQ,+EAAgFK,CAAM,CAAE,EAEtH,GAAK,CAACP,EAAcY,CAAK,GAAKA,IAAS,KACtC,MAAM,IAAI,UAAWV,EAAQ,sFAAuFU,CAAK,CAAE,EAE5H,GAAK,CAAChB,EAAmBiB,CAAM,EAC9B,MAAM,IAAI,UAAWX,EAAQ,6EAA8EW,CAAM,CAAE,EAEpH,GAAK,CAAClB,EAAsBmB,CAAI,EAC/B,MAAM,IAAI,UAAWZ,EAAQ,+EAAgFY,CAAI,CAAE,EAEpH,GAAK,CAACnB,EAAsBoB,CAAK,EAChC,MAAM,IAAI,UAAWb,EAAQ,+EAAgFa,CAAK,CAAE,EAGrH,GADAC,EAAUF,EAAMC,EACXC,IAAY,EAChB,MAAM,IAAI,MAAO,4IAA6I,EAE/J,GAAKH,IAAUG,EACd,MAAM,IAAI,MAAO,4FAA6F,EAE/G,GAAKE,GAEJ,GADAD,EAAQV,EAAM,OAASS,EAClB,CAACnB,EAAWoB,CAAM,EACtB,MAAM,IAAI,MAAO,8IAA+I,UAGjKA,EAAQN,EAAK,OACRJ,EAAM,SAAWU,EAAMD,EAC3B,MAAM,IAAI,MAAO,8IAA+I,EAGlK,GAAKJ,GAAQA,EAAK,SAAWK,EAC5B,MAAM,IAAI,MAAO,mGAAoG,EAEtH,OAAAV,EAAQD,EAAaC,CAAM,EACpBY,EAeP,SAASA,GAAa,CACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EAGJ,GADAa,EAAO,UAAU,OACZA,IAAST,EACb,MAAKS,EAAOT,EACL,IAAI,MAAO,6CAA8C,EAE1D,IAAI,MAAO,yCAA0C,EAI5D,IAFAO,EAAS,CAAC,EACVC,EAAS,CAAC,EACJZ,EAAI,EAAGA,EAAII,EAAOJ,IAAM,CAE7B,GADAe,EAAI,UAAWf,CAAE,EACZ,CAACR,EAAeuB,CAAE,EACtB,MAAKf,EAAIK,EACF,IAAI,UAAWZ,EAAQ,6EAA8EsB,CAAE,CAAE,EAEzG,IAAI,UAAWtB,EAAQ,8EAA+EsB,CAAE,CAAE,EAGlHJ,EAAO,KAAMI,CAAE,EACfH,EAAO,KAAMjB,EAAaD,EAAUqB,CAAE,CAAE,CAAE,CAC3C,CAKA,GAHAD,EAAMlB,EAAcY,EAAOD,EAAST,EAAOS,EAAS,EAAG,EAAGK,EAAQ,EAAG,CAAE,EAGlEE,EAAM,EACV,MAAM,IAAI,UAAW,6GAA8G,EAcpI,GAXKL,EACJO,EAAIP,EAEJO,EAAId,EAAMY,CAAI,EAGVX,EACJa,EAAGL,EAAQR,EAAMW,CAAI,CAAE,EAEvBE,EAAGL,CAAO,EAENL,IAAS,EACb,OAAOK,EAAQJ,EAAQ,CAAE,EAE1B,GAAKD,IAAS,EAGd,OAAOK,EAAO,MAAON,CAAI,CAC1B,CACD,CAKApB,EAAO,QAAUgB,IC9KjB,IAAIgB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_index_of_types", "__commonJSMin", "exports", "module", "indexOfTypes", "N", "M", "x", "strideX1", "strideX2", "offsetX", "y", "strideY", "offsetY", "ix", "iy", "i", "j", "require_main", "__commonJSMin", "exports", "module", "isNonNegativeInteger", "isPositiveInteger", "isInteger", "isFunctionArray", "isFunction", "isCollection", "isndarrayLike", "format", "getDType", "resolveEnum", "indexOfTypes", "types2enums", "types", "out", "i", "dispatch", "fcns", "data", "nargs", "nin", "nout", "narrays", "nfcns", "fcn", "dispatcher", "arrays", "dtypes", "argc", "idx", "v", "f", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 02fe150..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,87 +0,0 @@ - -{{alias}}( fcns, types, data, nargs, nin, nout ) - Returns an ndarray function interface which performs multiple dispatch. - - An ndarray function interface has the following signature: - - f( x, y, ... ) - - where - - - x: ndarray. - - y: ndarray. - - ...: additional ndarrays. - - The number of parameters is derived from `nargs`, the number of input - ndarrays is derived from `nin`, and the number of output ndarrays is derived - from `nout`. - - Parameters - ---------- - fcns: Function|ArrayLikeObject - List of ndarray functions. An ndarray function should have the following - signature: - - f( arrays, data ) - - where - - - arrays: array containing input and output ndarrays. - - data: ndarray function data (e.g., a callback). - - For convenience, a single ndarray function may be provided which will be - invoked whenever the ndarray argument data types match a sequence of - types in `types`. Providing a single ndarray function is particularly - convenient for the case where, regardless of array data types, - traversing arrays remains the same, but the ndarray function `data` - differs (e.g., callbacks which differ based on the array data types). - - types: ArrayLikeObject - One-dimensional list of ndarray argument data types. - - data: ArrayLikeObject|null - ndarray function data (e.g., callbacks). If `null`, a returned ndarray - function interface does **not** provide a `data` argument to an invoked - ndarray function. - - nargs: integer - Total number of ndarray function interface arguments. - - nin: integer - Number of input ndarrays. - - nout: integer - Number of output ndarrays. - - Returns - ------- - fcn: Function - ndarray function interface. - - Examples - -------- - // Define ndarray argument data types: - > var t = [ 'float64', 'float64', 'float32', 'float32' ]; - - // Define a list of ndarray function data (callbacks): - > var d = [ {{alias:@stdlib/math/base/special/abs}}, {{alias:@stdlib/math/base/special/absf}} ]; - - // Create an ndarray function interface for applying unary callbacks: - > var f = {{alias}}( {{alias:@stdlib/ndarray/base/unary}}, t, d, 2, 1, 1 ); - - // Create an input ndarray: - > var xbuf = new {{alias:@stdlib/array/float64}}( [ -1.0, -2.0, -3.0, -4.0 ] ); - > var x = {{alias:@stdlib/ndarray/ctor}}( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Create an output ndarray: - > var ybuf = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 0.0, 0.0 ] ); - > var y = {{alias:@stdlib/ndarray/ctor}}( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Compute the element-wise absolute value: - > f( x, y ); - > ybuf - [ 1.0, 2.0, 3.0, 4.0 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 3fece39..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,615 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable max-lines, prefer-const */ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import ind2sub = require( '@stdlib/ndarray-ind2sub' ); -import dispatch = require( './index' ); - - -// FUNCTIONS // - -/** -* Nullary callback. -* -* @returns input value -*/ -function nullary(): any { - return 5.0; -} - -/** -* Unary callback. -* -* @param x - input value -* @returns input value -*/ -function unary( x: any ): any { - return x; -} - -/** -* Binary callback. -* -* @param x - input value -* @param y - input value -* @returns output value -*/ -function binary( x: number, y: number ): number { - return x + y; -} - -/** -* Ternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @returns output value -*/ -function ternary( x: number, y: number, z: number ): number { - return x + y + z; -} - -/** -* Quaternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @param w - input value -* @returns output value -*/ -function quaternary( x: number, y: number, z: number, w: number ): number { - return x + y + z + w; -} - -/** -* Mock ndarray function. -* -* @param arrays - ndarrays -* @param fcn - callback -*/ -function ndarrayFcn( arrays: Array, fcn: ( x: any ) => any ): void { - let xord; - let yord; - let opts; - let sub; - let sh; - let N; - let x; - let y; - let v; - let i; - - x = arrays[ 0 ]; - y = arrays[ 1 ]; - sh = x.shape; - if ( sh.length === 0 ) { - return; - } - N = 1; - for ( i = 0; i < sh.length; i += 1 ) { - N *= sh[ i ]; - } - xord = x.order; - yord = y.order; - opts = { - 'order': xord - }; - for ( i = 0; i < N; i += 1 ) { - // Convert a linear index to subscripts: - opts.order = xord; - sub = ind2sub( sh, i, opts ); - - // Retrieve an element from `x`: - v = x.get.apply( x, sub ); - - // Convert a linear index to subscripts: - opts.order = yord; - sub = ind2sub( sh, i, opts ); - - // Append the result of applying the callback: - sub[ sub.length ] = fcn( v ) as number; - - // Assign the result to an element in `y`: - y.set.apply( y, sub ); - } -} - -/** -* Mock function to create an ndarray-like object. -* -* @returns ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a dispatch function... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, 1 ); // $ExpectType Dispatcher - dispatch( [ ndarrayFcn ], types, data, 2, 1, 1 ); // $ExpectType Dispatcher -} - -// The compiler throws an error if the function is provided a first argument which is not either an ndarray function or an array-like object containing ndarray functions... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( '10', types, data, 2, 1, 1 ); // $ExpectError - dispatch( 10, types, data, 2, 1, 1 ); // $ExpectError - dispatch( true, types, data, 2, 1, 1 ); // $ExpectError - dispatch( false, types, data, 2, 1, 1 ); // $ExpectError - dispatch( null, types, data, 2, 1, 1 ); // $ExpectError - dispatch( undefined, types, data, 2, 1, 1 ); // $ExpectError - dispatch( [ '1' ], types, data, 2, 1, 1 ); // $ExpectError - dispatch( {}, types, data, 2, 1, 1 ); // $ExpectError - dispatch( ( x: number ): number => x, types, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object... -{ - const data = [ unary ]; - - dispatch( ndarrayFcn, 10, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, true, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, false, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, null, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, undefined, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, {}, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object or null... -{ - const types = [ 'float64', 'float64' ]; - - dispatch( ndarrayFcn, types, 10, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, true, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, false, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, undefined, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, {}, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, '10', 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, true, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, false, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, null, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, undefined, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, [ '1' ], 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, {}, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, ( x: number ): number => x, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, '10', 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, true, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, false, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, null, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, undefined, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, [ '1' ], 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, {}, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, ( x: number ): number => x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, '10' ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, true ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, false ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, null ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, undefined ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, [ '1' ] ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, {} ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch(); // $ExpectError - dispatch( ndarrayFcn ); // $ExpectError - dispatch( ndarrayFcn, types ); // $ExpectError - dispatch( ndarrayFcn, types, data ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, 1, 0 ); // $ExpectError -} - -// The function returns a dispatch function... -{ - const x = array(); - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const t1 = [ 'float64' ]; - const d1 = [ nullary ]; - const f1 = dispatch( ndarrayFcn, t1, d1, 1, 1, 0 ); - f1( x ); // $ExpectType void | ndarray - - const t2 = [ 'float64', 'float64' ]; - const d2 = [ unary ]; - const f2 = dispatch( ndarrayFcn, t2, d2, 2, 1, 1 ); - f2( x, y ); // $ExpectType void | ndarray - - const t3 = [ 'float64', 'float64', 'float64' ]; - const d3 = [ binary ]; - const f3 = dispatch( ndarrayFcn, t3, d3, 3, 2, 1 ); - f3( x, y, z ); // $ExpectType void | ndarray - - const t4 = [ 'float64', 'float64', 'float64', 'float64' ]; - const d4 = [ ternary ]; - const f4 = dispatch( ndarrayFcn, t4, d4, 4, 3, 1 ); - f4( x, y, z, w ); // $ExpectType void | ndarray - - const t5 = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const d5 = [ quaternary ]; - const f5 = dispatch( ndarrayFcn, t5, d5, 5, 4, 1 ); - f5( x, y, z, w, u ); // $ExpectType void | ndarray -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (1 ndarray)... -{ - const types = [ 'float64' ]; - const data = [ nullary ]; - - const f = dispatch( ndarrayFcn, types, data, 1, 0, 1 ); - f( '10' ); // $ExpectError - f( 10 ); // $ExpectError - f( true ); // $ExpectError - f( false ); // $ExpectError - f( null ); // $ExpectError - f( undefined ); // $ExpectError - f( [ '1' ] ); // $ExpectError - f( {} ); // $ExpectError - f( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( 10, y ); // $ExpectError - f( '10', y ); // $ExpectError - f( true, y ); // $ExpectError - f( false, y ); // $ExpectError - f( null, y ); // $ExpectError - f( undefined, y ); // $ExpectError - f( [ '1' ], y ); // $ExpectError - f( {}, y ); // $ExpectError - f( ( x: number ): number => x, y ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const x = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( x, 10 ); // $ExpectError - f( x, '10' ); // $ExpectError - f( x, true ); // $ExpectError - f( x, false ); // $ExpectError - f( x, null ); // $ExpectError - f( x, undefined ); // $ExpectError - f( x, [ '1' ] ); // $ExpectError - f( x, {} ); // $ExpectError - f( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( 10, y, z ); // $ExpectError - f( '10', y, z ); // $ExpectError - f( true, y, z ); // $ExpectError - f( false, y, z ); // $ExpectError - f( null, y, z ); // $ExpectError - f( undefined, y, z ); // $ExpectError - f( [ '1' ], y, z ); // $ExpectError - f( {}, y, z ); // $ExpectError - f( ( x: number ): number => x, y, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, 10, z ); // $ExpectError - f( x, '10', z ); // $ExpectError - f( x, true, z ); // $ExpectError - f( x, false, z ); // $ExpectError - f( x, null, z ); // $ExpectError - f( x, undefined, z ); // $ExpectError - f( x, [ '1' ], z ); // $ExpectError - f( x, {}, z ); // $ExpectError - f( x, ( x: number ): number => x, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, y, '10' ); // $ExpectError - f( x, y, true ); // $ExpectError - f( x, y, false ); // $ExpectError - f( x, y, null ); // $ExpectError - f( x, y, undefined ); // $ExpectError - f( x, y, [ '1' ] ); // $ExpectError - f( x, y, {} ); // $ExpectError - f( x, y, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( 10, y, z, w ); // $ExpectError - f( '10', y, z, w ); // $ExpectError - f( true, y, z, w ); // $ExpectError - f( false, y, z, w ); // $ExpectError - f( null, y, z, w ); // $ExpectError - f( undefined, y, z, w ); // $ExpectError - f( [ '1' ], y, z, w ); // $ExpectError - f( {}, y, z, w ); // $ExpectError - f( ( x: number ): number => x, y, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, 10, z, w ); // $ExpectError - f( x, '10', z, w ); // $ExpectError - f( x, true, z, w ); // $ExpectError - f( x, false, z, w ); // $ExpectError - f( x, null, z, w ); // $ExpectError - f( x, undefined, z, w ); // $ExpectError - f( x, [ '1' ], z, w ); // $ExpectError - f( x, {}, z, w ); // $ExpectError - f( x, ( x: number ): number => x, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, 10, w ); // $ExpectError - f( x, y, '10', w ); // $ExpectError - f( x, y, true, w ); // $ExpectError - f( x, y, false, w ); // $ExpectError - f( x, y, null, w ); // $ExpectError - f( x, y, undefined, w ); // $ExpectError - f( x, y, [ '1' ], w ); // $ExpectError - f( x, y, {}, w ); // $ExpectError - f( x, y, ( x: number ): number => x, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, z, 10 ); // $ExpectError - f( x, y, z, '10' ); // $ExpectError - f( x, y, z, true ); // $ExpectError - f( x, y, z, false ); // $ExpectError - f( x, y, z, null ); // $ExpectError - f( x, y, z, undefined ); // $ExpectError - f( x, y, z, [ '1' ] ); // $ExpectError - f( x, y, z, {} ); // $ExpectError - f( x, y, z, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( 10, y, z, w, u ); // $ExpectError - f( '10', y, z, w, u ); // $ExpectError - f( true, y, z, w, u ); // $ExpectError - f( false, y, z, w, u ); // $ExpectError - f( null, y, z, w, u ); // $ExpectError - f( undefined, y, z, w, u ); // $ExpectError - f( [ '1' ], y, z, w, u ); // $ExpectError - f( {}, y, z, w, u ); // $ExpectError - f( ( x: number ): number => x, y, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, 10, z, w, u ); // $ExpectError - f( x, '10', z, w, u ); // $ExpectError - f( x, true, z, w, u ); // $ExpectError - f( x, false, z, w, u ); // $ExpectError - f( x, null, z, w, u ); // $ExpectError - f( x, undefined, z, w, u ); // $ExpectError - f( x, [ '1' ], z, w, u ); // $ExpectError - f( x, {}, z, w, u ); // $ExpectError - f( x, ( x: number ): number => x, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, 10, w, u ); // $ExpectError - f( x, y, '10', w, u ); // $ExpectError - f( x, y, true, w, u ); // $ExpectError - f( x, y, false, w, u ); // $ExpectError - f( x, y, null, w, u ); // $ExpectError - f( x, y, undefined, w, u ); // $ExpectError - f( x, y, [ '1' ], w, u ); // $ExpectError - f( x, y, {}, w, u ); // $ExpectError - f( x, y, ( x: number ): number => x, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, 10, u ); // $ExpectError - f( x, y, z, '10', u ); // $ExpectError - f( x, y, z, true, u ); // $ExpectError - f( x, y, z, false, u ); // $ExpectError - f( x, y, z, null, u ); // $ExpectError - f( x, y, z, undefined, u ); // $ExpectError - f( x, y, z, [ '1' ], u ); // $ExpectError - f( x, y, z, {}, u ); // $ExpectError - f( x, y, z, ( x: number ): number => x, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fifth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, w, 10 ); // $ExpectError - f( x, y, z, w, '10' ); // $ExpectError - f( x, y, z, w, true ); // $ExpectError - f( x, y, z, w, false ); // $ExpectError - f( x, y, z, w, null ); // $ExpectError - f( x, y, z, w, undefined ); // $ExpectError - f( x, y, z, w, [ '1' ] ); // $ExpectError - f( x, y, z, w, {} ); // $ExpectError - f( x, y, z, w, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/add.js b/examples/add.js deleted file mode 100644 index 775b711..0000000 --- a/examples/add.js +++ /dev/null @@ -1,121 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var dispatch = require( './../lib' ); - -function add2( arrays ) { - var opts; - var xo; - var yo; - var zo; - var sx; - var sy; - var sz; - var sh; - var N; - var x; - var y; - var z; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - z = arrays[ 2 ]; - xo = x.order; - yo = y.order; - zo = z.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - opts.order = yo; - sy = ind2sub( sh, i, opts ); - v = x.get.apply( x, sx ) + y.get.apply( y, sy ); - - opts.order = zo; - sz = ind2sub( sh, i, opts ); - sz.push( v ); - z.set.apply( z, sz ); - } -} - -var fcns = [ - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2 -]; - -var types = [ - dtypes.float64, dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.int32, dtypes.int32, - dtypes.uint32, dtypes.uint32, dtypes.uint32, - dtypes.int16, dtypes.int16, dtypes.int16, - dtypes.uint16, dtypes.uint16, dtypes.uint16, - dtypes.int8, dtypes.int8, dtypes.int8, - dtypes.uint8, dtypes.uint8, dtypes.uint8, - dtypes.uint8c, dtypes.uint8c, dtypes.uint8c -]; - -var add = dispatch( fcns, types, null, 3, 2, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var zbuf = new Float64Array( xbuf.length ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var z = ndarray( 'float64', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); - -xbuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -ybuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -zbuf = new Int32Array( xbuf.length ); - -x = ndarray( 'int32', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'int32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -z = ndarray( 'int32', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); diff --git a/examples/sin.js b/examples/sin.js deleted file mode 100644 index 8cd4871..0000000 --- a/examples/sin.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int8Array = require( '@stdlib/array-int8' ); -var sin = require( '@stdlib/math-base-special-sin' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/strided-dtypes' ); -var dispatch = require( './../lib' ); - -function apply( arrays, fcn ) { - var opts; - var xo; - var yo; - var sx; - var sy; - var sh; - var N; - var x; - var y; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - xo = x.order; - yo = y.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - v = fcn( x.get.apply( x, sx ) ); - - opts.order = yo; - sy = ind2sub( sh, i, opts ); - sy.push( v ); - y.set.apply( y, sy ); - } -} - -var fcns = [ - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply -]; - -var types = [ - dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float64, - dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.float64, - dtypes.uint32, dtypes.float64, - dtypes.int16, dtypes.float64, - dtypes.int16, dtypes.float32, - dtypes.uint16, dtypes.float64, - dtypes.uint16, dtypes.float32, - dtypes.int8, dtypes.float64, - dtypes.int8, dtypes.float32, - dtypes.uint8, dtypes.float64, - dtypes.uint8, dtypes.float32, - dtypes.uint8c, dtypes.float64, - dtypes.uint8c, dtypes.float32 -]; - -var data = [ - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin -]; - -var sine = dispatch( fcns, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); - -xbuf = new Int8Array( [ 1, 2, 3, 4, 5 ] ); -ybuf = new Float32Array( xbuf.length ); - -x = ndarray( 'int8', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'float32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); diff --git a/examples/unary.js b/examples/unary.js deleted file mode 100644 index e9c3fb4..0000000 --- a/examples/unary.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -var unary = require( '@stdlib/ndarray-base-unary' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var dispatch = require( './../lib' ); - -var types = [ 'float64', 'float64' ]; - -var data = [ - abs -]; - -var absolute = dispatch( unary, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -absolute( x, y ); -console.log( ybuf ); -// => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 5f280a1..c49a4e4 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..d798c10 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@v0.2.2-esm/index.mjs";function m(m,f,l,p,w,v){var a,g,c;if(i(m))c=m;else if(!s(m))throw new TypeError(d("0jr5d",m));if(!n(f))throw new TypeError(d("0jr2y",f));if(!n(l)&&null!==l)throw new TypeError(d("0jr5e",l));if(!e(p))throw new TypeError(d("0jr5f",p));if(!r(w))throw new TypeError(d("0jr5X",w));if(!r(v))throw new TypeError(d("0jr5g",v));if(0===(a=w+v))throw new Error(d("0jr0h"));if(p!==a)throw new Error(d("0jr0i"));if(c){if(g=f.length/a,!t(g))throw new Error(d("0jr0j"))}else if(g=m.length,f.length!==g*a)throw new Error(d("0jr0j"));if(l&&l.length!==g)throw new Error(d("0jr0k"));return f=function(r){var e,t;for(e=[],t=0;t [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0jr5d', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0jr2y', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( '0jr5e', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0jr5f', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0jr5X', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0jr5g', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format('0jr0h') );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format('0jr0i') );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format('0jr0k') );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format('0jr0l') );\n\t\t\t}\n\t\t\tthrow new Error( format('0jr0m') );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( '0jr5h', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( '0jr5i', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format('0jr0n') );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found).\n*\n* ## Notes\n*\n* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types).\n* - The function assumes that `x` is stored in row-major order.\n* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`.\n* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value.\n*\n* @private\n* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension)\n* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension)\n* @param {ArrayLikeObject} x - input two-dimensional reference array\n* @param {integer} strideX1 - `x` stride length along first dimension\n* @param {integer} strideX2 - `x` stride length along second dimension\n* @param {NonNegativeInteger} offsetX - `x` starting index\n* @param {ArrayLikeObject} y - search array\n* @param {integer} strideY - `y` stride length\n* @param {NonNegativeInteger} offsetY - `y` starting index\n* @returns {integer} row index (if found) and `-1` otherwise\n*\n* @example\n* // Define a reference array to search:\n* var types = [\n* 'float64', 'float64', 'float64',\n* 'float32', 'float32', 'float32',\n* 'uint32', 'uint32', 'float64',\n* 'int32', 'int32', 'float64',\n* 'uint16', 'uint16', 'float64',\n* 'int16', 'int16', 'float64',\n* 'uint8', 'uint8', 'float64',\n* 'int8', 'int8', 'float64'\n* ];\n*\n* // Define reference array dimensions:\n* var N = 8; // rows\n* var M = 3; // columns\n*\n* // Define a search array:\n* y1 = [\n* 'float32', 'float32', 'float32',\n* ];\n*\n* // Find the list of types:\n* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 );\n* // returns 1\n*\n// Define a search array:\n* y2 = [\n* 'float32', 'float32', 'float64',\n* ];\n*\n* // Find the list of types:\n* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 );\n* // returns -1\n*/\nfunction indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len\n\tvar ix;\n\tvar iy;\n\tvar i;\n\tvar j;\n\n\t// Search for the first row which matches `y`...\n\tix = offsetX;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tiy = offsetY;\n\t\tfor ( j = 0; j < M; j++ ) {\n\t\t\tif ( x[ ix+(j*strideX2) ] !== y[ iy ] ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tiy += strideY;\n\t\t}\n\t\t// If we successfully iterated over all columns, then that means we've found a match...\n\t\tif ( j === M ) {\n\t\t\treturn i;\n\t\t}\n\t\tix += strideX1;\n\t}\n\treturn -1;\n}\n\n\n// EXPORTS //\n\nexport default indexOfTypes;\n"],"names":["dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","out","i","push","resolveEnum","types2enums","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","getDType","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","j","indexOfTypes","slice"],"mappings":";;0+BA0GA,SAASA,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAO,UAEzB,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAO,UAEzB,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAO,eAIzB,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAO,UAG1B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAO,UAGzB,OADAX,EA5GD,SAAsBA,GACrB,IAAIkB,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAInB,EAAMgB,OAAQG,IAC9BD,EAAIE,KAAMC,EAAarB,EAAOmB,KAE/B,OAAOD,CACR,CAmGSI,CAAatB,GAgBrB,WACC,IAAIuB,EACAC,EACAC,EACAC,EACAC,EACAC,EACAT,EAGJ,GADAM,EAAOI,UAAUb,OACZS,IAASvB,EAAQ,CACrB,GAAKuB,EAAOvB,EACX,MAAM,IAAIa,MAAOJ,EAAO,UAEzB,MAAM,IAAII,MAAOJ,EAAO,SACxB,CAGD,IAFAY,EAAS,GACTC,EAAS,GACHL,EAAI,EAAGA,EAAIjB,EAAOiB,IAAM,CAE7B,IAAMW,EADNH,EAAIE,UAAWV,IAEd,MAAKA,EAAIhB,EACF,IAAIO,UAAWC,EAAQ,QAASgB,IAEhC,IAAIjB,UAAWC,EAAQ,QAASgB,IAGxCJ,EAAOH,KAAMO,GACbH,EAAOJ,KAAMC,EAAaU,EAAUJ,IACpC,CAKD,IAHAD,EC1HF,SAAuBM,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAvB,EACAwB,EAIJ,IADAF,EAAKJ,EACClB,EAAI,EAAGA,EAAIa,EAAGb,IAAM,CAEzB,IADAuB,EAAKF,EACCG,EAAI,EAAGA,EAAIV,GACXC,EAAGO,EAAIE,EAAEP,KAAgBE,EAAGI,GADdC,IAInBD,GAAMH,EAGP,GAAKI,IAAMV,EACV,OAAOd,EAERsB,GAAMN,CACN,CACD,OAAQ,CACT,CDmGQS,CAActC,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGmB,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAId,UAAWC,EAAO,UAI5BiB,EADIrB,GAGAR,EAAM2B,GAGNzB,EACJ2B,EAAGL,EAAQtB,EAAMyB,IAEjBE,EAAGL,GAEJ,GAAc,IAATnB,EACJ,OAAOmB,EAAQlB,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOmB,EAAOsB,MAAO1C,EACrB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 88f0e3e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Create an ndarray function interface which performs multiple dispatch. -* -* @module @stdlib/ndarray-dispatch -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var dispatch = require( '@stdlib/ndarray-dispatch' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/index_of_types.js b/lib/index_of_types.js deleted file mode 100644 index fda2297..0000000 --- a/lib/index_of_types.js +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found). -* -* ## Notes -* -* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types). -* - The function assumes that `x` is stored in row-major order. -* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`. -* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value. -* -* @private -* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension) -* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension) -* @param {ArrayLikeObject} x - input two-dimensional reference array -* @param {integer} strideX1 - `x` stride length along first dimension -* @param {integer} strideX2 - `x` stride length along second dimension -* @param {NonNegativeInteger} offsetX - `x` starting index -* @param {ArrayLikeObject} y - search array -* @param {integer} strideY - `y` stride length -* @param {NonNegativeInteger} offsetY - `y` starting index -* @returns {integer} row index (if found) and `-1` otherwise -* -* @example -* // Define a reference array to search: -* var types = [ -* 'float64', 'float64', 'float64', -* 'float32', 'float32', 'float32', -* 'uint32', 'uint32', 'float64', -* 'int32', 'int32', 'float64', -* 'uint16', 'uint16', 'float64', -* 'int16', 'int16', 'float64', -* 'uint8', 'uint8', 'float64', -* 'int8', 'int8', 'float64' -* ]; -* -* // Define reference array dimensions: -* var N = 8; // rows -* var M = 3; // columns -* -* // Define a search array: -* y1 = [ -* 'float32', 'float32', 'float32', -* ]; -* -* // Find the list of types: -* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 ); -* // returns 1 -* -// Define a search array: -* y2 = [ -* 'float32', 'float32', 'float64', -* ]; -* -* // Find the list of types: -* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 ); -* // returns -1 -*/ -function indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len - var ix; - var iy; - var i; - var j; - - // Search for the first row which matches `y`... - ix = offsetX; - for ( i = 0; i < N; i++ ) { - iy = offsetY; - for ( j = 0; j < M; j++ ) { - if ( x[ ix+(j*strideX2) ] !== y[ iy ] ) { - break; - } - iy += strideY; - } - // If we successfully iterated over all columns, then that means we've found a match... - if ( j === M ) { - return i; - } - ix += strideX1; - } - return -1; -} - - -// EXPORTS // - -module.exports = indexOfTypes; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4648598..0000000 --- a/lib/main.js +++ /dev/null @@ -1,231 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isFunctionArray = require( '@stdlib/assert-is-function-array' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var resolveEnum = require( '@stdlib/ndarray-base-dtype-resolve-enum' ); -var indexOfTypes = require( './index_of_types.js' ); - - -// FUNCTIONS // - -/** -* Returns a list of data type enumeration constants. -* -* @private -* @param {Collection} types - list of types -* @returns {IntegerArray} list of data type enumeration constants -*/ -function types2enums( types ) { - var out; - var i; - - out = []; - for ( i = 0; i < types.length; i++ ) { - out.push( resolveEnum( types[ i ] ) ); - } - return out; -} - - -// MAIN // - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param {(FunctionArray|Function)} fcns - list of ndarray functions -* @param {Collection} types - one-dimensional list of ndarray argument data types -* @param {(Collection|null)} data - ndarray function data (e.g., callbacks) -* @param {PositiveInteger} nargs - total number of ndarray function interface arguments -* @param {NonNegativeInteger} nin - number of input ndarrays -* @param {NonNegativeInteger} nout - number of output ndarrays -* @throws {TypeError} first argument must be either a function or an array of functions -* @throws {TypeError} second argument must be an array-like object -* @throws {TypeError} third argument must be an array-like object or `null` -* @throws {Error} third and first arguments must have the same number of elements -* @throws {TypeError} fourth argument must be a positive integer -* @throws {TypeError} fifth argument must be a nonnegative integer -* @throws {TypeError} sixth argument must be a nonnegative integer -* @throws {Error} fourth argument must equal the specified number of input and output arrays -* @throws {Error} number of types must match the number of functions times the total number of array arguments for each function -* @throws {Error} interface must accept at least one input and/or output ndarray -* @returns {Function} ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function dispatch( fcns, types, data, nargs, nin, nout ) { - var narrays; - var nfcns; - var fcn; - - if ( isFunction( fcns ) ) { - fcn = fcns; - } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( '0jr5d', fcns ) ); - } - if ( !isCollection( types ) ) { - throw new TypeError( format( '0jr2y', types ) ); - } - if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( '0jr5e', data ) ); - } - if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( '0jr5f', nargs ) ); - } - if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( '0jr5X', nin ) ); - } - if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( '0jr5g', nout ) ); - } - narrays = nin + nout; - if ( narrays === 0 ) { - throw new Error( format('0jr0h') ); - } - if ( nargs !== narrays ) { - throw new Error( format('0jr0i') ); - } - if ( fcn ) { - nfcns = types.length / narrays; - if ( !isInteger( nfcns ) ) { - throw new Error( format('0jr0j') ); - } - } else { - nfcns = fcns.length; - if ( types.length !== nfcns*narrays ) { - throw new Error( format('0jr0j') ); - } - } - if ( data && data.length !== nfcns ) { - throw new Error( format('0jr0k') ); - } - types = types2enums( types ); - return dispatcher; - - /** - * ndarray function interface which performs multiple dispatch. - * - * @private - * @param {ndarrayLike} x - ndarray - * @param {...ndarrayLike} args - ndarray arguments - * @throws {Error} insufficient arguments - * @throws {Error} too many arguments - * @throws {TypeError} input array arguments must be ndarray-like objects - * @throws {TypeError} output array arguments must be ndarray-like objects - * @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types - * @returns {(ndarrayLike|Array|void)} destination array(s) - */ - function dispatcher() { - var arrays; - var dtypes; - var argc; - var idx; - var v; - var f; - var i; - - argc = arguments.length; - if ( argc !== nargs ) { - if ( argc < nargs ) { - throw new Error( format('0jr0l') ); - } - throw new Error( format('0jr0m') ); - } - arrays = []; - dtypes = []; - for ( i = 0; i < nargs; i++ ) { - v = arguments[ i ]; - if ( !isndarrayLike( v ) ) { - if ( i < nin ) { - throw new TypeError( format( '0jr5h', v ) ); - } else { - throw new TypeError( format( '0jr5i', v ) ); - } - } - arrays.push( v ); - dtypes.push( resolveEnum( getDType( v ) ) ); - } - // Resolve the ndarray function satisfying the input array types: - idx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len - - // Check whether we were able to successfully resolve an ndarray function: - if ( idx < 0 ) { - throw new TypeError( format('0jr0n') ); - } - // Retrieve the ndarray function: - if ( fcn ) { - f = fcn; - } else { - f = fcns[ idx ]; - } - // Evaluate the ndarray function: - if ( data ) { - f( arrays, data[ idx ] ); - } else { - f( arrays ); - } - if ( nout === 1 ) { - return arrays[ narrays-1 ]; - } - if ( nout === 0 ) { - return; - } - return arrays.slice( nin ); - } -} - - -// EXPORTS // - -module.exports = dispatch; diff --git a/package.json b/package.json index 5f84ca4..e6c8bad 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Create an ndarray function interface which performs multiple dispatch.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,57 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-function-array": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer": "^0.2.2", - "@stdlib/assert-is-positive-integer": "^0.2.2", - "@stdlib/ndarray-base-dtype-resolve-enum": "^0.2.2", - "@stdlib/ndarray-dtype": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.2.2", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/array-int8": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/math-base-assert-is-nan": "^0.2.2", - "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/math-base-special-pow": "^0.3.0", - "@stdlib/math-base-special-sin": "^0.3.0", - "@stdlib/ndarray-base-buffer-dtype": "^0.3.0", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-unary": "^0.2.1", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-dtypes": "^0.3.0", - "@stdlib/ndarray-ind2sub": "^0.2.2", - "@stdlib/strided-dtypes": "^0.3.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "ndarray", @@ -100,7 +26,6 @@ "multimethod", "multimethods" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..252182f --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/fixtures/binary.js b/test/fixtures/binary.js deleted file mode 100644 index a60dfa2..0000000 --- a/test/fixtures/binary.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Binary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @returns {number} sum -*/ -function binary( x, y ) { - return x + y; -} - - -// EXPORTS // - -module.exports = binary; diff --git a/test/fixtures/fill.js b/test/fixtures/fill.js deleted file mode 100644 index 41b2958..0000000 --- a/test/fixtures/fill.js +++ /dev/null @@ -1,76 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which fills one or more ndarrays. -* -* @private -* @param {*} value - fill value -* @returns {Function} ndarray function -*/ -function fill( value ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - */ - function ndarrayFcn( arrays ) { - var opts; - var sub; - var arr; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - opts = { - 'order': '' - }; - for ( j = 0; j < M; j++ ) { - arr = arrays[ j ]; - opts.order = arrays[ j ].order; - for ( i = 0; i < N; i++ ) { - sub = ind2sub( sh, i, opts ); - sub.push( value ); - arr.set.apply( arr, sub ); - } - } - } -} - - -// EXPORTS // - -module.exports = fill; diff --git a/test/fixtures/foreach.js b/test/fixtures/foreach.js deleted file mode 100644 index a426290..0000000 --- a/test/fixtures/foreach.js +++ /dev/null @@ -1,72 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function forEach( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - fcn.apply( null, args ); - } -} - - -// EXPORTS // - -module.exports = forEach; diff --git a/test/fixtures/map1n.js b/test/fixtures/map1n.js deleted file mode 100644 index 614196b..0000000 --- a/test/fixtures/map1n.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function which maps the return value of a callback to `N` arrays. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function map1N( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var v; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - v = fcn(); - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - sub.push( v ); - arrays[ j ].set.apply( arrays[ j ], sub ); - } - } -} - - -// EXPORTS // - -module.exports = map1N; diff --git a/test/fixtures/nullary.js b/test/fixtures/nullary.js deleted file mode 100644 index 4f22126..0000000 --- a/test/fixtures/nullary.js +++ /dev/null @@ -1,36 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Nullary callback. -* -* @private -* @returns {number} value -*/ -function nullary() { - return 3.0; -} - - -// EXPORTS // - -module.exports = nullary; diff --git a/test/fixtures/quaternary.js b/test/fixtures/quaternary.js deleted file mode 100644 index 548437b..0000000 --- a/test/fixtures/quaternary.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quaternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @returns {number} sum -*/ -function quaternary( x, y, z, w ) { - return x + y + z + w; -} - - -// EXPORTS // - -module.exports = quaternary; diff --git a/test/fixtures/quinary.js b/test/fixtures/quinary.js deleted file mode 100644 index 36068de..0000000 --- a/test/fixtures/quinary.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quinary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @param {number} u - input value -* @returns {number} sum -*/ -function quinary( x, y, z, w, u ) { - return x + y + z + w + u; -} - - -// EXPORTS // - -module.exports = quinary; diff --git a/test/fixtures/sum.js b/test/fixtures/sum.js deleted file mode 100644 index efdbb1b..0000000 --- a/test/fixtures/sum.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which computes the sum across one or more ndarrays. -* -* @private -* @param {Object} ctx - context -* @param {number} ctx.sum - initial sum -* @returns {Function} ndarray function -*/ -function wrapper( ctx ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - * @param {Function} [fcn] - callback - */ - function ndarrayFcn( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var f; - var i; - var j; - - if ( arguments.length > 1 ) { - f = fcn; - } - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - if ( f ) { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - ctx.sum += f.apply( null, args ); - } - } else { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - ctx.sum += arrays[ j ].get.apply( arrays[ j ], sub ); - } - } - } - } -} - - -// EXPORTS // - -module.exports = wrapper; diff --git a/test/fixtures/ternary.js b/test/fixtures/ternary.js deleted file mode 100644 index 0595d5f..0000000 --- a/test/fixtures/ternary.js +++ /dev/null @@ -1,39 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Ternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @returns {number} sum -*/ -function ternary( x, y, z ) { - return x + y + z; -} - - -// EXPORTS // - -module.exports = ternary; diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d6c2c8e..0000000 --- a/test/test.js +++ /dev/null @@ -1,363 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var fill = require( './fixtures/fill.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either a function or an array of functions as a first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( value, types, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object as a second argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided either an array-like object or `null` as a third argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - dispatch( unary, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a positive integer for a fourth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 0, - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a fifth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, value, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a sixth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, 1, value ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function array)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var fcns = [ unary, unary, unary ]; - var data = [ abs, abs, abs ]; - dispatch( fcns, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function argument)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs, abs, abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the length of `data` argument does not match the number of ndarray functions', function test( t ) { - var values; - var i; - - values = [ - [], - [ abs, abs ], - [ abs, abs, abs ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var fcns = [ unary ]; - dispatch( fcns, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the fourth argument is incompatible with the number of input and output ndarrays', function test( t ) { - var values; - var i; - - values = [ - 0, - 1, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of specified input and output ndarrays is zero', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var types = [ 'float64' ]; - dispatch( fill( 3 ), types, null, 1, 0, 0 ); - } -}); - -tape( 'the function returns an ndarray function interface', function test( t ) { - var types; - var data; - var f; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - f = dispatch( unary, types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ unary ], types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( fill( 3 ), types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ fill( 3 ) ], types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.two_arrays.js b/test/test.two_arrays.js deleted file mode 100644 index 16eb61b..0000000 --- a/test/test.two_arrays.js +++ /dev/null @@ -1,814 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var dtype = require( '@stdlib/ndarray-base-buffer-dtype' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var forEach = require( './fixtures/foreach.js' ); -var map1N = require( './fixtures/map1n.js' ); -var fill = require( './fixtures/fill.js' ); -var sum = require( './fixtures/sum.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the first argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var ybuf = new Float64Array( 10 ); - var y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( value, y ); - }; - } -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the second argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var xbuf = new Float64Array( 10 ); - var x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( x, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided insufficient arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var f; - var x; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [], - [ x ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided too many arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var ybuf; - var f; - var x; - var y; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [ x, y, y ], - [ x, y, y, y ], - [ x, y, y, y, y ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if unable to resolve a ndarray function supporting the provided array argument data types', function test( t ) { - var values; - var types; - var data; - var xbuf; - var fcn; - var x; - var i; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ abs, abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 4 ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - values = [ - new Uint8Array( 4 ), - new Int32Array( 4 ), - [ 0, 0, 0, 0 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided an array having data type: ' + dtype( values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var y = ndarray( dtype( value ), value, [ value.length ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - }; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only input arrays)', function test( t ) { - var types; - var xbuf; - var ybuf; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only output arrays)', function test( t ) { - var expected; - var types; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only input arrays)', function test( t ) { - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var ctx; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcns = [ - sum( ctx ), - sum( ctx ) - ]; - fcn = dispatch( fcns, types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only output arrays)', function test( t ) { - var expected; - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcns = [ - fill( 3.0 ), - fill( 4.0 ) - ]; - fcn = dispatch( fcns, types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - - fcn = dispatch( forEach, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - - fcn = dispatch( map1N, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - fcns = [ - forEach, - forEach - ]; - fcn = dispatch( fcns, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - fcns = [ - map1N, - map1N - ]; - fcn = dispatch( fcns, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - fcns = [ - unary, - unary - ]; - fcn = dispatch( fcns, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which returns one or more output arrays, if one or more output arrays is specified, and otherwise returns `undefined`', function test( t ) { - var types; - var data; - var xbuf; - var ybuf; - var out; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - // No output arrays... - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, void 0, 'returns expected value' ); - - // One output array... - data = [ - abs, - abs - ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - fcn = dispatch( fill( 3.0 ), types, null, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - // Two output arrays... - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.end(); -}); From 5d68faaf1a4c9292004d96cca1f537202c01c287 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 26 May 2025 01:21:26 +0000 Subject: [PATCH 098/109] Transform error messages --- lib/main.js | 34 +++++++++++++++++----------------- package.json | 2 +- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/main.js b/lib/main.js index 5f4bb5d..4648598 100644 --- a/lib/main.js +++ b/lib/main.js @@ -27,7 +27,7 @@ var isFunctionArray = require( '@stdlib/assert-is-function-array' ); var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var getDType = require( '@stdlib/ndarray-dtype' ); var resolveEnum = require( '@stdlib/ndarray-base-dtype-resolve-enum' ); var indexOfTypes = require( './index_of_types.js' ); @@ -112,43 +112,43 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { if ( isFunction( fcns ) ) { fcn = fcns; } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) ); + throw new TypeError( format( '0jr5d', fcns ) ); } if ( !isCollection( types ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) ); + throw new TypeError( format( '0jr2y', types ) ); } if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); + throw new TypeError( format( '0jr5e', data ) ); } if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) ); + throw new TypeError( format( '0jr5f', nargs ) ); } if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) ); + throw new TypeError( format( '0jr5X', nin ) ); } if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) ); + throw new TypeError( format( '0jr5g', nout ) ); } narrays = nin + nout; if ( narrays === 0 ) { - throw new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' ); + throw new Error( format('0jr0h') ); } if ( nargs !== narrays ) { - throw new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' ); + throw new Error( format('0jr0i') ); } if ( fcn ) { nfcns = types.length / narrays; if ( !isInteger( nfcns ) ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format('0jr0j') ); } } else { nfcns = fcns.length; if ( types.length !== nfcns*narrays ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format('0jr0j') ); } } if ( data && data.length !== nfcns ) { - throw new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' ); + throw new Error( format('0jr0k') ); } types = types2enums( types ); return dispatcher; @@ -178,9 +178,9 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { argc = arguments.length; if ( argc !== nargs ) { if ( argc < nargs ) { - throw new Error( 'invalid invocation. Insufficient arguments.' ); + throw new Error( format('0jr0l') ); } - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('0jr0m') ); } arrays = []; dtypes = []; @@ -188,9 +188,9 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { v = arguments[ i ]; if ( !isndarrayLike( v ) ) { if ( i < nin ) { - throw new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) ); + throw new TypeError( format( '0jr5h', v ) ); } else { - throw new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) ); + throw new TypeError( format( '0jr5i', v ) ); } } arrays.push( v ); @@ -201,7 +201,7 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { // Check whether we were able to successfully resolve an ndarray function: if ( idx < 0 ) { - throw new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' ); + throw new TypeError( format('0jr0n') ); } // Retrieve the ndarray function: if ( fcn ) { diff --git a/package.json b/package.json index 12f46eb..5f84ca4 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@stdlib/assert-is-positive-integer": "^0.2.2", "@stdlib/ndarray-base-dtype-resolve-enum": "^0.2.2", "@stdlib/ndarray-dtype": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From b397c693ed8d2fc76d842923d41e42bca0551b8d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 26 May 2025 01:59:48 +0000 Subject: [PATCH 099/109] Remove files --- index.d.ts | 334 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5181 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index c49a4e4..0000000 --- a/index.d.ts +++ /dev/null @@ -1,334 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* ndarray function. -* -* @param arrays - array containing input and output ndarrays -* @param data - ndarray function data (e.g., a callback) -* -* @example -* var numel = require( '@stdlib/ndarray-base-numel' ); -* var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -* -* function ndarrayFcn( arrays, fcn ) { -* var xord; -* var yord; -* var opts; -* var sub; -* var sh; -* var N; -* var x; -* var y; -* var v; -* var i; -* -* x = arrays[ 0 ]; -* y = arrays[ 1 ]; -* sh = x.shape; -* N = numel( sh ); -* if ( N <= 0 ) { -* return; -* } -* xord = x.order; -* yord = y.order; -* opts = {}; -* opts.order = xord; -* for ( i = 0; i < N; i++ ) { -* // Convert a linear index to subscripts: -* opts.order = xord; -* sub = ind2sub( sh, i, opts ); -* -* // Retrieve an element from `x`: -* v = x.get.apply( x, sub ); -* -* // Convert a linear index to subscripts: -* opts.order = yord; -* sub = ind2sub( sh, i, opts ); -* -* // Append the result of applying the callback: -* sub.push( fcn( v ) ); -* -* // Assign the result to an element in `y`: -* y.set.apply( y, sub ); -* } -* } -*/ -type ndarrayFcn = ( arrays: Array, data?: any ) => void; - -/** -* Interface describing an ndarray function dispatcher. -*/ -interface Dispatcher { - /** - * Invokes an ndarray function based on the provided array data type(s). - * - * @param x - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array - * - * @example - * var nullary = require( '@stdlib/ndarray-base-nullary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function value() { - * return 3.14; - * } - * - * var types = [ 'float64' ]; - * var data = [ value ]; - * - * var fcn = dispatch( nullary, types, data, 1, 0, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( 5 ); - * var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x ); - * // xbuf => [ 3.14, 3.14, 3.14, 3.14, 3.14 ] - */ - ( x: ndarray ): ndarray | void; - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var unary = require( '@stdlib/ndarray-base-unary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * var abs = require( '@stdlib/math-base-special-abs' ); - * - * var types = [ 'float64', 'float64' ]; - * var data = [ abs ]; - * - * var fcn = dispatch( unary, types, data, 2, 1, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - * var ybuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y ); - * // ybuf => [ 1.0, 2.0, 3.0 ] - */ - ( x: ndarray, y: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var ternary = require( '@stdlib/ndarray-base-ternary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function add2( x, y ) { - * return x + y; - * } - * - * var types = [ 'float64', 'float64', 'float64' ]; - * var data = [ add2 ]; - * - * var fcn = dispatch( ternary, types, data, 3, 2, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z ); - * // zbuf => [ 2.0, 4.0, 6.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quaternary = require( '@stdlib/ndarray-base-quaternary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function add3( x, y, z ) { - * return x + y + z; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add3 ]; - * - * var fcn = dispatch( quaternary, types, data, 4, 3, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w ); - * // wbuf => [ 3.0, 6.0, 9.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @param args - ndarray arguments - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quinary = require( '@stdlib/ndarray-base-quinary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function add4( x, y, z, w ) { - * return x + y + z + w; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add4 ]; - * - * var fcn = dispatch( quinary, types, data, 5, 4, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ubuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var u = ndarray( 'float64', ubuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w, u ); - * // ubuf => [ 4.0, 8.0, 12.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray, ...args: Array ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures -} - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param fcns - list of ndarray functions -* @param types - one-dimensional list of ndarray argument data types -* @param data - ndarray function data (e.g., callbacks) -* @param nargs - total number of ndarray function interface arguments -* @param nin - number of input ndarrays -* @param nout - number of output ndarrays -* @throws first argument must be either a function or an array of functions -* @throws second argument must be an array-like object -* @throws third argument must be an array-like object or `null` -* @throws third and first arguments must have the same number of elements -* @throws fourth argument must be a positive integer -* @throws fifth argument must be a nonnegative integer -* @throws sixth argument must be a nonnegative integer -* @throws fourth argument must equal the specified number of input and output arrays -* @throws number of types must match the number of functions times the total number of array arguments for each function -* @throws interface must accept at least one input and/or output ndarray -* @returns ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var fcn = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* fcn( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function dispatch( fcns: ndarrayFcn | ArrayLike, types: ArrayLike, data: ArrayLike | null, nargs: number, nin: number, nout: number ): Dispatcher; - - -// EXPORTS // - -export = dispatch; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index d798c10..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@v0.2.2-esm/index.mjs";function m(m,f,l,p,w,v){var a,g,c;if(i(m))c=m;else if(!s(m))throw new TypeError(d("0jr5d",m));if(!n(f))throw new TypeError(d("0jr2y",f));if(!n(l)&&null!==l)throw new TypeError(d("0jr5e",l));if(!e(p))throw new TypeError(d("0jr5f",p));if(!r(w))throw new TypeError(d("0jr5X",w));if(!r(v))throw new TypeError(d("0jr5g",v));if(0===(a=w+v))throw new Error(d("0jr0h"));if(p!==a)throw new Error(d("0jr0i"));if(c){if(g=f.length/a,!t(g))throw new Error(d("0jr0j"))}else if(g=m.length,f.length!==g*a)throw new Error(d("0jr0j"));if(l&&l.length!==g)throw new Error(d("0jr0k"));return f=function(r){var e,t;for(e=[],t=0;t [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0jr5d', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0jr2y', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( '0jr5e', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0jr5f', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0jr5X', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0jr5g', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format('0jr0h') );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format('0jr0i') );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format('0jr0k') );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format('0jr0l') );\n\t\t\t}\n\t\t\tthrow new Error( format('0jr0m') );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( '0jr5h', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( '0jr5i', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format('0jr0n') );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found).\n*\n* ## Notes\n*\n* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types).\n* - The function assumes that `x` is stored in row-major order.\n* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`.\n* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value.\n*\n* @private\n* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension)\n* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension)\n* @param {ArrayLikeObject} x - input two-dimensional reference array\n* @param {integer} strideX1 - `x` stride length along first dimension\n* @param {integer} strideX2 - `x` stride length along second dimension\n* @param {NonNegativeInteger} offsetX - `x` starting index\n* @param {ArrayLikeObject} y - search array\n* @param {integer} strideY - `y` stride length\n* @param {NonNegativeInteger} offsetY - `y` starting index\n* @returns {integer} row index (if found) and `-1` otherwise\n*\n* @example\n* // Define a reference array to search:\n* var types = [\n* 'float64', 'float64', 'float64',\n* 'float32', 'float32', 'float32',\n* 'uint32', 'uint32', 'float64',\n* 'int32', 'int32', 'float64',\n* 'uint16', 'uint16', 'float64',\n* 'int16', 'int16', 'float64',\n* 'uint8', 'uint8', 'float64',\n* 'int8', 'int8', 'float64'\n* ];\n*\n* // Define reference array dimensions:\n* var N = 8; // rows\n* var M = 3; // columns\n*\n* // Define a search array:\n* y1 = [\n* 'float32', 'float32', 'float32',\n* ];\n*\n* // Find the list of types:\n* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 );\n* // returns 1\n*\n// Define a search array:\n* y2 = [\n* 'float32', 'float32', 'float64',\n* ];\n*\n* // Find the list of types:\n* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 );\n* // returns -1\n*/\nfunction indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len\n\tvar ix;\n\tvar iy;\n\tvar i;\n\tvar j;\n\n\t// Search for the first row which matches `y`...\n\tix = offsetX;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tiy = offsetY;\n\t\tfor ( j = 0; j < M; j++ ) {\n\t\t\tif ( x[ ix+(j*strideX2) ] !== y[ iy ] ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tiy += strideY;\n\t\t}\n\t\t// If we successfully iterated over all columns, then that means we've found a match...\n\t\tif ( j === M ) {\n\t\t\treturn i;\n\t\t}\n\t\tix += strideX1;\n\t}\n\treturn -1;\n}\n\n\n// EXPORTS //\n\nexport default indexOfTypes;\n"],"names":["dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","out","i","push","resolveEnum","types2enums","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","getDType","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","j","indexOfTypes","slice"],"mappings":";;0+BA0GA,SAASA,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAO,UAEzB,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAO,UAEzB,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAO,eAIzB,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAO,UAG1B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAO,UAGzB,OADAX,EA5GD,SAAsBA,GACrB,IAAIkB,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAInB,EAAMgB,OAAQG,IAC9BD,EAAIE,KAAMC,EAAarB,EAAOmB,KAE/B,OAAOD,CACR,CAmGSI,CAAatB,GAgBrB,WACC,IAAIuB,EACAC,EACAC,EACAC,EACAC,EACAC,EACAT,EAGJ,GADAM,EAAOI,UAAUb,OACZS,IAASvB,EAAQ,CACrB,GAAKuB,EAAOvB,EACX,MAAM,IAAIa,MAAOJ,EAAO,UAEzB,MAAM,IAAII,MAAOJ,EAAO,SACxB,CAGD,IAFAY,EAAS,GACTC,EAAS,GACHL,EAAI,EAAGA,EAAIjB,EAAOiB,IAAM,CAE7B,IAAMW,EADNH,EAAIE,UAAWV,IAEd,MAAKA,EAAIhB,EACF,IAAIO,UAAWC,EAAQ,QAASgB,IAEhC,IAAIjB,UAAWC,EAAQ,QAASgB,IAGxCJ,EAAOH,KAAMO,GACbH,EAAOJ,KAAMC,EAAaU,EAAUJ,IACpC,CAKD,IAHAD,EC1HF,SAAuBM,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAvB,EACAwB,EAIJ,IADAF,EAAKJ,EACClB,EAAI,EAAGA,EAAIa,EAAGb,IAAM,CAEzB,IADAuB,EAAKF,EACCG,EAAI,EAAGA,EAAIV,GACXC,EAAGO,EAAIE,EAAEP,KAAgBE,EAAGI,GADdC,IAInBD,GAAMH,EAGP,GAAKI,IAAMV,EACV,OAAOd,EAERsB,GAAMN,CACN,CACD,OAAQ,CACT,CDmGQS,CAActC,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGmB,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAId,UAAWC,EAAO,UAI5BiB,EADIrB,GAGAR,EAAM2B,GAGNzB,EACJ2B,EAAGL,EAAQtB,EAAMyB,IAEjBE,EAAGL,GAEJ,GAAc,IAATnB,EACJ,OAAOmB,EAAQlB,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOmB,EAAOsB,MAAO1C,EACrB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 252182f..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From cd26c05b846c0d981095a4fd74116a022e256b9a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 26 May 2025 02:00:12 +0000 Subject: [PATCH 100/109] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 194 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 257 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 61 +- SECURITY.md | 5 - benchmark/benchmark.dispatch_size.js | 156 - benchmark/benchmark.js | 81 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 87 - docs/types/test.ts | 615 --- examples/add.js | 121 - examples/sin.js | 142 - examples/unary.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/index_of_types.js | 106 - lib/main.js | 231 - package.json | 79 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/binary.js | 38 - test/fixtures/fill.js | 76 - test/fixtures/foreach.js | 72 - test/fixtures/map1n.js | 74 - test/fixtures/nullary.js | 36 - test/fixtures/quaternary.js | 40 - test/fixtures/quinary.js | 41 - test/fixtures/sum.js | 98 - test/fixtures/ternary.js | 39 - test/test.js | 363 -- test/test.two_arrays.js | 814 --- 58 files changed, 4876 insertions(+), 7112 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.dispatch_size.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/add.js delete mode 100644 examples/sin.js delete mode 100644 examples/unary.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/index_of_types.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/fixtures/binary.js delete mode 100644 test/fixtures/fill.js delete mode 100644 test/fixtures/foreach.js delete mode 100644 test/fixtures/map1n.js delete mode 100644 test/fixtures/nullary.js delete mode 100644 test/fixtures/quaternary.js delete mode 100644 test/fixtures/quinary.js delete mode 100644 test/fixtures/sum.js delete mode 100644 test/fixtures/ternary.js delete mode 100644 test/test.js delete mode 100644 test/test.two_arrays.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index f53b103..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-05-26T01:18:10.083Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 731bd4f..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/contributing/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 5e92c3e..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2b4fac7..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '43 7 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -304,7 +295,7 @@ console.log( ybuf ); ## 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. +This package is part of [stdlib][stdlib], a standard library 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]. @@ -367,11 +358,11 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-dispatch/main/LICENSE -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.dispatch_size.js b/benchmark/benchmark.dispatch_size.js deleted file mode 100644 index 15805ba..0000000 --- a/benchmark/benchmark.dispatch_size.js +++ /dev/null @@ -1,156 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib/main.js' ); - - -// FUNCTIONS // - -/** -* Evaluates the identity function. -* -* @private -* @param {*} v - value -* @returns {*} input value -*/ -function identity( v ) { - return v; -} - -/** -* Dummy function which throws an error. -* -* @private -* @throws {Error} unexpected error -*/ -function throwError() { - throw new Error( 'unexpected error' ); -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} size - dispatch size -* @returns {Function} benchmark function -*/ -function createBenchmark( size ) { - var types; - var data; - var fcn; - var x; - var y; - var t; - var i; - - types = []; - - // Create dummy types... - for ( i = 0; i < (size-1)*2; i += 2 ) { - t = 'foo' + i; - types.push( t ); - types.push( t ); - } - // Append test types: - types.push( 'float64' ); - types.push( 'float64' ); - - // Define a list of callbacks: - data = []; - for ( i = 0; i < size-1; i++ ) { - data.push( throwError ); - } - // Append a test callback: - data.push( identity ); - - // Create the dispatcher: - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - // Create sample arrays: - x = new Float64Array( 1 ); - y = new Float64Array( x.length ); - - x = ndarray( 'float64', x, [ 1 ], [ 1 ], 0, 'row-major' ); - y = ndarray( 'float64', y, [ 1 ], [ 1 ], 0, 'row-major' ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var z; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x.data[ 0 ] = i; - z = fcn( x, y ); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var size; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - size = pow( 2, i ); - f = createBenchmark( size ); - bench( pkg+':size='+size, f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 3c6f450..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::fcns_array', function benchmark( b ) { - var types; - var fcns; - var data; - var out; - var i; - - fcns = [ unary ]; - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( fcns, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::fcn_arg', function benchmark( b ) { - var types; - var data; - var out; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( unary, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0aae4af..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch" -%% click B href "https://github.com/stdlib-js/ndarray-dispatch/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-dispatch/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-dispatch/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-dispatch/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-dispatch/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch -[production-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 1295a44..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import dispatch from '../docs/types/index'; -export = dispatch; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index c23dc5d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var y=function(i,r){return function(){return r||i((r={exports:{}}).exports,r),r.exports}};var b=y(function(D,w){"use strict";function k(i,r,e,u,f,m,n,o,l){var h,t,s,a;for(h=m,s=0;s [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( 'invalid invocation. Insufficient arguments.' );\n\t\t\t}\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = dispatch;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an ndarray function interface which performs multiple dispatch.\n*\n* @module @stdlib/ndarray-dispatch\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var unary = require( '@stdlib/ndarray-base-unary' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var Float64Array = require( '@stdlib/array-float64' );\n* var dispatch = require( '@stdlib/ndarray-dispatch' );\n*\n* var types = [\n* 'float64', 'float64'\n* ];\n*\n* var data = [\n* abs\n* ];\n*\n* var absolute = dispatch( unary, types, data, 2, 1, 1 );\n*\n* // ...\n*\n* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] );\n* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] );\n*\n* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' );\n* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' );\n*\n* absolute( x, y );\n* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA6EA,SAASC,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,EAAU,CAClF,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,CAAU,IAAME,EAAGI,CAAG,EADjBE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,CACP,CACA,MAAO,EACR,CAKAL,EAAO,QAAUC,ICzGjB,IAAAc,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAoB,QAAS,oCAAqC,EAClEC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAkB,QAAS,kCAAmC,EAC9DC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAc,QAAS,yCAA0C,EACjEC,EAAe,IAYnB,SAASC,EAAaC,EAAQ,CAC7B,IAAIC,EACAC,EAGJ,IADAD,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIF,EAAM,OAAQE,IAC9BD,EAAI,KAAMJ,EAAaG,EAAOE,CAAE,CAAE,CAAE,EAErC,OAAOD,CACR,CAqDA,SAASE,EAAUC,EAAMJ,EAAOK,EAAMC,EAAOC,EAAKC,EAAO,CACxD,IAAIC,EACAC,EACAC,EAEJ,GAAKnB,EAAYY,CAAK,EACrBO,EAAMP,UACK,CAACb,EAAiBa,CAAK,EAClC,MAAM,IAAI,UAAWT,EAAQ,oGAAqGS,CAAK,CAAE,EAE1I,GAAK,CAACX,EAAcO,CAAM,EACzB,MAAM,IAAI,UAAWL,EAAQ,+EAAgFK,CAAM,CAAE,EAEtH,GAAK,CAACP,EAAcY,CAAK,GAAKA,IAAS,KACtC,MAAM,IAAI,UAAWV,EAAQ,sFAAuFU,CAAK,CAAE,EAE5H,GAAK,CAAChB,EAAmBiB,CAAM,EAC9B,MAAM,IAAI,UAAWX,EAAQ,6EAA8EW,CAAM,CAAE,EAEpH,GAAK,CAAClB,EAAsBmB,CAAI,EAC/B,MAAM,IAAI,UAAWZ,EAAQ,+EAAgFY,CAAI,CAAE,EAEpH,GAAK,CAACnB,EAAsBoB,CAAK,EAChC,MAAM,IAAI,UAAWb,EAAQ,+EAAgFa,CAAK,CAAE,EAGrH,GADAC,EAAUF,EAAMC,EACXC,IAAY,EAChB,MAAM,IAAI,MAAO,4IAA6I,EAE/J,GAAKH,IAAUG,EACd,MAAM,IAAI,MAAO,4FAA6F,EAE/G,GAAKE,GAEJ,GADAD,EAAQV,EAAM,OAASS,EAClB,CAACnB,EAAWoB,CAAM,EACtB,MAAM,IAAI,MAAO,8IAA+I,UAGjKA,EAAQN,EAAK,OACRJ,EAAM,SAAWU,EAAMD,EAC3B,MAAM,IAAI,MAAO,8IAA+I,EAGlK,GAAKJ,GAAQA,EAAK,SAAWK,EAC5B,MAAM,IAAI,MAAO,mGAAoG,EAEtH,OAAAV,EAAQD,EAAaC,CAAM,EACpBY,EAeP,SAASA,GAAa,CACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAhB,EAGJ,GADAa,EAAO,UAAU,OACZA,IAAST,EACb,MAAKS,EAAOT,EACL,IAAI,MAAO,6CAA8C,EAE1D,IAAI,MAAO,yCAA0C,EAI5D,IAFAO,EAAS,CAAC,EACVC,EAAS,CAAC,EACJZ,EAAI,EAAGA,EAAII,EAAOJ,IAAM,CAE7B,GADAe,EAAI,UAAWf,CAAE,EACZ,CAACR,EAAeuB,CAAE,EACtB,MAAKf,EAAIK,EACF,IAAI,UAAWZ,EAAQ,6EAA8EsB,CAAE,CAAE,EAEzG,IAAI,UAAWtB,EAAQ,8EAA+EsB,CAAE,CAAE,EAGlHJ,EAAO,KAAMI,CAAE,EACfH,EAAO,KAAMjB,EAAaD,EAAUqB,CAAE,CAAE,CAAE,CAC3C,CAKA,GAHAD,EAAMlB,EAAcY,EAAOD,EAAST,EAAOS,EAAS,EAAG,EAAGK,EAAQ,EAAG,CAAE,EAGlEE,EAAM,EACV,MAAM,IAAI,UAAW,6GAA8G,EAcpI,GAXKL,EACJO,EAAIP,EAEJO,EAAId,EAAMY,CAAI,EAGVX,EACJa,EAAGL,EAAQR,EAAMW,CAAI,CAAE,EAEvBE,EAAGL,CAAO,EAENL,IAAS,EACb,OAAOK,EAAQJ,EAAQ,CAAE,EAE1B,GAAKD,IAAS,EAGd,OAAOK,EAAO,MAAON,CAAI,CAC1B,CACD,CAKApB,EAAO,QAAUgB,IC9KjB,IAAIgB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_index_of_types", "__commonJSMin", "exports", "module", "indexOfTypes", "N", "M", "x", "strideX1", "strideX2", "offsetX", "y", "strideY", "offsetY", "ix", "iy", "i", "j", "require_main", "__commonJSMin", "exports", "module", "isNonNegativeInteger", "isPositiveInteger", "isInteger", "isFunctionArray", "isFunction", "isCollection", "isndarrayLike", "format", "getDType", "resolveEnum", "indexOfTypes", "types2enums", "types", "out", "i", "dispatch", "fcns", "data", "nargs", "nin", "nout", "narrays", "nfcns", "fcn", "dispatcher", "arrays", "dtypes", "argc", "idx", "v", "f", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 02fe150..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,87 +0,0 @@ - -{{alias}}( fcns, types, data, nargs, nin, nout ) - Returns an ndarray function interface which performs multiple dispatch. - - An ndarray function interface has the following signature: - - f( x, y, ... ) - - where - - - x: ndarray. - - y: ndarray. - - ...: additional ndarrays. - - The number of parameters is derived from `nargs`, the number of input - ndarrays is derived from `nin`, and the number of output ndarrays is derived - from `nout`. - - Parameters - ---------- - fcns: Function|ArrayLikeObject - List of ndarray functions. An ndarray function should have the following - signature: - - f( arrays, data ) - - where - - - arrays: array containing input and output ndarrays. - - data: ndarray function data (e.g., a callback). - - For convenience, a single ndarray function may be provided which will be - invoked whenever the ndarray argument data types match a sequence of - types in `types`. Providing a single ndarray function is particularly - convenient for the case where, regardless of array data types, - traversing arrays remains the same, but the ndarray function `data` - differs (e.g., callbacks which differ based on the array data types). - - types: ArrayLikeObject - One-dimensional list of ndarray argument data types. - - data: ArrayLikeObject|null - ndarray function data (e.g., callbacks). If `null`, a returned ndarray - function interface does **not** provide a `data` argument to an invoked - ndarray function. - - nargs: integer - Total number of ndarray function interface arguments. - - nin: integer - Number of input ndarrays. - - nout: integer - Number of output ndarrays. - - Returns - ------- - fcn: Function - ndarray function interface. - - Examples - -------- - // Define ndarray argument data types: - > var t = [ 'float64', 'float64', 'float32', 'float32' ]; - - // Define a list of ndarray function data (callbacks): - > var d = [ {{alias:@stdlib/math/base/special/abs}}, {{alias:@stdlib/math/base/special/absf}} ]; - - // Create an ndarray function interface for applying unary callbacks: - > var f = {{alias}}( {{alias:@stdlib/ndarray/base/unary}}, t, d, 2, 1, 1 ); - - // Create an input ndarray: - > var xbuf = new {{alias:@stdlib/array/float64}}( [ -1.0, -2.0, -3.0, -4.0 ] ); - > var x = {{alias:@stdlib/ndarray/ctor}}( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Create an output ndarray: - > var ybuf = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 0.0, 0.0 ] ); - > var y = {{alias:@stdlib/ndarray/ctor}}( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Compute the element-wise absolute value: - > f( x, y ); - > ybuf - [ 1.0, 2.0, 3.0, 4.0 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 3fece39..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,615 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable max-lines, prefer-const */ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import ind2sub = require( '@stdlib/ndarray-ind2sub' ); -import dispatch = require( './index' ); - - -// FUNCTIONS // - -/** -* Nullary callback. -* -* @returns input value -*/ -function nullary(): any { - return 5.0; -} - -/** -* Unary callback. -* -* @param x - input value -* @returns input value -*/ -function unary( x: any ): any { - return x; -} - -/** -* Binary callback. -* -* @param x - input value -* @param y - input value -* @returns output value -*/ -function binary( x: number, y: number ): number { - return x + y; -} - -/** -* Ternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @returns output value -*/ -function ternary( x: number, y: number, z: number ): number { - return x + y + z; -} - -/** -* Quaternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @param w - input value -* @returns output value -*/ -function quaternary( x: number, y: number, z: number, w: number ): number { - return x + y + z + w; -} - -/** -* Mock ndarray function. -* -* @param arrays - ndarrays -* @param fcn - callback -*/ -function ndarrayFcn( arrays: Array, fcn: ( x: any ) => any ): void { - let xord; - let yord; - let opts; - let sub; - let sh; - let N; - let x; - let y; - let v; - let i; - - x = arrays[ 0 ]; - y = arrays[ 1 ]; - sh = x.shape; - if ( sh.length === 0 ) { - return; - } - N = 1; - for ( i = 0; i < sh.length; i += 1 ) { - N *= sh[ i ]; - } - xord = x.order; - yord = y.order; - opts = { - 'order': xord - }; - for ( i = 0; i < N; i += 1 ) { - // Convert a linear index to subscripts: - opts.order = xord; - sub = ind2sub( sh, i, opts ); - - // Retrieve an element from `x`: - v = x.get.apply( x, sub ); - - // Convert a linear index to subscripts: - opts.order = yord; - sub = ind2sub( sh, i, opts ); - - // Append the result of applying the callback: - sub[ sub.length ] = fcn( v ) as number; - - // Assign the result to an element in `y`: - y.set.apply( y, sub ); - } -} - -/** -* Mock function to create an ndarray-like object. -* -* @returns ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a dispatch function... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, 1 ); // $ExpectType Dispatcher - dispatch( [ ndarrayFcn ], types, data, 2, 1, 1 ); // $ExpectType Dispatcher -} - -// The compiler throws an error if the function is provided a first argument which is not either an ndarray function or an array-like object containing ndarray functions... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( '10', types, data, 2, 1, 1 ); // $ExpectError - dispatch( 10, types, data, 2, 1, 1 ); // $ExpectError - dispatch( true, types, data, 2, 1, 1 ); // $ExpectError - dispatch( false, types, data, 2, 1, 1 ); // $ExpectError - dispatch( null, types, data, 2, 1, 1 ); // $ExpectError - dispatch( undefined, types, data, 2, 1, 1 ); // $ExpectError - dispatch( [ '1' ], types, data, 2, 1, 1 ); // $ExpectError - dispatch( {}, types, data, 2, 1, 1 ); // $ExpectError - dispatch( ( x: number ): number => x, types, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object... -{ - const data = [ unary ]; - - dispatch( ndarrayFcn, 10, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, true, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, false, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, null, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, undefined, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, {}, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object or null... -{ - const types = [ 'float64', 'float64' ]; - - dispatch( ndarrayFcn, types, 10, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, true, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, false, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, undefined, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, {}, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, '10', 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, true, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, false, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, null, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, undefined, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, [ '1' ], 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, {}, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, ( x: number ): number => x, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, '10', 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, true, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, false, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, null, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, undefined, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, [ '1' ], 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, {}, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, ( x: number ): number => x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, '10' ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, true ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, false ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, null ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, undefined ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, [ '1' ] ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, {} ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch(); // $ExpectError - dispatch( ndarrayFcn ); // $ExpectError - dispatch( ndarrayFcn, types ); // $ExpectError - dispatch( ndarrayFcn, types, data ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, 1, 0 ); // $ExpectError -} - -// The function returns a dispatch function... -{ - const x = array(); - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const t1 = [ 'float64' ]; - const d1 = [ nullary ]; - const f1 = dispatch( ndarrayFcn, t1, d1, 1, 1, 0 ); - f1( x ); // $ExpectType void | ndarray - - const t2 = [ 'float64', 'float64' ]; - const d2 = [ unary ]; - const f2 = dispatch( ndarrayFcn, t2, d2, 2, 1, 1 ); - f2( x, y ); // $ExpectType void | ndarray - - const t3 = [ 'float64', 'float64', 'float64' ]; - const d3 = [ binary ]; - const f3 = dispatch( ndarrayFcn, t3, d3, 3, 2, 1 ); - f3( x, y, z ); // $ExpectType void | ndarray - - const t4 = [ 'float64', 'float64', 'float64', 'float64' ]; - const d4 = [ ternary ]; - const f4 = dispatch( ndarrayFcn, t4, d4, 4, 3, 1 ); - f4( x, y, z, w ); // $ExpectType void | ndarray - - const t5 = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const d5 = [ quaternary ]; - const f5 = dispatch( ndarrayFcn, t5, d5, 5, 4, 1 ); - f5( x, y, z, w, u ); // $ExpectType void | ndarray -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (1 ndarray)... -{ - const types = [ 'float64' ]; - const data = [ nullary ]; - - const f = dispatch( ndarrayFcn, types, data, 1, 0, 1 ); - f( '10' ); // $ExpectError - f( 10 ); // $ExpectError - f( true ); // $ExpectError - f( false ); // $ExpectError - f( null ); // $ExpectError - f( undefined ); // $ExpectError - f( [ '1' ] ); // $ExpectError - f( {} ); // $ExpectError - f( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( 10, y ); // $ExpectError - f( '10', y ); // $ExpectError - f( true, y ); // $ExpectError - f( false, y ); // $ExpectError - f( null, y ); // $ExpectError - f( undefined, y ); // $ExpectError - f( [ '1' ], y ); // $ExpectError - f( {}, y ); // $ExpectError - f( ( x: number ): number => x, y ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const x = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( x, 10 ); // $ExpectError - f( x, '10' ); // $ExpectError - f( x, true ); // $ExpectError - f( x, false ); // $ExpectError - f( x, null ); // $ExpectError - f( x, undefined ); // $ExpectError - f( x, [ '1' ] ); // $ExpectError - f( x, {} ); // $ExpectError - f( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( 10, y, z ); // $ExpectError - f( '10', y, z ); // $ExpectError - f( true, y, z ); // $ExpectError - f( false, y, z ); // $ExpectError - f( null, y, z ); // $ExpectError - f( undefined, y, z ); // $ExpectError - f( [ '1' ], y, z ); // $ExpectError - f( {}, y, z ); // $ExpectError - f( ( x: number ): number => x, y, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, 10, z ); // $ExpectError - f( x, '10', z ); // $ExpectError - f( x, true, z ); // $ExpectError - f( x, false, z ); // $ExpectError - f( x, null, z ); // $ExpectError - f( x, undefined, z ); // $ExpectError - f( x, [ '1' ], z ); // $ExpectError - f( x, {}, z ); // $ExpectError - f( x, ( x: number ): number => x, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, y, '10' ); // $ExpectError - f( x, y, true ); // $ExpectError - f( x, y, false ); // $ExpectError - f( x, y, null ); // $ExpectError - f( x, y, undefined ); // $ExpectError - f( x, y, [ '1' ] ); // $ExpectError - f( x, y, {} ); // $ExpectError - f( x, y, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( 10, y, z, w ); // $ExpectError - f( '10', y, z, w ); // $ExpectError - f( true, y, z, w ); // $ExpectError - f( false, y, z, w ); // $ExpectError - f( null, y, z, w ); // $ExpectError - f( undefined, y, z, w ); // $ExpectError - f( [ '1' ], y, z, w ); // $ExpectError - f( {}, y, z, w ); // $ExpectError - f( ( x: number ): number => x, y, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, 10, z, w ); // $ExpectError - f( x, '10', z, w ); // $ExpectError - f( x, true, z, w ); // $ExpectError - f( x, false, z, w ); // $ExpectError - f( x, null, z, w ); // $ExpectError - f( x, undefined, z, w ); // $ExpectError - f( x, [ '1' ], z, w ); // $ExpectError - f( x, {}, z, w ); // $ExpectError - f( x, ( x: number ): number => x, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, 10, w ); // $ExpectError - f( x, y, '10', w ); // $ExpectError - f( x, y, true, w ); // $ExpectError - f( x, y, false, w ); // $ExpectError - f( x, y, null, w ); // $ExpectError - f( x, y, undefined, w ); // $ExpectError - f( x, y, [ '1' ], w ); // $ExpectError - f( x, y, {}, w ); // $ExpectError - f( x, y, ( x: number ): number => x, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, z, 10 ); // $ExpectError - f( x, y, z, '10' ); // $ExpectError - f( x, y, z, true ); // $ExpectError - f( x, y, z, false ); // $ExpectError - f( x, y, z, null ); // $ExpectError - f( x, y, z, undefined ); // $ExpectError - f( x, y, z, [ '1' ] ); // $ExpectError - f( x, y, z, {} ); // $ExpectError - f( x, y, z, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( 10, y, z, w, u ); // $ExpectError - f( '10', y, z, w, u ); // $ExpectError - f( true, y, z, w, u ); // $ExpectError - f( false, y, z, w, u ); // $ExpectError - f( null, y, z, w, u ); // $ExpectError - f( undefined, y, z, w, u ); // $ExpectError - f( [ '1' ], y, z, w, u ); // $ExpectError - f( {}, y, z, w, u ); // $ExpectError - f( ( x: number ): number => x, y, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, 10, z, w, u ); // $ExpectError - f( x, '10', z, w, u ); // $ExpectError - f( x, true, z, w, u ); // $ExpectError - f( x, false, z, w, u ); // $ExpectError - f( x, null, z, w, u ); // $ExpectError - f( x, undefined, z, w, u ); // $ExpectError - f( x, [ '1' ], z, w, u ); // $ExpectError - f( x, {}, z, w, u ); // $ExpectError - f( x, ( x: number ): number => x, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, 10, w, u ); // $ExpectError - f( x, y, '10', w, u ); // $ExpectError - f( x, y, true, w, u ); // $ExpectError - f( x, y, false, w, u ); // $ExpectError - f( x, y, null, w, u ); // $ExpectError - f( x, y, undefined, w, u ); // $ExpectError - f( x, y, [ '1' ], w, u ); // $ExpectError - f( x, y, {}, w, u ); // $ExpectError - f( x, y, ( x: number ): number => x, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, 10, u ); // $ExpectError - f( x, y, z, '10', u ); // $ExpectError - f( x, y, z, true, u ); // $ExpectError - f( x, y, z, false, u ); // $ExpectError - f( x, y, z, null, u ); // $ExpectError - f( x, y, z, undefined, u ); // $ExpectError - f( x, y, z, [ '1' ], u ); // $ExpectError - f( x, y, z, {}, u ); // $ExpectError - f( x, y, z, ( x: number ): number => x, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fifth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, w, 10 ); // $ExpectError - f( x, y, z, w, '10' ); // $ExpectError - f( x, y, z, w, true ); // $ExpectError - f( x, y, z, w, false ); // $ExpectError - f( x, y, z, w, null ); // $ExpectError - f( x, y, z, w, undefined ); // $ExpectError - f( x, y, z, w, [ '1' ] ); // $ExpectError - f( x, y, z, w, {} ); // $ExpectError - f( x, y, z, w, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/add.js b/examples/add.js deleted file mode 100644 index 775b711..0000000 --- a/examples/add.js +++ /dev/null @@ -1,121 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var dispatch = require( './../lib' ); - -function add2( arrays ) { - var opts; - var xo; - var yo; - var zo; - var sx; - var sy; - var sz; - var sh; - var N; - var x; - var y; - var z; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - z = arrays[ 2 ]; - xo = x.order; - yo = y.order; - zo = z.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - opts.order = yo; - sy = ind2sub( sh, i, opts ); - v = x.get.apply( x, sx ) + y.get.apply( y, sy ); - - opts.order = zo; - sz = ind2sub( sh, i, opts ); - sz.push( v ); - z.set.apply( z, sz ); - } -} - -var fcns = [ - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2 -]; - -var types = [ - dtypes.float64, dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.int32, dtypes.int32, - dtypes.uint32, dtypes.uint32, dtypes.uint32, - dtypes.int16, dtypes.int16, dtypes.int16, - dtypes.uint16, dtypes.uint16, dtypes.uint16, - dtypes.int8, dtypes.int8, dtypes.int8, - dtypes.uint8, dtypes.uint8, dtypes.uint8, - dtypes.uint8c, dtypes.uint8c, dtypes.uint8c -]; - -var add = dispatch( fcns, types, null, 3, 2, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var zbuf = new Float64Array( xbuf.length ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var z = ndarray( 'float64', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); - -xbuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -ybuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -zbuf = new Int32Array( xbuf.length ); - -x = ndarray( 'int32', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'int32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -z = ndarray( 'int32', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); diff --git a/examples/sin.js b/examples/sin.js deleted file mode 100644 index 8cd4871..0000000 --- a/examples/sin.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int8Array = require( '@stdlib/array-int8' ); -var sin = require( '@stdlib/math-base-special-sin' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/strided-dtypes' ); -var dispatch = require( './../lib' ); - -function apply( arrays, fcn ) { - var opts; - var xo; - var yo; - var sx; - var sy; - var sh; - var N; - var x; - var y; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - xo = x.order; - yo = y.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - v = fcn( x.get.apply( x, sx ) ); - - opts.order = yo; - sy = ind2sub( sh, i, opts ); - sy.push( v ); - y.set.apply( y, sy ); - } -} - -var fcns = [ - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply -]; - -var types = [ - dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float64, - dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.float64, - dtypes.uint32, dtypes.float64, - dtypes.int16, dtypes.float64, - dtypes.int16, dtypes.float32, - dtypes.uint16, dtypes.float64, - dtypes.uint16, dtypes.float32, - dtypes.int8, dtypes.float64, - dtypes.int8, dtypes.float32, - dtypes.uint8, dtypes.float64, - dtypes.uint8, dtypes.float32, - dtypes.uint8c, dtypes.float64, - dtypes.uint8c, dtypes.float32 -]; - -var data = [ - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin -]; - -var sine = dispatch( fcns, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); - -xbuf = new Int8Array( [ 1, 2, 3, 4, 5 ] ); -ybuf = new Float32Array( xbuf.length ); - -x = ndarray( 'int8', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'float32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); diff --git a/examples/unary.js b/examples/unary.js deleted file mode 100644 index e9c3fb4..0000000 --- a/examples/unary.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -var unary = require( '@stdlib/ndarray-base-unary' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var dispatch = require( './../lib' ); - -var types = [ 'float64', 'float64' ]; - -var data = [ - abs -]; - -var absolute = dispatch( unary, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -absolute( x, y ); -console.log( ybuf ); -// => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 5f280a1..c49a4e4 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..d798c10 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@v0.2.2-esm/index.mjs";function m(m,f,l,p,w,v){var a,g,c;if(i(m))c=m;else if(!s(m))throw new TypeError(d("0jr5d",m));if(!n(f))throw new TypeError(d("0jr2y",f));if(!n(l)&&null!==l)throw new TypeError(d("0jr5e",l));if(!e(p))throw new TypeError(d("0jr5f",p));if(!r(w))throw new TypeError(d("0jr5X",w));if(!r(v))throw new TypeError(d("0jr5g",v));if(0===(a=w+v))throw new Error(d("0jr0h"));if(p!==a)throw new Error(d("0jr0i"));if(c){if(g=f.length/a,!t(g))throw new Error(d("0jr0j"))}else if(g=m.length,f.length!==g*a)throw new Error(d("0jr0j"));if(l&&l.length!==g)throw new Error(d("0jr0k"));return f=function(r){var e,t;for(e=[],t=0;t [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0jr5d', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0jr2y', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( '0jr5e', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0jr5f', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0jr5X', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0jr5g', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format('0jr0h') );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format('0jr0i') );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format('0jr0k') );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format('0jr0l') );\n\t\t\t}\n\t\t\tthrow new Error( format('0jr0m') );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( '0jr5h', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( '0jr5i', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format('0jr0n') );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found).\n*\n* ## Notes\n*\n* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types).\n* - The function assumes that `x` is stored in row-major order.\n* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`.\n* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value.\n*\n* @private\n* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension)\n* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension)\n* @param {ArrayLikeObject} x - input two-dimensional reference array\n* @param {integer} strideX1 - `x` stride length along first dimension\n* @param {integer} strideX2 - `x` stride length along second dimension\n* @param {NonNegativeInteger} offsetX - `x` starting index\n* @param {ArrayLikeObject} y - search array\n* @param {integer} strideY - `y` stride length\n* @param {NonNegativeInteger} offsetY - `y` starting index\n* @returns {integer} row index (if found) and `-1` otherwise\n*\n* @example\n* // Define a reference array to search:\n* var types = [\n* 'float64', 'float64', 'float64',\n* 'float32', 'float32', 'float32',\n* 'uint32', 'uint32', 'float64',\n* 'int32', 'int32', 'float64',\n* 'uint16', 'uint16', 'float64',\n* 'int16', 'int16', 'float64',\n* 'uint8', 'uint8', 'float64',\n* 'int8', 'int8', 'float64'\n* ];\n*\n* // Define reference array dimensions:\n* var N = 8; // rows\n* var M = 3; // columns\n*\n* // Define a search array:\n* y1 = [\n* 'float32', 'float32', 'float32',\n* ];\n*\n* // Find the list of types:\n* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 );\n* // returns 1\n*\n// Define a search array:\n* y2 = [\n* 'float32', 'float32', 'float64',\n* ];\n*\n* // Find the list of types:\n* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 );\n* // returns -1\n*/\nfunction indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len\n\tvar ix;\n\tvar iy;\n\tvar i;\n\tvar j;\n\n\t// Search for the first row which matches `y`...\n\tix = offsetX;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tiy = offsetY;\n\t\tfor ( j = 0; j < M; j++ ) {\n\t\t\tif ( x[ ix+(j*strideX2) ] !== y[ iy ] ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tiy += strideY;\n\t\t}\n\t\t// If we successfully iterated over all columns, then that means we've found a match...\n\t\tif ( j === M ) {\n\t\t\treturn i;\n\t\t}\n\t\tix += strideX1;\n\t}\n\treturn -1;\n}\n\n\n// EXPORTS //\n\nexport default indexOfTypes;\n"],"names":["dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","out","i","push","resolveEnum","types2enums","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","getDType","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","j","indexOfTypes","slice"],"mappings":";;0+BA0GA,SAASA,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAO,UAEzB,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAO,UAEzB,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAO,eAIzB,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAO,UAG1B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAO,UAGzB,OADAX,EA5GD,SAAsBA,GACrB,IAAIkB,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAInB,EAAMgB,OAAQG,IAC9BD,EAAIE,KAAMC,EAAarB,EAAOmB,KAE/B,OAAOD,CACR,CAmGSI,CAAatB,GAgBrB,WACC,IAAIuB,EACAC,EACAC,EACAC,EACAC,EACAC,EACAT,EAGJ,GADAM,EAAOI,UAAUb,OACZS,IAASvB,EAAQ,CACrB,GAAKuB,EAAOvB,EACX,MAAM,IAAIa,MAAOJ,EAAO,UAEzB,MAAM,IAAII,MAAOJ,EAAO,SACxB,CAGD,IAFAY,EAAS,GACTC,EAAS,GACHL,EAAI,EAAGA,EAAIjB,EAAOiB,IAAM,CAE7B,IAAMW,EADNH,EAAIE,UAAWV,IAEd,MAAKA,EAAIhB,EACF,IAAIO,UAAWC,EAAQ,QAASgB,IAEhC,IAAIjB,UAAWC,EAAQ,QAASgB,IAGxCJ,EAAOH,KAAMO,GACbH,EAAOJ,KAAMC,EAAaU,EAAUJ,IACpC,CAKD,IAHAD,EC1HF,SAAuBM,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAvB,EACAwB,EAIJ,IADAF,EAAKJ,EACClB,EAAI,EAAGA,EAAIa,EAAGb,IAAM,CAEzB,IADAuB,EAAKF,EACCG,EAAI,EAAGA,EAAIV,GACXC,EAAGO,EAAIE,EAAEP,KAAgBE,EAAGI,GADdC,IAInBD,GAAMH,EAGP,GAAKI,IAAMV,EACV,OAAOd,EAERsB,GAAMN,CACN,CACD,OAAQ,CACT,CDmGQS,CAActC,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGmB,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAId,UAAWC,EAAO,UAI5BiB,EADIrB,GAGAR,EAAM2B,GAGNzB,EACJ2B,EAAGL,EAAQtB,EAAMyB,IAEjBE,EAAGL,GAEJ,GAAc,IAATnB,EACJ,OAAOmB,EAAQlB,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOmB,EAAOsB,MAAO1C,EACrB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 88f0e3e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Create an ndarray function interface which performs multiple dispatch. -* -* @module @stdlib/ndarray-dispatch -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var dispatch = require( '@stdlib/ndarray-dispatch' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/index_of_types.js b/lib/index_of_types.js deleted file mode 100644 index fda2297..0000000 --- a/lib/index_of_types.js +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found). -* -* ## Notes -* -* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types). -* - The function assumes that `x` is stored in row-major order. -* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`. -* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value. -* -* @private -* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension) -* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension) -* @param {ArrayLikeObject} x - input two-dimensional reference array -* @param {integer} strideX1 - `x` stride length along first dimension -* @param {integer} strideX2 - `x` stride length along second dimension -* @param {NonNegativeInteger} offsetX - `x` starting index -* @param {ArrayLikeObject} y - search array -* @param {integer} strideY - `y` stride length -* @param {NonNegativeInteger} offsetY - `y` starting index -* @returns {integer} row index (if found) and `-1` otherwise -* -* @example -* // Define a reference array to search: -* var types = [ -* 'float64', 'float64', 'float64', -* 'float32', 'float32', 'float32', -* 'uint32', 'uint32', 'float64', -* 'int32', 'int32', 'float64', -* 'uint16', 'uint16', 'float64', -* 'int16', 'int16', 'float64', -* 'uint8', 'uint8', 'float64', -* 'int8', 'int8', 'float64' -* ]; -* -* // Define reference array dimensions: -* var N = 8; // rows -* var M = 3; // columns -* -* // Define a search array: -* y1 = [ -* 'float32', 'float32', 'float32', -* ]; -* -* // Find the list of types: -* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 ); -* // returns 1 -* -// Define a search array: -* y2 = [ -* 'float32', 'float32', 'float64', -* ]; -* -* // Find the list of types: -* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 ); -* // returns -1 -*/ -function indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len - var ix; - var iy; - var i; - var j; - - // Search for the first row which matches `y`... - ix = offsetX; - for ( i = 0; i < N; i++ ) { - iy = offsetY; - for ( j = 0; j < M; j++ ) { - if ( x[ ix+(j*strideX2) ] !== y[ iy ] ) { - break; - } - iy += strideY; - } - // If we successfully iterated over all columns, then that means we've found a match... - if ( j === M ) { - return i; - } - ix += strideX1; - } - return -1; -} - - -// EXPORTS // - -module.exports = indexOfTypes; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 4648598..0000000 --- a/lib/main.js +++ /dev/null @@ -1,231 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isFunctionArray = require( '@stdlib/assert-is-function-array' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var resolveEnum = require( '@stdlib/ndarray-base-dtype-resolve-enum' ); -var indexOfTypes = require( './index_of_types.js' ); - - -// FUNCTIONS // - -/** -* Returns a list of data type enumeration constants. -* -* @private -* @param {Collection} types - list of types -* @returns {IntegerArray} list of data type enumeration constants -*/ -function types2enums( types ) { - var out; - var i; - - out = []; - for ( i = 0; i < types.length; i++ ) { - out.push( resolveEnum( types[ i ] ) ); - } - return out; -} - - -// MAIN // - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param {(FunctionArray|Function)} fcns - list of ndarray functions -* @param {Collection} types - one-dimensional list of ndarray argument data types -* @param {(Collection|null)} data - ndarray function data (e.g., callbacks) -* @param {PositiveInteger} nargs - total number of ndarray function interface arguments -* @param {NonNegativeInteger} nin - number of input ndarrays -* @param {NonNegativeInteger} nout - number of output ndarrays -* @throws {TypeError} first argument must be either a function or an array of functions -* @throws {TypeError} second argument must be an array-like object -* @throws {TypeError} third argument must be an array-like object or `null` -* @throws {Error} third and first arguments must have the same number of elements -* @throws {TypeError} fourth argument must be a positive integer -* @throws {TypeError} fifth argument must be a nonnegative integer -* @throws {TypeError} sixth argument must be a nonnegative integer -* @throws {Error} fourth argument must equal the specified number of input and output arrays -* @throws {Error} number of types must match the number of functions times the total number of array arguments for each function -* @throws {Error} interface must accept at least one input and/or output ndarray -* @returns {Function} ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function dispatch( fcns, types, data, nargs, nin, nout ) { - var narrays; - var nfcns; - var fcn; - - if ( isFunction( fcns ) ) { - fcn = fcns; - } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( '0jr5d', fcns ) ); - } - if ( !isCollection( types ) ) { - throw new TypeError( format( '0jr2y', types ) ); - } - if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( '0jr5e', data ) ); - } - if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( '0jr5f', nargs ) ); - } - if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( '0jr5X', nin ) ); - } - if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( '0jr5g', nout ) ); - } - narrays = nin + nout; - if ( narrays === 0 ) { - throw new Error( format('0jr0h') ); - } - if ( nargs !== narrays ) { - throw new Error( format('0jr0i') ); - } - if ( fcn ) { - nfcns = types.length / narrays; - if ( !isInteger( nfcns ) ) { - throw new Error( format('0jr0j') ); - } - } else { - nfcns = fcns.length; - if ( types.length !== nfcns*narrays ) { - throw new Error( format('0jr0j') ); - } - } - if ( data && data.length !== nfcns ) { - throw new Error( format('0jr0k') ); - } - types = types2enums( types ); - return dispatcher; - - /** - * ndarray function interface which performs multiple dispatch. - * - * @private - * @param {ndarrayLike} x - ndarray - * @param {...ndarrayLike} args - ndarray arguments - * @throws {Error} insufficient arguments - * @throws {Error} too many arguments - * @throws {TypeError} input array arguments must be ndarray-like objects - * @throws {TypeError} output array arguments must be ndarray-like objects - * @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types - * @returns {(ndarrayLike|Array|void)} destination array(s) - */ - function dispatcher() { - var arrays; - var dtypes; - var argc; - var idx; - var v; - var f; - var i; - - argc = arguments.length; - if ( argc !== nargs ) { - if ( argc < nargs ) { - throw new Error( format('0jr0l') ); - } - throw new Error( format('0jr0m') ); - } - arrays = []; - dtypes = []; - for ( i = 0; i < nargs; i++ ) { - v = arguments[ i ]; - if ( !isndarrayLike( v ) ) { - if ( i < nin ) { - throw new TypeError( format( '0jr5h', v ) ); - } else { - throw new TypeError( format( '0jr5i', v ) ); - } - } - arrays.push( v ); - dtypes.push( resolveEnum( getDType( v ) ) ); - } - // Resolve the ndarray function satisfying the input array types: - idx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len - - // Check whether we were able to successfully resolve an ndarray function: - if ( idx < 0 ) { - throw new TypeError( format('0jr0n') ); - } - // Retrieve the ndarray function: - if ( fcn ) { - f = fcn; - } else { - f = fcns[ idx ]; - } - // Evaluate the ndarray function: - if ( data ) { - f( arrays, data[ idx ] ); - } else { - f( arrays ); - } - if ( nout === 1 ) { - return arrays[ narrays-1 ]; - } - if ( nout === 0 ) { - return; - } - return arrays.slice( nin ); - } -} - - -// EXPORTS // - -module.exports = dispatch; diff --git a/package.json b/package.json index 5f84ca4..e6c8bad 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Create an ndarray function interface which performs multiple dispatch.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,57 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-function-array": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer": "^0.2.2", - "@stdlib/assert-is-positive-integer": "^0.2.2", - "@stdlib/ndarray-base-dtype-resolve-enum": "^0.2.2", - "@stdlib/ndarray-dtype": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.2.2", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/array-int8": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/math-base-assert-is-nan": "^0.2.2", - "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/math-base-special-pow": "^0.3.0", - "@stdlib/math-base-special-sin": "^0.3.0", - "@stdlib/ndarray-base-buffer-dtype": "^0.3.0", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-unary": "^0.2.1", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-dtypes": "^0.3.0", - "@stdlib/ndarray-ind2sub": "^0.2.2", - "@stdlib/strided-dtypes": "^0.3.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "ndarray", @@ -100,7 +26,6 @@ "multimethod", "multimethods" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..252182f --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/fixtures/binary.js b/test/fixtures/binary.js deleted file mode 100644 index a60dfa2..0000000 --- a/test/fixtures/binary.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Binary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @returns {number} sum -*/ -function binary( x, y ) { - return x + y; -} - - -// EXPORTS // - -module.exports = binary; diff --git a/test/fixtures/fill.js b/test/fixtures/fill.js deleted file mode 100644 index 41b2958..0000000 --- a/test/fixtures/fill.js +++ /dev/null @@ -1,76 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which fills one or more ndarrays. -* -* @private -* @param {*} value - fill value -* @returns {Function} ndarray function -*/ -function fill( value ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - */ - function ndarrayFcn( arrays ) { - var opts; - var sub; - var arr; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - opts = { - 'order': '' - }; - for ( j = 0; j < M; j++ ) { - arr = arrays[ j ]; - opts.order = arrays[ j ].order; - for ( i = 0; i < N; i++ ) { - sub = ind2sub( sh, i, opts ); - sub.push( value ); - arr.set.apply( arr, sub ); - } - } - } -} - - -// EXPORTS // - -module.exports = fill; diff --git a/test/fixtures/foreach.js b/test/fixtures/foreach.js deleted file mode 100644 index a426290..0000000 --- a/test/fixtures/foreach.js +++ /dev/null @@ -1,72 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function forEach( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - fcn.apply( null, args ); - } -} - - -// EXPORTS // - -module.exports = forEach; diff --git a/test/fixtures/map1n.js b/test/fixtures/map1n.js deleted file mode 100644 index 614196b..0000000 --- a/test/fixtures/map1n.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function which maps the return value of a callback to `N` arrays. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function map1N( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var v; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - v = fcn(); - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - sub.push( v ); - arrays[ j ].set.apply( arrays[ j ], sub ); - } - } -} - - -// EXPORTS // - -module.exports = map1N; diff --git a/test/fixtures/nullary.js b/test/fixtures/nullary.js deleted file mode 100644 index 4f22126..0000000 --- a/test/fixtures/nullary.js +++ /dev/null @@ -1,36 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Nullary callback. -* -* @private -* @returns {number} value -*/ -function nullary() { - return 3.0; -} - - -// EXPORTS // - -module.exports = nullary; diff --git a/test/fixtures/quaternary.js b/test/fixtures/quaternary.js deleted file mode 100644 index 548437b..0000000 --- a/test/fixtures/quaternary.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quaternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @returns {number} sum -*/ -function quaternary( x, y, z, w ) { - return x + y + z + w; -} - - -// EXPORTS // - -module.exports = quaternary; diff --git a/test/fixtures/quinary.js b/test/fixtures/quinary.js deleted file mode 100644 index 36068de..0000000 --- a/test/fixtures/quinary.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quinary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @param {number} u - input value -* @returns {number} sum -*/ -function quinary( x, y, z, w, u ) { - return x + y + z + w + u; -} - - -// EXPORTS // - -module.exports = quinary; diff --git a/test/fixtures/sum.js b/test/fixtures/sum.js deleted file mode 100644 index efdbb1b..0000000 --- a/test/fixtures/sum.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which computes the sum across one or more ndarrays. -* -* @private -* @param {Object} ctx - context -* @param {number} ctx.sum - initial sum -* @returns {Function} ndarray function -*/ -function wrapper( ctx ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - * @param {Function} [fcn] - callback - */ - function ndarrayFcn( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var f; - var i; - var j; - - if ( arguments.length > 1 ) { - f = fcn; - } - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - if ( f ) { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - ctx.sum += f.apply( null, args ); - } - } else { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - ctx.sum += arrays[ j ].get.apply( arrays[ j ], sub ); - } - } - } - } -} - - -// EXPORTS // - -module.exports = wrapper; diff --git a/test/fixtures/ternary.js b/test/fixtures/ternary.js deleted file mode 100644 index 0595d5f..0000000 --- a/test/fixtures/ternary.js +++ /dev/null @@ -1,39 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Ternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @returns {number} sum -*/ -function ternary( x, y, z ) { - return x + y + z; -} - - -// EXPORTS // - -module.exports = ternary; diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d6c2c8e..0000000 --- a/test/test.js +++ /dev/null @@ -1,363 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var fill = require( './fixtures/fill.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either a function or an array of functions as a first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( value, types, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object as a second argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided either an array-like object or `null` as a third argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - dispatch( unary, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a positive integer for a fourth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 0, - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a fifth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, value, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a sixth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, 1, value ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function array)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var fcns = [ unary, unary, unary ]; - var data = [ abs, abs, abs ]; - dispatch( fcns, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function argument)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs, abs, abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the length of `data` argument does not match the number of ndarray functions', function test( t ) { - var values; - var i; - - values = [ - [], - [ abs, abs ], - [ abs, abs, abs ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var fcns = [ unary ]; - dispatch( fcns, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the fourth argument is incompatible with the number of input and output ndarrays', function test( t ) { - var values; - var i; - - values = [ - 0, - 1, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of specified input and output ndarrays is zero', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var types = [ 'float64' ]; - dispatch( fill( 3 ), types, null, 1, 0, 0 ); - } -}); - -tape( 'the function returns an ndarray function interface', function test( t ) { - var types; - var data; - var f; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - f = dispatch( unary, types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ unary ], types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( fill( 3 ), types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ fill( 3 ) ], types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.two_arrays.js b/test/test.two_arrays.js deleted file mode 100644 index 16eb61b..0000000 --- a/test/test.two_arrays.js +++ /dev/null @@ -1,814 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var dtype = require( '@stdlib/ndarray-base-buffer-dtype' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var forEach = require( './fixtures/foreach.js' ); -var map1N = require( './fixtures/map1n.js' ); -var fill = require( './fixtures/fill.js' ); -var sum = require( './fixtures/sum.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the first argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var ybuf = new Float64Array( 10 ); - var y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( value, y ); - }; - } -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the second argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var xbuf = new Float64Array( 10 ); - var x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( x, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided insufficient arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var f; - var x; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [], - [ x ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided too many arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var ybuf; - var f; - var x; - var y; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [ x, y, y ], - [ x, y, y, y ], - [ x, y, y, y, y ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if unable to resolve a ndarray function supporting the provided array argument data types', function test( t ) { - var values; - var types; - var data; - var xbuf; - var fcn; - var x; - var i; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ abs, abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 4 ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - values = [ - new Uint8Array( 4 ), - new Int32Array( 4 ), - [ 0, 0, 0, 0 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided an array having data type: ' + dtype( values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var y = ndarray( dtype( value ), value, [ value.length ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - }; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only input arrays)', function test( t ) { - var types; - var xbuf; - var ybuf; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only output arrays)', function test( t ) { - var expected; - var types; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only input arrays)', function test( t ) { - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var ctx; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcns = [ - sum( ctx ), - sum( ctx ) - ]; - fcn = dispatch( fcns, types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only output arrays)', function test( t ) { - var expected; - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcns = [ - fill( 3.0 ), - fill( 4.0 ) - ]; - fcn = dispatch( fcns, types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - - fcn = dispatch( forEach, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - - fcn = dispatch( map1N, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - fcns = [ - forEach, - forEach - ]; - fcn = dispatch( fcns, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - fcns = [ - map1N, - map1N - ]; - fcn = dispatch( fcns, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - fcns = [ - unary, - unary - ]; - fcn = dispatch( fcns, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which returns one or more output arrays, if one or more output arrays is specified, and otherwise returns `undefined`', function test( t ) { - var types; - var data; - var xbuf; - var ybuf; - var out; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - // No output arrays... - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, void 0, 'returns expected value' ); - - // One output array... - data = [ - abs, - abs - ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - fcn = dispatch( fill( 3.0 ), types, null, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - // Two output arrays... - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.end(); -}); From b5c3727743f1204ed96d36b83d9994b3a4375b64 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 14 Sep 2025 06:40:23 +0000 Subject: [PATCH 101/109] Transform error messages --- lib/main.js | 34 +++++++++++++++++----------------- package.json | 2 +- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/main.js b/lib/main.js index 84d6a24..0892b4a 100644 --- a/lib/main.js +++ b/lib/main.js @@ -27,7 +27,7 @@ var isFunctionArray = require( '@stdlib/assert-is-function-array' ); var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var getDType = require( '@stdlib/ndarray-dtype' ); var resolveEnum = require( '@stdlib/ndarray-base-dtype-resolve-enum' ); var dtypes2enums = require( '@stdlib/ndarray-base-dtypes2enums' ); @@ -92,43 +92,43 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { if ( isFunction( fcns ) ) { fcn = fcns; } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) ); + throw new TypeError( format( '0jr5d', fcns ) ); } if ( !isCollection( types ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) ); + throw new TypeError( format( '0jr2y', types ) ); } if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); + throw new TypeError( format( '0jr5e', data ) ); } if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) ); + throw new TypeError( format( '0jr5f', nargs ) ); } if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) ); + throw new TypeError( format( '0jr5X', nin ) ); } if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) ); + throw new TypeError( format( '0jr5g', nout ) ); } narrays = nin + nout; if ( narrays === 0 ) { - throw new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' ); + throw new Error( format('0jr0h') ); } if ( nargs !== narrays ) { - throw new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' ); + throw new Error( format('0jr0i') ); } if ( fcn ) { nfcns = types.length / narrays; if ( !isInteger( nfcns ) ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format('0jr0j') ); } } else { nfcns = fcns.length; if ( types.length !== nfcns*narrays ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format('0jr0j') ); } } if ( data && data.length !== nfcns ) { - throw new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' ); + throw new Error( format('0jr0k') ); } types = dtypes2enums( types ); return dispatcher; @@ -158,9 +158,9 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { argc = arguments.length; if ( argc !== nargs ) { if ( argc < nargs ) { - throw new Error( 'invalid invocation. Insufficient arguments.' ); + throw new Error( format('0jr0l') ); } - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('0jr0m') ); } arrays = []; dtypes = []; @@ -168,9 +168,9 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { v = arguments[ i ]; if ( !isndarrayLike( v ) ) { if ( i < nin ) { - throw new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) ); + throw new TypeError( format( '0jr5h', v ) ); } else { - throw new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) ); + throw new TypeError( format( '0jr5i', v ) ); } } arrays.push( v ); @@ -181,7 +181,7 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { // Check whether we were able to successfully resolve an ndarray function: if ( idx < 0 ) { - throw new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' ); + throw new TypeError( format('0jr0n') ); } // Retrieve the ndarray function: if ( fcn ) { diff --git a/package.json b/package.json index ef6cbae..240c09f 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@stdlib/ndarray-base-dtype-resolve-enum": "^0.2.2", "@stdlib/ndarray-base-dtypes2enums": "github:stdlib-js/ndarray-base-dtypes2enums#main", "@stdlib/ndarray-dtype": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 7550d4b5e45e2d4f67478bdbf658fd3095c27c1f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 14 Sep 2025 06:41:07 +0000 Subject: [PATCH 102/109] Remove files --- index.d.ts | 334 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5181 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index c49a4e4..0000000 --- a/index.d.ts +++ /dev/null @@ -1,334 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* ndarray function. -* -* @param arrays - array containing input and output ndarrays -* @param data - ndarray function data (e.g., a callback) -* -* @example -* var numel = require( '@stdlib/ndarray-base-numel' ); -* var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -* -* function ndarrayFcn( arrays, fcn ) { -* var xord; -* var yord; -* var opts; -* var sub; -* var sh; -* var N; -* var x; -* var y; -* var v; -* var i; -* -* x = arrays[ 0 ]; -* y = arrays[ 1 ]; -* sh = x.shape; -* N = numel( sh ); -* if ( N <= 0 ) { -* return; -* } -* xord = x.order; -* yord = y.order; -* opts = {}; -* opts.order = xord; -* for ( i = 0; i < N; i++ ) { -* // Convert a linear index to subscripts: -* opts.order = xord; -* sub = ind2sub( sh, i, opts ); -* -* // Retrieve an element from `x`: -* v = x.get.apply( x, sub ); -* -* // Convert a linear index to subscripts: -* opts.order = yord; -* sub = ind2sub( sh, i, opts ); -* -* // Append the result of applying the callback: -* sub.push( fcn( v ) ); -* -* // Assign the result to an element in `y`: -* y.set.apply( y, sub ); -* } -* } -*/ -type ndarrayFcn = ( arrays: Array, data?: any ) => void; - -/** -* Interface describing an ndarray function dispatcher. -*/ -interface Dispatcher { - /** - * Invokes an ndarray function based on the provided array data type(s). - * - * @param x - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array - * - * @example - * var nullary = require( '@stdlib/ndarray-base-nullary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function value() { - * return 3.14; - * } - * - * var types = [ 'float64' ]; - * var data = [ value ]; - * - * var fcn = dispatch( nullary, types, data, 1, 0, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( 5 ); - * var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x ); - * // xbuf => [ 3.14, 3.14, 3.14, 3.14, 3.14 ] - */ - ( x: ndarray ): ndarray | void; - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var unary = require( '@stdlib/ndarray-base-unary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * var abs = require( '@stdlib/math-base-special-abs' ); - * - * var types = [ 'float64', 'float64' ]; - * var data = [ abs ]; - * - * var fcn = dispatch( unary, types, data, 2, 1, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - * var ybuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y ); - * // ybuf => [ 1.0, 2.0, 3.0 ] - */ - ( x: ndarray, y: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var ternary = require( '@stdlib/ndarray-base-ternary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function add2( x, y ) { - * return x + y; - * } - * - * var types = [ 'float64', 'float64', 'float64' ]; - * var data = [ add2 ]; - * - * var fcn = dispatch( ternary, types, data, 3, 2, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z ); - * // zbuf => [ 2.0, 4.0, 6.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quaternary = require( '@stdlib/ndarray-base-quaternary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function add3( x, y, z ) { - * return x + y + z; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add3 ]; - * - * var fcn = dispatch( quaternary, types, data, 4, 3, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w ); - * // wbuf => [ 3.0, 6.0, 9.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @param args - ndarray arguments - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quinary = require( '@stdlib/ndarray-base-quinary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function add4( x, y, z, w ) { - * return x + y + z + w; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add4 ]; - * - * var fcn = dispatch( quinary, types, data, 5, 4, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ubuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var u = ndarray( 'float64', ubuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w, u ); - * // ubuf => [ 4.0, 8.0, 12.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray, ...args: Array ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures -} - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param fcns - list of ndarray functions -* @param types - one-dimensional list of ndarray argument data types -* @param data - ndarray function data (e.g., callbacks) -* @param nargs - total number of ndarray function interface arguments -* @param nin - number of input ndarrays -* @param nout - number of output ndarrays -* @throws first argument must be either a function or an array of functions -* @throws second argument must be an array-like object -* @throws third argument must be an array-like object or `null` -* @throws third and first arguments must have the same number of elements -* @throws fourth argument must be a positive integer -* @throws fifth argument must be a nonnegative integer -* @throws sixth argument must be a nonnegative integer -* @throws fourth argument must equal the specified number of input and output arrays -* @throws number of types must match the number of functions times the total number of array arguments for each function -* @throws interface must accept at least one input and/or output ndarray -* @returns ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var fcn = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* fcn( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function dispatch( fcns: ndarrayFcn | ArrayLike, types: ArrayLike, data: ArrayLike | null, nargs: number, nin: number, nout: number ): Dispatcher; - - -// EXPORTS // - -export = dispatch; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index d798c10..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@v0.2.2-esm/index.mjs";function m(m,f,l,p,w,v){var a,g,c;if(i(m))c=m;else if(!s(m))throw new TypeError(d("0jr5d",m));if(!n(f))throw new TypeError(d("0jr2y",f));if(!n(l)&&null!==l)throw new TypeError(d("0jr5e",l));if(!e(p))throw new TypeError(d("0jr5f",p));if(!r(w))throw new TypeError(d("0jr5X",w));if(!r(v))throw new TypeError(d("0jr5g",v));if(0===(a=w+v))throw new Error(d("0jr0h"));if(p!==a)throw new Error(d("0jr0i"));if(c){if(g=f.length/a,!t(g))throw new Error(d("0jr0j"))}else if(g=m.length,f.length!==g*a)throw new Error(d("0jr0j"));if(l&&l.length!==g)throw new Error(d("0jr0k"));return f=function(r){var e,t;for(e=[],t=0;t [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0jr5d', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0jr2y', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( '0jr5e', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0jr5f', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0jr5X', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0jr5g', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format('0jr0h') );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format('0jr0i') );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format('0jr0k') );\n\t}\n\ttypes = types2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format('0jr0l') );\n\t\t\t}\n\t\t\tthrow new Error( format('0jr0m') );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( '0jr5h', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( '0jr5i', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format('0jr0n') );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found).\n*\n* ## Notes\n*\n* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types).\n* - The function assumes that `x` is stored in row-major order.\n* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`.\n* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value.\n*\n* @private\n* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension)\n* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension)\n* @param {ArrayLikeObject} x - input two-dimensional reference array\n* @param {integer} strideX1 - `x` stride length along first dimension\n* @param {integer} strideX2 - `x` stride length along second dimension\n* @param {NonNegativeInteger} offsetX - `x` starting index\n* @param {ArrayLikeObject} y - search array\n* @param {integer} strideY - `y` stride length\n* @param {NonNegativeInteger} offsetY - `y` starting index\n* @returns {integer} row index (if found) and `-1` otherwise\n*\n* @example\n* // Define a reference array to search:\n* var types = [\n* 'float64', 'float64', 'float64',\n* 'float32', 'float32', 'float32',\n* 'uint32', 'uint32', 'float64',\n* 'int32', 'int32', 'float64',\n* 'uint16', 'uint16', 'float64',\n* 'int16', 'int16', 'float64',\n* 'uint8', 'uint8', 'float64',\n* 'int8', 'int8', 'float64'\n* ];\n*\n* // Define reference array dimensions:\n* var N = 8; // rows\n* var M = 3; // columns\n*\n* // Define a search array:\n* y1 = [\n* 'float32', 'float32', 'float32',\n* ];\n*\n* // Find the list of types:\n* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 );\n* // returns 1\n*\n// Define a search array:\n* y2 = [\n* 'float32', 'float32', 'float64',\n* ];\n*\n* // Find the list of types:\n* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 );\n* // returns -1\n*/\nfunction indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len\n\tvar ix;\n\tvar iy;\n\tvar i;\n\tvar j;\n\n\t// Search for the first row which matches `y`...\n\tix = offsetX;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tiy = offsetY;\n\t\tfor ( j = 0; j < M; j++ ) {\n\t\t\tif ( x[ ix+(j*strideX2) ] !== y[ iy ] ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tiy += strideY;\n\t\t}\n\t\t// If we successfully iterated over all columns, then that means we've found a match...\n\t\tif ( j === M ) {\n\t\t\treturn i;\n\t\t}\n\t\tix += strideX1;\n\t}\n\treturn -1;\n}\n\n\n// EXPORTS //\n\nexport default indexOfTypes;\n"],"names":["dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","out","i","push","resolveEnum","types2enums","arrays","dtypes","argc","idx","v","f","arguments","isndarrayLike","getDType","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","j","indexOfTypes","slice"],"mappings":";;0+BA0GA,SAASA,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAO,UAEzB,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAO,UAEzB,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAO,eAIzB,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAO,UAG1B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAO,UAGzB,OADAX,EA5GD,SAAsBA,GACrB,IAAIkB,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAInB,EAAMgB,OAAQG,IAC9BD,EAAIE,KAAMC,EAAarB,EAAOmB,KAE/B,OAAOD,CACR,CAmGSI,CAAatB,GAgBrB,WACC,IAAIuB,EACAC,EACAC,EACAC,EACAC,EACAC,EACAT,EAGJ,GADAM,EAAOI,UAAUb,OACZS,IAASvB,EAAQ,CACrB,GAAKuB,EAAOvB,EACX,MAAM,IAAIa,MAAOJ,EAAO,UAEzB,MAAM,IAAII,MAAOJ,EAAO,SACxB,CAGD,IAFAY,EAAS,GACTC,EAAS,GACHL,EAAI,EAAGA,EAAIjB,EAAOiB,IAAM,CAE7B,IAAMW,EADNH,EAAIE,UAAWV,IAEd,MAAKA,EAAIhB,EACF,IAAIO,UAAWC,EAAQ,QAASgB,IAEhC,IAAIjB,UAAWC,EAAQ,QAASgB,IAGxCJ,EAAOH,KAAMO,GACbH,EAAOJ,KAAMC,EAAaU,EAAUJ,IACpC,CAKD,IAHAD,EC1HF,SAAuBM,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAvB,EACAwB,EAIJ,IADAF,EAAKJ,EACClB,EAAI,EAAGA,EAAIa,EAAGb,IAAM,CAEzB,IADAuB,EAAKF,EACCG,EAAI,EAAGA,EAAIV,GACXC,EAAGO,EAAIE,EAAEP,KAAgBE,EAAGI,GADdC,IAInBD,GAAMH,EAGP,GAAKI,IAAMV,EACV,OAAOd,EAERsB,GAAMN,CACN,CACD,OAAQ,CACT,CDmGQS,CAActC,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGmB,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAId,UAAWC,EAAO,UAI5BiB,EADIrB,GAGAR,EAAM2B,GAGNzB,EACJ2B,EAAGL,EAAQtB,EAAMyB,IAEjBE,EAAGL,GAEJ,GAAc,IAATnB,EACJ,OAAOmB,EAAQlB,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOmB,EAAOsB,MAAO1C,EACrB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 252182f..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From fc7096295664870337691e97e5fd78d30bb34ae4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 14 Sep 2025 06:41:38 +0000 Subject: [PATCH 103/109] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 199 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 258 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 61 +- SECURITY.md | 5 - benchmark/benchmark.dispatch_size.js | 156 - benchmark/benchmark.js | 81 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 87 - docs/types/test.ts | 615 --- examples/add.js | 121 - examples/sin.js | 142 - examples/unary.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/index_of_types.js | 106 - lib/main.js | 211 - package.json | 80 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/binary.js | 38 - test/fixtures/fill.js | 76 - test/fixtures/foreach.js | 72 - test/fixtures/map1n.js | 74 - test/fixtures/nullary.js | 36 - test/fixtures/quaternary.js | 40 - test/fixtures/quinary.js | 41 - test/fixtures/sum.js | 98 - test/fixtures/ternary.js | 39 - test/test.js | 363 -- test/test.two_arrays.js | 814 --- 57 files changed, 4876 insertions(+), 7098 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.dispatch_size.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/add.js delete mode 100644 examples/sin.js delete mode 100644 examples/unary.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/index_of_types.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/fixtures/binary.js delete mode 100644 test/fixtures/fill.js delete mode 100644 test/fixtures/foreach.js delete mode 100644 test/fixtures/map1n.js delete mode 100644 test/fixtures/nullary.js delete mode 100644 test/fixtures/quaternary.js delete mode 100644 test/fixtures/quinary.js delete mode 100644 test/fixtures/sum.js delete mode 100644 test/fixtures/ternary.js delete mode 100644 test/test.js delete mode 100644 test/test.two_arrays.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 731bd4f..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/contributing/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 5e92c3e..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2b4fac7..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '43 7 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -304,7 +295,7 @@ console.log( ybuf ); ## 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. +This package is part of [stdlib][stdlib], a standard library 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]. @@ -367,11 +358,11 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-dispatch/main/LICENSE -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.dispatch_size.js b/benchmark/benchmark.dispatch_size.js deleted file mode 100644 index 15805ba..0000000 --- a/benchmark/benchmark.dispatch_size.js +++ /dev/null @@ -1,156 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib/main.js' ); - - -// FUNCTIONS // - -/** -* Evaluates the identity function. -* -* @private -* @param {*} v - value -* @returns {*} input value -*/ -function identity( v ) { - return v; -} - -/** -* Dummy function which throws an error. -* -* @private -* @throws {Error} unexpected error -*/ -function throwError() { - throw new Error( 'unexpected error' ); -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} size - dispatch size -* @returns {Function} benchmark function -*/ -function createBenchmark( size ) { - var types; - var data; - var fcn; - var x; - var y; - var t; - var i; - - types = []; - - // Create dummy types... - for ( i = 0; i < (size-1)*2; i += 2 ) { - t = 'foo' + i; - types.push( t ); - types.push( t ); - } - // Append test types: - types.push( 'float64' ); - types.push( 'float64' ); - - // Define a list of callbacks: - data = []; - for ( i = 0; i < size-1; i++ ) { - data.push( throwError ); - } - // Append a test callback: - data.push( identity ); - - // Create the dispatcher: - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - // Create sample arrays: - x = new Float64Array( 1 ); - y = new Float64Array( x.length ); - - x = ndarray( 'float64', x, [ 1 ], [ 1 ], 0, 'row-major' ); - y = ndarray( 'float64', y, [ 1 ], [ 1 ], 0, 'row-major' ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var z; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x.data[ 0 ] = i; - z = fcn( x, y ); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var size; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - size = pow( 2, i ); - f = createBenchmark( size ); - bench( pkg+':size='+size, f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 3c6f450..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::fcns_array', function benchmark( b ) { - var types; - var fcns; - var data; - var out; - var i; - - fcns = [ unary ]; - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( fcns, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::fcn_arg', function benchmark( b ) { - var types; - var data; - var out; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( unary, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0aae4af..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch" -%% click B href "https://github.com/stdlib-js/ndarray-dispatch/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-dispatch/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-dispatch/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-dispatch/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-dispatch/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch -[production-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 1295a44..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import dispatch from '../docs/types/index'; -export = dispatch; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 82b5a88..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var y=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var b=y(function(D,w){"use strict";function V(e,r,a,u,m,f,i,o,l){var h,n,s,t;for(h=f,s=0;s [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' );\n\t}\n\ttypes = dtypes2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( 'invalid invocation. Insufficient arguments.' );\n\t\t\t}\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = dispatch;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an ndarray function interface which performs multiple dispatch.\n*\n* @module @stdlib/ndarray-dispatch\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var unary = require( '@stdlib/ndarray-base-unary' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var Float64Array = require( '@stdlib/array-float64' );\n* var dispatch = require( '@stdlib/ndarray-dispatch' );\n*\n* var types = [\n* 'float64', 'float64'\n* ];\n*\n* var data = [\n* abs\n* ];\n*\n* var absolute = dispatch( unary, types, data, 2, 1, 1 );\n*\n* // ...\n*\n* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] );\n* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] );\n*\n* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' );\n* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' );\n*\n* absolute( x, y );\n* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA6EA,SAASC,EAAcC,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,EAAU,CAClF,IAAIC,EACAC,EACAC,EACAC,EAIJ,IADAH,EAAKJ,EACCM,EAAI,EAAGA,EAAIX,EAAGW,IAAM,CAEzB,IADAD,EAAKF,EACCI,EAAI,EAAGA,EAAIX,GACXC,EAAGO,EAAIG,EAAER,CAAU,IAAME,EAAGI,CAAG,EADjBE,IAInBF,GAAMH,EAGP,GAAKK,IAAMX,EACV,OAAOU,EAERF,GAAMN,CACP,CACA,MAAO,EACR,CAKAL,EAAO,QAAUC,ICzGjB,IAAAc,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAoB,QAAS,oCAAqC,EAClEC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAkB,QAAS,kCAAmC,EAC9DC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAc,QAAS,yCAA0C,EACjEC,EAAe,QAAS,mCAAoC,EAC5DC,EAAe,IAqDnB,SAASC,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,EAAO,CACxD,IAAIC,EACAC,EACAC,EAEJ,GAAKjB,EAAYS,CAAK,EACrBQ,EAAMR,UACK,CAACV,EAAiBU,CAAK,EAClC,MAAM,IAAI,UAAWN,EAAQ,oGAAqGM,CAAK,CAAE,EAE1I,GAAK,CAACR,EAAcS,CAAM,EACzB,MAAM,IAAI,UAAWP,EAAQ,+EAAgFO,CAAM,CAAE,EAEtH,GAAK,CAACT,EAAcU,CAAK,GAAKA,IAAS,KACtC,MAAM,IAAI,UAAWR,EAAQ,sFAAuFQ,CAAK,CAAE,EAE5H,GAAK,CAACd,EAAmBe,CAAM,EAC9B,MAAM,IAAI,UAAWT,EAAQ,6EAA8ES,CAAM,CAAE,EAEpH,GAAK,CAAChB,EAAsBiB,CAAI,EAC/B,MAAM,IAAI,UAAWV,EAAQ,+EAAgFU,CAAI,CAAE,EAEpH,GAAK,CAACjB,EAAsBkB,CAAK,EAChC,MAAM,IAAI,UAAWX,EAAQ,+EAAgFW,CAAK,CAAE,EAGrH,GADAC,EAAUF,EAAMC,EACXC,IAAY,EAChB,MAAM,IAAI,MAAO,4IAA6I,EAE/J,GAAKH,IAAUG,EACd,MAAM,IAAI,MAAO,4FAA6F,EAE/G,GAAKE,GAEJ,GADAD,EAAQN,EAAM,OAASK,EAClB,CAACjB,EAAWkB,CAAM,EACtB,MAAM,IAAI,MAAO,8IAA+I,UAGjKA,EAAQP,EAAK,OACRC,EAAM,SAAWM,EAAMD,EAC3B,MAAM,IAAI,MAAO,8IAA+I,EAGlK,GAAKJ,GAAQA,EAAK,SAAWK,EAC5B,MAAM,IAAI,MAAO,mGAAoG,EAEtH,OAAAN,EAAQJ,EAAcI,CAAM,EACrBQ,EAeP,SAASA,GAAa,CACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GADAJ,EAAO,UAAU,OACZA,IAAST,EACb,MAAKS,EAAOT,EACL,IAAI,MAAO,6CAA8C,EAE1D,IAAI,MAAO,yCAA0C,EAI5D,IAFAO,EAAS,CAAC,EACVC,EAAS,CAAC,EACJK,EAAI,EAAGA,EAAIb,EAAOa,IAAM,CAE7B,GADAF,EAAI,UAAWE,CAAE,EACZ,CAACvB,EAAeqB,CAAE,EACtB,MAAKE,EAAIZ,EACF,IAAI,UAAWV,EAAQ,6EAA8EoB,CAAE,CAAE,EAEzG,IAAI,UAAWpB,EAAQ,8EAA+EoB,CAAE,CAAE,EAGlHJ,EAAO,KAAMI,CAAE,EACfH,EAAO,KAAMf,EAAaD,EAAUmB,CAAE,CAAE,CAAE,CAC3C,CAKA,GAHAD,EAAMf,EAAcS,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGK,EAAQ,EAAG,CAAE,EAGlEE,EAAM,EACV,MAAM,IAAI,UAAW,6GAA8G,EAcpI,GAXKL,EACJO,EAAIP,EAEJO,EAAIf,EAAMa,CAAI,EAGVX,EACJa,EAAGL,EAAQR,EAAMW,CAAI,CAAE,EAEvBE,EAAGL,CAAO,EAENL,IAAS,EACb,OAAOK,EAAQJ,EAAQ,CAAE,EAE1B,GAAKD,IAAS,EAGd,OAAOK,EAAO,MAAON,CAAI,CAC1B,CACD,CAKAlB,EAAO,QAAUa,IC1JjB,IAAIkB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_index_of_types", "__commonJSMin", "exports", "module", "indexOfTypes", "N", "M", "x", "strideX1", "strideX2", "offsetX", "y", "strideY", "offsetY", "ix", "iy", "i", "j", "require_main", "__commonJSMin", "exports", "module", "isNonNegativeInteger", "isPositiveInteger", "isInteger", "isFunctionArray", "isFunction", "isCollection", "isndarrayLike", "format", "getDType", "resolveEnum", "dtypes2enums", "indexOfTypes", "dispatch", "fcns", "types", "data", "nargs", "nin", "nout", "narrays", "nfcns", "fcn", "dispatcher", "arrays", "dtypes", "argc", "idx", "v", "f", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 02fe150..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,87 +0,0 @@ - -{{alias}}( fcns, types, data, nargs, nin, nout ) - Returns an ndarray function interface which performs multiple dispatch. - - An ndarray function interface has the following signature: - - f( x, y, ... ) - - where - - - x: ndarray. - - y: ndarray. - - ...: additional ndarrays. - - The number of parameters is derived from `nargs`, the number of input - ndarrays is derived from `nin`, and the number of output ndarrays is derived - from `nout`. - - Parameters - ---------- - fcns: Function|ArrayLikeObject - List of ndarray functions. An ndarray function should have the following - signature: - - f( arrays, data ) - - where - - - arrays: array containing input and output ndarrays. - - data: ndarray function data (e.g., a callback). - - For convenience, a single ndarray function may be provided which will be - invoked whenever the ndarray argument data types match a sequence of - types in `types`. Providing a single ndarray function is particularly - convenient for the case where, regardless of array data types, - traversing arrays remains the same, but the ndarray function `data` - differs (e.g., callbacks which differ based on the array data types). - - types: ArrayLikeObject - One-dimensional list of ndarray argument data types. - - data: ArrayLikeObject|null - ndarray function data (e.g., callbacks). If `null`, a returned ndarray - function interface does **not** provide a `data` argument to an invoked - ndarray function. - - nargs: integer - Total number of ndarray function interface arguments. - - nin: integer - Number of input ndarrays. - - nout: integer - Number of output ndarrays. - - Returns - ------- - fcn: Function - ndarray function interface. - - Examples - -------- - // Define ndarray argument data types: - > var t = [ 'float64', 'float64', 'float32', 'float32' ]; - - // Define a list of ndarray function data (callbacks): - > var d = [ {{alias:@stdlib/math/base/special/abs}}, {{alias:@stdlib/math/base/special/absf}} ]; - - // Create an ndarray function interface for applying unary callbacks: - > var f = {{alias}}( {{alias:@stdlib/ndarray/base/unary}}, t, d, 2, 1, 1 ); - - // Create an input ndarray: - > var xbuf = new {{alias:@stdlib/array/float64}}( [ -1.0, -2.0, -3.0, -4.0 ] ); - > var x = {{alias:@stdlib/ndarray/ctor}}( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Create an output ndarray: - > var ybuf = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 0.0, 0.0 ] ); - > var y = {{alias:@stdlib/ndarray/ctor}}( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Compute the element-wise absolute value: - > f( x, y ); - > ybuf - [ 1.0, 2.0, 3.0, 4.0 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 3fece39..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,615 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable max-lines, prefer-const */ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import ind2sub = require( '@stdlib/ndarray-ind2sub' ); -import dispatch = require( './index' ); - - -// FUNCTIONS // - -/** -* Nullary callback. -* -* @returns input value -*/ -function nullary(): any { - return 5.0; -} - -/** -* Unary callback. -* -* @param x - input value -* @returns input value -*/ -function unary( x: any ): any { - return x; -} - -/** -* Binary callback. -* -* @param x - input value -* @param y - input value -* @returns output value -*/ -function binary( x: number, y: number ): number { - return x + y; -} - -/** -* Ternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @returns output value -*/ -function ternary( x: number, y: number, z: number ): number { - return x + y + z; -} - -/** -* Quaternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @param w - input value -* @returns output value -*/ -function quaternary( x: number, y: number, z: number, w: number ): number { - return x + y + z + w; -} - -/** -* Mock ndarray function. -* -* @param arrays - ndarrays -* @param fcn - callback -*/ -function ndarrayFcn( arrays: Array, fcn: ( x: any ) => any ): void { - let xord; - let yord; - let opts; - let sub; - let sh; - let N; - let x; - let y; - let v; - let i; - - x = arrays[ 0 ]; - y = arrays[ 1 ]; - sh = x.shape; - if ( sh.length === 0 ) { - return; - } - N = 1; - for ( i = 0; i < sh.length; i += 1 ) { - N *= sh[ i ]; - } - xord = x.order; - yord = y.order; - opts = { - 'order': xord - }; - for ( i = 0; i < N; i += 1 ) { - // Convert a linear index to subscripts: - opts.order = xord; - sub = ind2sub( sh, i, opts ); - - // Retrieve an element from `x`: - v = x.get.apply( x, sub ); - - // Convert a linear index to subscripts: - opts.order = yord; - sub = ind2sub( sh, i, opts ); - - // Append the result of applying the callback: - sub[ sub.length ] = fcn( v ) as number; - - // Assign the result to an element in `y`: - y.set.apply( y, sub ); - } -} - -/** -* Mock function to create an ndarray-like object. -* -* @returns ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a dispatch function... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, 1 ); // $ExpectType Dispatcher - dispatch( [ ndarrayFcn ], types, data, 2, 1, 1 ); // $ExpectType Dispatcher -} - -// The compiler throws an error if the function is provided a first argument which is not either an ndarray function or an array-like object containing ndarray functions... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( '10', types, data, 2, 1, 1 ); // $ExpectError - dispatch( 10, types, data, 2, 1, 1 ); // $ExpectError - dispatch( true, types, data, 2, 1, 1 ); // $ExpectError - dispatch( false, types, data, 2, 1, 1 ); // $ExpectError - dispatch( null, types, data, 2, 1, 1 ); // $ExpectError - dispatch( undefined, types, data, 2, 1, 1 ); // $ExpectError - dispatch( [ '1' ], types, data, 2, 1, 1 ); // $ExpectError - dispatch( {}, types, data, 2, 1, 1 ); // $ExpectError - dispatch( ( x: number ): number => x, types, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object... -{ - const data = [ unary ]; - - dispatch( ndarrayFcn, 10, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, true, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, false, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, null, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, undefined, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, {}, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object or null... -{ - const types = [ 'float64', 'float64' ]; - - dispatch( ndarrayFcn, types, 10, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, true, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, false, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, undefined, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, {}, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, '10', 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, true, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, false, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, null, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, undefined, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, [ '1' ], 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, {}, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, ( x: number ): number => x, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, '10', 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, true, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, false, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, null, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, undefined, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, [ '1' ], 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, {}, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, ( x: number ): number => x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, '10' ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, true ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, false ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, null ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, undefined ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, [ '1' ] ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, {} ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch(); // $ExpectError - dispatch( ndarrayFcn ); // $ExpectError - dispatch( ndarrayFcn, types ); // $ExpectError - dispatch( ndarrayFcn, types, data ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, 1, 0 ); // $ExpectError -} - -// The function returns a dispatch function... -{ - const x = array(); - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const t1 = [ 'float64' ]; - const d1 = [ nullary ]; - const f1 = dispatch( ndarrayFcn, t1, d1, 1, 1, 0 ); - f1( x ); // $ExpectType void | ndarray - - const t2 = [ 'float64', 'float64' ]; - const d2 = [ unary ]; - const f2 = dispatch( ndarrayFcn, t2, d2, 2, 1, 1 ); - f2( x, y ); // $ExpectType void | ndarray - - const t3 = [ 'float64', 'float64', 'float64' ]; - const d3 = [ binary ]; - const f3 = dispatch( ndarrayFcn, t3, d3, 3, 2, 1 ); - f3( x, y, z ); // $ExpectType void | ndarray - - const t4 = [ 'float64', 'float64', 'float64', 'float64' ]; - const d4 = [ ternary ]; - const f4 = dispatch( ndarrayFcn, t4, d4, 4, 3, 1 ); - f4( x, y, z, w ); // $ExpectType void | ndarray - - const t5 = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const d5 = [ quaternary ]; - const f5 = dispatch( ndarrayFcn, t5, d5, 5, 4, 1 ); - f5( x, y, z, w, u ); // $ExpectType void | ndarray -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (1 ndarray)... -{ - const types = [ 'float64' ]; - const data = [ nullary ]; - - const f = dispatch( ndarrayFcn, types, data, 1, 0, 1 ); - f( '10' ); // $ExpectError - f( 10 ); // $ExpectError - f( true ); // $ExpectError - f( false ); // $ExpectError - f( null ); // $ExpectError - f( undefined ); // $ExpectError - f( [ '1' ] ); // $ExpectError - f( {} ); // $ExpectError - f( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( 10, y ); // $ExpectError - f( '10', y ); // $ExpectError - f( true, y ); // $ExpectError - f( false, y ); // $ExpectError - f( null, y ); // $ExpectError - f( undefined, y ); // $ExpectError - f( [ '1' ], y ); // $ExpectError - f( {}, y ); // $ExpectError - f( ( x: number ): number => x, y ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const x = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( x, 10 ); // $ExpectError - f( x, '10' ); // $ExpectError - f( x, true ); // $ExpectError - f( x, false ); // $ExpectError - f( x, null ); // $ExpectError - f( x, undefined ); // $ExpectError - f( x, [ '1' ] ); // $ExpectError - f( x, {} ); // $ExpectError - f( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( 10, y, z ); // $ExpectError - f( '10', y, z ); // $ExpectError - f( true, y, z ); // $ExpectError - f( false, y, z ); // $ExpectError - f( null, y, z ); // $ExpectError - f( undefined, y, z ); // $ExpectError - f( [ '1' ], y, z ); // $ExpectError - f( {}, y, z ); // $ExpectError - f( ( x: number ): number => x, y, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, 10, z ); // $ExpectError - f( x, '10', z ); // $ExpectError - f( x, true, z ); // $ExpectError - f( x, false, z ); // $ExpectError - f( x, null, z ); // $ExpectError - f( x, undefined, z ); // $ExpectError - f( x, [ '1' ], z ); // $ExpectError - f( x, {}, z ); // $ExpectError - f( x, ( x: number ): number => x, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, y, '10' ); // $ExpectError - f( x, y, true ); // $ExpectError - f( x, y, false ); // $ExpectError - f( x, y, null ); // $ExpectError - f( x, y, undefined ); // $ExpectError - f( x, y, [ '1' ] ); // $ExpectError - f( x, y, {} ); // $ExpectError - f( x, y, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( 10, y, z, w ); // $ExpectError - f( '10', y, z, w ); // $ExpectError - f( true, y, z, w ); // $ExpectError - f( false, y, z, w ); // $ExpectError - f( null, y, z, w ); // $ExpectError - f( undefined, y, z, w ); // $ExpectError - f( [ '1' ], y, z, w ); // $ExpectError - f( {}, y, z, w ); // $ExpectError - f( ( x: number ): number => x, y, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, 10, z, w ); // $ExpectError - f( x, '10', z, w ); // $ExpectError - f( x, true, z, w ); // $ExpectError - f( x, false, z, w ); // $ExpectError - f( x, null, z, w ); // $ExpectError - f( x, undefined, z, w ); // $ExpectError - f( x, [ '1' ], z, w ); // $ExpectError - f( x, {}, z, w ); // $ExpectError - f( x, ( x: number ): number => x, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, 10, w ); // $ExpectError - f( x, y, '10', w ); // $ExpectError - f( x, y, true, w ); // $ExpectError - f( x, y, false, w ); // $ExpectError - f( x, y, null, w ); // $ExpectError - f( x, y, undefined, w ); // $ExpectError - f( x, y, [ '1' ], w ); // $ExpectError - f( x, y, {}, w ); // $ExpectError - f( x, y, ( x: number ): number => x, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, z, 10 ); // $ExpectError - f( x, y, z, '10' ); // $ExpectError - f( x, y, z, true ); // $ExpectError - f( x, y, z, false ); // $ExpectError - f( x, y, z, null ); // $ExpectError - f( x, y, z, undefined ); // $ExpectError - f( x, y, z, [ '1' ] ); // $ExpectError - f( x, y, z, {} ); // $ExpectError - f( x, y, z, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( 10, y, z, w, u ); // $ExpectError - f( '10', y, z, w, u ); // $ExpectError - f( true, y, z, w, u ); // $ExpectError - f( false, y, z, w, u ); // $ExpectError - f( null, y, z, w, u ); // $ExpectError - f( undefined, y, z, w, u ); // $ExpectError - f( [ '1' ], y, z, w, u ); // $ExpectError - f( {}, y, z, w, u ); // $ExpectError - f( ( x: number ): number => x, y, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, 10, z, w, u ); // $ExpectError - f( x, '10', z, w, u ); // $ExpectError - f( x, true, z, w, u ); // $ExpectError - f( x, false, z, w, u ); // $ExpectError - f( x, null, z, w, u ); // $ExpectError - f( x, undefined, z, w, u ); // $ExpectError - f( x, [ '1' ], z, w, u ); // $ExpectError - f( x, {}, z, w, u ); // $ExpectError - f( x, ( x: number ): number => x, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, 10, w, u ); // $ExpectError - f( x, y, '10', w, u ); // $ExpectError - f( x, y, true, w, u ); // $ExpectError - f( x, y, false, w, u ); // $ExpectError - f( x, y, null, w, u ); // $ExpectError - f( x, y, undefined, w, u ); // $ExpectError - f( x, y, [ '1' ], w, u ); // $ExpectError - f( x, y, {}, w, u ); // $ExpectError - f( x, y, ( x: number ): number => x, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, 10, u ); // $ExpectError - f( x, y, z, '10', u ); // $ExpectError - f( x, y, z, true, u ); // $ExpectError - f( x, y, z, false, u ); // $ExpectError - f( x, y, z, null, u ); // $ExpectError - f( x, y, z, undefined, u ); // $ExpectError - f( x, y, z, [ '1' ], u ); // $ExpectError - f( x, y, z, {}, u ); // $ExpectError - f( x, y, z, ( x: number ): number => x, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fifth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, w, 10 ); // $ExpectError - f( x, y, z, w, '10' ); // $ExpectError - f( x, y, z, w, true ); // $ExpectError - f( x, y, z, w, false ); // $ExpectError - f( x, y, z, w, null ); // $ExpectError - f( x, y, z, w, undefined ); // $ExpectError - f( x, y, z, w, [ '1' ] ); // $ExpectError - f( x, y, z, w, {} ); // $ExpectError - f( x, y, z, w, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/add.js b/examples/add.js deleted file mode 100644 index 775b711..0000000 --- a/examples/add.js +++ /dev/null @@ -1,121 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var dispatch = require( './../lib' ); - -function add2( arrays ) { - var opts; - var xo; - var yo; - var zo; - var sx; - var sy; - var sz; - var sh; - var N; - var x; - var y; - var z; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - z = arrays[ 2 ]; - xo = x.order; - yo = y.order; - zo = z.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - opts.order = yo; - sy = ind2sub( sh, i, opts ); - v = x.get.apply( x, sx ) + y.get.apply( y, sy ); - - opts.order = zo; - sz = ind2sub( sh, i, opts ); - sz.push( v ); - z.set.apply( z, sz ); - } -} - -var fcns = [ - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2 -]; - -var types = [ - dtypes.float64, dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.int32, dtypes.int32, - dtypes.uint32, dtypes.uint32, dtypes.uint32, - dtypes.int16, dtypes.int16, dtypes.int16, - dtypes.uint16, dtypes.uint16, dtypes.uint16, - dtypes.int8, dtypes.int8, dtypes.int8, - dtypes.uint8, dtypes.uint8, dtypes.uint8, - dtypes.uint8c, dtypes.uint8c, dtypes.uint8c -]; - -var add = dispatch( fcns, types, null, 3, 2, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var zbuf = new Float64Array( xbuf.length ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var z = ndarray( 'float64', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); - -xbuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -ybuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -zbuf = new Int32Array( xbuf.length ); - -x = ndarray( 'int32', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'int32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -z = ndarray( 'int32', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); diff --git a/examples/sin.js b/examples/sin.js deleted file mode 100644 index 8cd4871..0000000 --- a/examples/sin.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int8Array = require( '@stdlib/array-int8' ); -var sin = require( '@stdlib/math-base-special-sin' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/strided-dtypes' ); -var dispatch = require( './../lib' ); - -function apply( arrays, fcn ) { - var opts; - var xo; - var yo; - var sx; - var sy; - var sh; - var N; - var x; - var y; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - xo = x.order; - yo = y.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - v = fcn( x.get.apply( x, sx ) ); - - opts.order = yo; - sy = ind2sub( sh, i, opts ); - sy.push( v ); - y.set.apply( y, sy ); - } -} - -var fcns = [ - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply -]; - -var types = [ - dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float64, - dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.float64, - dtypes.uint32, dtypes.float64, - dtypes.int16, dtypes.float64, - dtypes.int16, dtypes.float32, - dtypes.uint16, dtypes.float64, - dtypes.uint16, dtypes.float32, - dtypes.int8, dtypes.float64, - dtypes.int8, dtypes.float32, - dtypes.uint8, dtypes.float64, - dtypes.uint8, dtypes.float32, - dtypes.uint8c, dtypes.float64, - dtypes.uint8c, dtypes.float32 -]; - -var data = [ - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin -]; - -var sine = dispatch( fcns, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); - -xbuf = new Int8Array( [ 1, 2, 3, 4, 5 ] ); -ybuf = new Float32Array( xbuf.length ); - -x = ndarray( 'int8', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'float32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); diff --git a/examples/unary.js b/examples/unary.js deleted file mode 100644 index e9c3fb4..0000000 --- a/examples/unary.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -var unary = require( '@stdlib/ndarray-base-unary' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var dispatch = require( './../lib' ); - -var types = [ 'float64', 'float64' ]; - -var data = [ - abs -]; - -var absolute = dispatch( unary, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -absolute( x, y ); -console.log( ybuf ); -// => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 5f280a1..c49a4e4 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..d8bef9e --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtypes2enums@esm/index.mjs";function f(f,l,p,w,v,a){var g,c,y;if(i(f))y=f;else if(!s(f))throw new TypeError(d("0jr5d",f));if(!n(l))throw new TypeError(d("0jr2y",l));if(!n(p)&&null!==p)throw new TypeError(d("0jr5e",p));if(!e(w))throw new TypeError(d("0jr5f",w));if(!r(v))throw new TypeError(d("0jr5X",v));if(!r(a))throw new TypeError(d("0jr5g",a));if(0===(g=v+a))throw new Error(d("0jr0h"));if(w!==g)throw new Error(d("0jr0i"));if(y){if(c=l.length/g,!t(c))throw new Error(d("0jr0j"))}else if(c=f.length,l.length!==c*g)throw new Error(d("0jr0j"));if(p&&p.length!==c)throw new Error(d("0jr0k"));return l=h(l),function(){var r,e,t,s,i,n,h;if(t=arguments.length,t!==w){if(t [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0jr5d', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0jr2y', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( '0jr5e', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0jr5f', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0jr5X', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0jr5g', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format('0jr0h') );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format('0jr0i') );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format('0jr0k') );\n\t}\n\ttypes = dtypes2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format('0jr0l') );\n\t\t\t}\n\t\t\tthrow new Error( format('0jr0m') );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( '0jr5h', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( '0jr5i', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format('0jr0n') );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found).\n*\n* ## Notes\n*\n* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types).\n* - The function assumes that `x` is stored in row-major order.\n* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`.\n* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value.\n*\n* @private\n* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension)\n* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension)\n* @param {ArrayLikeObject} x - input two-dimensional reference array\n* @param {integer} strideX1 - `x` stride length along first dimension\n* @param {integer} strideX2 - `x` stride length along second dimension\n* @param {NonNegativeInteger} offsetX - `x` starting index\n* @param {ArrayLikeObject} y - search array\n* @param {integer} strideY - `y` stride length\n* @param {NonNegativeInteger} offsetY - `y` starting index\n* @returns {integer} row index (if found) and `-1` otherwise\n*\n* @example\n* // Define a reference array to search:\n* var types = [\n* 'float64', 'float64', 'float64',\n* 'float32', 'float32', 'float32',\n* 'uint32', 'uint32', 'float64',\n* 'int32', 'int32', 'float64',\n* 'uint16', 'uint16', 'float64',\n* 'int16', 'int16', 'float64',\n* 'uint8', 'uint8', 'float64',\n* 'int8', 'int8', 'float64'\n* ];\n*\n* // Define reference array dimensions:\n* var N = 8; // rows\n* var M = 3; // columns\n*\n* // Define a search array:\n* y1 = [\n* 'float32', 'float32', 'float32',\n* ];\n*\n* // Find the list of types:\n* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 );\n* // returns 1\n*\n// Define a search array:\n* y2 = [\n* 'float32', 'float32', 'float64',\n* ];\n*\n* // Find the list of types:\n* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 );\n* // returns -1\n*/\nfunction indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len\n\tvar ix;\n\tvar iy;\n\tvar i;\n\tvar j;\n\n\t// Search for the first row which matches `y`...\n\tix = offsetX;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tiy = offsetY;\n\t\tfor ( j = 0; j < M; j++ ) {\n\t\t\tif ( x[ ix+(j*strideX2) ] !== y[ iy ] ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tiy += strideY;\n\t\t}\n\t\t// If we successfully iterated over all columns, then that means we've found a match...\n\t\tif ( j === M ) {\n\t\t\treturn i;\n\t\t}\n\t\tix += strideX1;\n\t}\n\treturn -1;\n}\n\n\n// EXPORTS //\n\nexport default indexOfTypes;\n"],"names":["dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","dtypes2enums","arrays","dtypes","argc","idx","v","f","i","arguments","isndarrayLike","push","resolveEnum","getDType","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","j","indexOfTypes","slice"],"mappings":";;ukCAsFA,SAASA,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAO,UAEzB,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAO,UAEzB,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAO,eAIzB,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAO,UAG1B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAO,UAGzB,OADAX,EAAQkB,EAAclB,GAgBtB,WACC,IAAImB,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GADAJ,EAAOK,UAAUV,OACZK,IAASnB,EAAQ,CACrB,GAAKmB,EAAOnB,EACX,MAAM,IAAIa,MAAOJ,EAAO,UAEzB,MAAM,IAAII,MAAOJ,EAAO,SACxB,CAGD,IAFAQ,EAAS,GACTC,EAAS,GACHK,EAAI,EAAGA,EAAIvB,EAAOuB,IAAM,CAE7B,IAAME,EADNJ,EAAIG,UAAWD,IAEd,MAAKA,EAAItB,EACF,IAAIO,UAAWC,EAAQ,QAASY,IAEhC,IAAIb,UAAWC,EAAQ,QAASY,IAGxCJ,EAAOS,KAAML,GACbH,EAAOQ,KAAMC,EAAaC,EAAUP,IACpC,CAKD,IAHAD,ECtGF,SAAuBS,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAhB,EACAiB,EAIJ,IADAF,EAAKJ,EACCX,EAAI,EAAGA,EAAIM,EAAGN,IAAM,CAEzB,IADAgB,EAAKF,EACCG,EAAI,EAAGA,EAAIV,GACXC,EAAGO,EAAIE,EAAEP,KAAgBE,EAAGI,GADdC,IAInBD,GAAMH,EAGP,GAAKI,IAAMV,EACV,OAAOP,EAERe,GAAMN,CACN,CACD,OAAQ,CACT,CD+EQS,CAAcrC,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGe,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAIV,UAAWC,EAAO,UAI5Ba,EADIjB,GAGAR,EAAMuB,GAGNrB,EACJuB,EAAGL,EAAQlB,EAAMqB,IAEjBE,EAAGL,GAEJ,GAAc,IAATf,EACJ,OAAOe,EAAQd,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOe,EAAOyB,MAAOzC,EACrB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 88f0e3e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Create an ndarray function interface which performs multiple dispatch. -* -* @module @stdlib/ndarray-dispatch -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var dispatch = require( '@stdlib/ndarray-dispatch' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/index_of_types.js b/lib/index_of_types.js deleted file mode 100644 index fda2297..0000000 --- a/lib/index_of_types.js +++ /dev/null @@ -1,106 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found). -* -* ## Notes -* -* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types). -* - The function assumes that `x` is stored in row-major order. -* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`. -* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value. -* -* @private -* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension) -* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension) -* @param {ArrayLikeObject} x - input two-dimensional reference array -* @param {integer} strideX1 - `x` stride length along first dimension -* @param {integer} strideX2 - `x` stride length along second dimension -* @param {NonNegativeInteger} offsetX - `x` starting index -* @param {ArrayLikeObject} y - search array -* @param {integer} strideY - `y` stride length -* @param {NonNegativeInteger} offsetY - `y` starting index -* @returns {integer} row index (if found) and `-1` otherwise -* -* @example -* // Define a reference array to search: -* var types = [ -* 'float64', 'float64', 'float64', -* 'float32', 'float32', 'float32', -* 'uint32', 'uint32', 'float64', -* 'int32', 'int32', 'float64', -* 'uint16', 'uint16', 'float64', -* 'int16', 'int16', 'float64', -* 'uint8', 'uint8', 'float64', -* 'int8', 'int8', 'float64' -* ]; -* -* // Define reference array dimensions: -* var N = 8; // rows -* var M = 3; // columns -* -* // Define a search array: -* y1 = [ -* 'float32', 'float32', 'float32', -* ]; -* -* // Find the list of types: -* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 ); -* // returns 1 -* -// Define a search array: -* y2 = [ -* 'float32', 'float32', 'float64', -* ]; -* -* // Find the list of types: -* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 ); -* // returns -1 -*/ -function indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len - var ix; - var iy; - var i; - var j; - - // Search for the first row which matches `y`... - ix = offsetX; - for ( i = 0; i < N; i++ ) { - iy = offsetY; - for ( j = 0; j < M; j++ ) { - if ( x[ ix+(j*strideX2) ] !== y[ iy ] ) { - break; - } - iy += strideY; - } - // If we successfully iterated over all columns, then that means we've found a match... - if ( j === M ) { - return i; - } - ix += strideX1; - } - return -1; -} - - -// EXPORTS // - -module.exports = indexOfTypes; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 0892b4a..0000000 --- a/lib/main.js +++ /dev/null @@ -1,211 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isFunctionArray = require( '@stdlib/assert-is-function-array' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var resolveEnum = require( '@stdlib/ndarray-base-dtype-resolve-enum' ); -var dtypes2enums = require( '@stdlib/ndarray-base-dtypes2enums' ); -var indexOfTypes = require( './index_of_types.js' ); - - -// MAIN // - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param {(FunctionArray|Function)} fcns - list of ndarray functions -* @param {Collection} types - one-dimensional list of ndarray argument data types -* @param {(Collection|null)} data - ndarray function data (e.g., callbacks) -* @param {PositiveInteger} nargs - total number of ndarray function interface arguments -* @param {NonNegativeInteger} nin - number of input ndarrays -* @param {NonNegativeInteger} nout - number of output ndarrays -* @throws {TypeError} first argument must be either a function or an array of functions -* @throws {TypeError} second argument must be an array-like object -* @throws {TypeError} third argument must be an array-like object or `null` -* @throws {Error} third and first arguments must have the same number of elements -* @throws {TypeError} fourth argument must be a positive integer -* @throws {TypeError} fifth argument must be a nonnegative integer -* @throws {TypeError} sixth argument must be a nonnegative integer -* @throws {Error} fourth argument must equal the specified number of input and output arrays -* @throws {Error} number of types must match the number of functions times the total number of array arguments for each function -* @throws {Error} interface must accept at least one input and/or output ndarray -* @returns {Function} ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function dispatch( fcns, types, data, nargs, nin, nout ) { - var narrays; - var nfcns; - var fcn; - - if ( isFunction( fcns ) ) { - fcn = fcns; - } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( '0jr5d', fcns ) ); - } - if ( !isCollection( types ) ) { - throw new TypeError( format( '0jr2y', types ) ); - } - if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( '0jr5e', data ) ); - } - if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( '0jr5f', nargs ) ); - } - if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( '0jr5X', nin ) ); - } - if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( '0jr5g', nout ) ); - } - narrays = nin + nout; - if ( narrays === 0 ) { - throw new Error( format('0jr0h') ); - } - if ( nargs !== narrays ) { - throw new Error( format('0jr0i') ); - } - if ( fcn ) { - nfcns = types.length / narrays; - if ( !isInteger( nfcns ) ) { - throw new Error( format('0jr0j') ); - } - } else { - nfcns = fcns.length; - if ( types.length !== nfcns*narrays ) { - throw new Error( format('0jr0j') ); - } - } - if ( data && data.length !== nfcns ) { - throw new Error( format('0jr0k') ); - } - types = dtypes2enums( types ); - return dispatcher; - - /** - * ndarray function interface which performs multiple dispatch. - * - * @private - * @param {ndarrayLike} x - ndarray - * @param {...ndarrayLike} args - ndarray arguments - * @throws {Error} insufficient arguments - * @throws {Error} too many arguments - * @throws {TypeError} input array arguments must be ndarray-like objects - * @throws {TypeError} output array arguments must be ndarray-like objects - * @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types - * @returns {(ndarrayLike|Array|void)} destination array(s) - */ - function dispatcher() { - var arrays; - var dtypes; - var argc; - var idx; - var v; - var f; - var i; - - argc = arguments.length; - if ( argc !== nargs ) { - if ( argc < nargs ) { - throw new Error( format('0jr0l') ); - } - throw new Error( format('0jr0m') ); - } - arrays = []; - dtypes = []; - for ( i = 0; i < nargs; i++ ) { - v = arguments[ i ]; - if ( !isndarrayLike( v ) ) { - if ( i < nin ) { - throw new TypeError( format( '0jr5h', v ) ); - } else { - throw new TypeError( format( '0jr5i', v ) ); - } - } - arrays.push( v ); - dtypes.push( resolveEnum( getDType( v ) ) ); - } - // Resolve the ndarray function satisfying the input array types: - idx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len - - // Check whether we were able to successfully resolve an ndarray function: - if ( idx < 0 ) { - throw new TypeError( format('0jr0n') ); - } - // Retrieve the ndarray function: - if ( fcn ) { - f = fcn; - } else { - f = fcns[ idx ]; - } - // Evaluate the ndarray function: - if ( data ) { - f( arrays, data[ idx ] ); - } else { - f( arrays ); - } - if ( nout === 1 ) { - return arrays[ narrays-1 ]; - } - if ( nout === 0 ) { - return; - } - return arrays.slice( nin ); - } -} - - -// EXPORTS // - -module.exports = dispatch; diff --git a/package.json b/package.json index 240c09f..e6c8bad 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Create an ndarray function interface which performs multiple dispatch.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,58 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-function-array": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer": "^0.2.2", - "@stdlib/assert-is-positive-integer": "^0.2.2", - "@stdlib/ndarray-base-dtype-resolve-enum": "^0.2.2", - "@stdlib/ndarray-base-dtypes2enums": "github:stdlib-js/ndarray-base-dtypes2enums#main", - "@stdlib/ndarray-dtype": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.2.2", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/array-int8": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/math-base-assert-is-nan": "^0.2.2", - "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/math-base-special-pow": "^0.3.0", - "@stdlib/math-base-special-sin": "^0.3.0", - "@stdlib/ndarray-base-buffer-dtype": "^0.3.0", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-unary": "^0.2.1", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-dtypes": "^0.3.0", - "@stdlib/ndarray-ind2sub": "^0.2.2", - "@stdlib/strided-dtypes": "^0.3.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "ndarray", @@ -101,7 +26,6 @@ "multimethod", "multimethods" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..2342a52 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/fixtures/binary.js b/test/fixtures/binary.js deleted file mode 100644 index a60dfa2..0000000 --- a/test/fixtures/binary.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Binary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @returns {number} sum -*/ -function binary( x, y ) { - return x + y; -} - - -// EXPORTS // - -module.exports = binary; diff --git a/test/fixtures/fill.js b/test/fixtures/fill.js deleted file mode 100644 index 41b2958..0000000 --- a/test/fixtures/fill.js +++ /dev/null @@ -1,76 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which fills one or more ndarrays. -* -* @private -* @param {*} value - fill value -* @returns {Function} ndarray function -*/ -function fill( value ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - */ - function ndarrayFcn( arrays ) { - var opts; - var sub; - var arr; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - opts = { - 'order': '' - }; - for ( j = 0; j < M; j++ ) { - arr = arrays[ j ]; - opts.order = arrays[ j ].order; - for ( i = 0; i < N; i++ ) { - sub = ind2sub( sh, i, opts ); - sub.push( value ); - arr.set.apply( arr, sub ); - } - } - } -} - - -// EXPORTS // - -module.exports = fill; diff --git a/test/fixtures/foreach.js b/test/fixtures/foreach.js deleted file mode 100644 index a426290..0000000 --- a/test/fixtures/foreach.js +++ /dev/null @@ -1,72 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function forEach( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - fcn.apply( null, args ); - } -} - - -// EXPORTS // - -module.exports = forEach; diff --git a/test/fixtures/map1n.js b/test/fixtures/map1n.js deleted file mode 100644 index 614196b..0000000 --- a/test/fixtures/map1n.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function which maps the return value of a callback to `N` arrays. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function map1N( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var v; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - v = fcn(); - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - sub.push( v ); - arrays[ j ].set.apply( arrays[ j ], sub ); - } - } -} - - -// EXPORTS // - -module.exports = map1N; diff --git a/test/fixtures/nullary.js b/test/fixtures/nullary.js deleted file mode 100644 index 4f22126..0000000 --- a/test/fixtures/nullary.js +++ /dev/null @@ -1,36 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Nullary callback. -* -* @private -* @returns {number} value -*/ -function nullary() { - return 3.0; -} - - -// EXPORTS // - -module.exports = nullary; diff --git a/test/fixtures/quaternary.js b/test/fixtures/quaternary.js deleted file mode 100644 index 548437b..0000000 --- a/test/fixtures/quaternary.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quaternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @returns {number} sum -*/ -function quaternary( x, y, z, w ) { - return x + y + z + w; -} - - -// EXPORTS // - -module.exports = quaternary; diff --git a/test/fixtures/quinary.js b/test/fixtures/quinary.js deleted file mode 100644 index 36068de..0000000 --- a/test/fixtures/quinary.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quinary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @param {number} u - input value -* @returns {number} sum -*/ -function quinary( x, y, z, w, u ) { - return x + y + z + w + u; -} - - -// EXPORTS // - -module.exports = quinary; diff --git a/test/fixtures/sum.js b/test/fixtures/sum.js deleted file mode 100644 index efdbb1b..0000000 --- a/test/fixtures/sum.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which computes the sum across one or more ndarrays. -* -* @private -* @param {Object} ctx - context -* @param {number} ctx.sum - initial sum -* @returns {Function} ndarray function -*/ -function wrapper( ctx ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - * @param {Function} [fcn] - callback - */ - function ndarrayFcn( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var f; - var i; - var j; - - if ( arguments.length > 1 ) { - f = fcn; - } - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - if ( f ) { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - ctx.sum += f.apply( null, args ); - } - } else { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - ctx.sum += arrays[ j ].get.apply( arrays[ j ], sub ); - } - } - } - } -} - - -// EXPORTS // - -module.exports = wrapper; diff --git a/test/fixtures/ternary.js b/test/fixtures/ternary.js deleted file mode 100644 index 0595d5f..0000000 --- a/test/fixtures/ternary.js +++ /dev/null @@ -1,39 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Ternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @returns {number} sum -*/ -function ternary( x, y, z ) { - return x + y + z; -} - - -// EXPORTS // - -module.exports = ternary; diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d6c2c8e..0000000 --- a/test/test.js +++ /dev/null @@ -1,363 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var fill = require( './fixtures/fill.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either a function or an array of functions as a first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( value, types, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object as a second argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided either an array-like object or `null` as a third argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - dispatch( unary, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a positive integer for a fourth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 0, - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a fifth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, value, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a sixth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, 1, value ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function array)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var fcns = [ unary, unary, unary ]; - var data = [ abs, abs, abs ]; - dispatch( fcns, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function argument)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs, abs, abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the length of `data` argument does not match the number of ndarray functions', function test( t ) { - var values; - var i; - - values = [ - [], - [ abs, abs ], - [ abs, abs, abs ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var fcns = [ unary ]; - dispatch( fcns, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the fourth argument is incompatible with the number of input and output ndarrays', function test( t ) { - var values; - var i; - - values = [ - 0, - 1, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of specified input and output ndarrays is zero', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var types = [ 'float64' ]; - dispatch( fill( 3 ), types, null, 1, 0, 0 ); - } -}); - -tape( 'the function returns an ndarray function interface', function test( t ) { - var types; - var data; - var f; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - f = dispatch( unary, types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ unary ], types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( fill( 3 ), types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ fill( 3 ) ], types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.two_arrays.js b/test/test.two_arrays.js deleted file mode 100644 index 16eb61b..0000000 --- a/test/test.two_arrays.js +++ /dev/null @@ -1,814 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var dtype = require( '@stdlib/ndarray-base-buffer-dtype' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var forEach = require( './fixtures/foreach.js' ); -var map1N = require( './fixtures/map1n.js' ); -var fill = require( './fixtures/fill.js' ); -var sum = require( './fixtures/sum.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the first argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var ybuf = new Float64Array( 10 ); - var y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( value, y ); - }; - } -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the second argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var xbuf = new Float64Array( 10 ); - var x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( x, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided insufficient arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var f; - var x; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [], - [ x ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided too many arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var ybuf; - var f; - var x; - var y; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [ x, y, y ], - [ x, y, y, y ], - [ x, y, y, y, y ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if unable to resolve a ndarray function supporting the provided array argument data types', function test( t ) { - var values; - var types; - var data; - var xbuf; - var fcn; - var x; - var i; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ abs, abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 4 ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - values = [ - new Uint8Array( 4 ), - new Int32Array( 4 ), - [ 0, 0, 0, 0 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided an array having data type: ' + dtype( values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var y = ndarray( dtype( value ), value, [ value.length ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - }; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only input arrays)', function test( t ) { - var types; - var xbuf; - var ybuf; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only output arrays)', function test( t ) { - var expected; - var types; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only input arrays)', function test( t ) { - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var ctx; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcns = [ - sum( ctx ), - sum( ctx ) - ]; - fcn = dispatch( fcns, types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only output arrays)', function test( t ) { - var expected; - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcns = [ - fill( 3.0 ), - fill( 4.0 ) - ]; - fcn = dispatch( fcns, types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - - fcn = dispatch( forEach, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - - fcn = dispatch( map1N, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - fcns = [ - forEach, - forEach - ]; - fcn = dispatch( fcns, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - fcns = [ - map1N, - map1N - ]; - fcn = dispatch( fcns, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - fcns = [ - unary, - unary - ]; - fcn = dispatch( fcns, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which returns one or more output arrays, if one or more output arrays is specified, and otherwise returns `undefined`', function test( t ) { - var types; - var data; - var xbuf; - var ybuf; - var out; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - // No output arrays... - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, void 0, 'returns expected value' ); - - // One output array... - data = [ - abs, - abs - ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - fcn = dispatch( fill( 3.0 ), types, null, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - // Two output arrays... - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.end(); -}); From 36527ad3b627ba83dfb3e4192f0bd5eaa057d950 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 14 Sep 2025 09:57:44 +0000 Subject: [PATCH 104/109] Transform error messages --- lib/main.js | 34 +++++++++++++++++----------------- package.json | 2 +- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/main.js b/lib/main.js index 29d8984..c8b8f74 100644 --- a/lib/main.js +++ b/lib/main.js @@ -27,7 +27,7 @@ var isFunctionArray = require( '@stdlib/assert-is-function-array' ); var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var getDType = require( '@stdlib/ndarray-dtype' ); var resolveEnum = require( '@stdlib/ndarray-base-dtype-resolve-enum' ); var dtypes2enums = require( '@stdlib/ndarray-base-dtypes2enums' ); @@ -92,43 +92,43 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { if ( isFunction( fcns ) ) { fcn = fcns; } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) ); + throw new TypeError( format( '0jr5d', fcns ) ); } if ( !isCollection( types ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) ); + throw new TypeError( format( '0jr2y', types ) ); } if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); + throw new TypeError( format( '0jr5e', data ) ); } if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) ); + throw new TypeError( format( '0jr5f', nargs ) ); } if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) ); + throw new TypeError( format( '0jr5X', nin ) ); } if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) ); + throw new TypeError( format( '0jr5g', nout ) ); } narrays = nin + nout; if ( narrays === 0 ) { - throw new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' ); + throw new Error( format('0jr0h') ); } if ( nargs !== narrays ) { - throw new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' ); + throw new Error( format('0jr0i') ); } if ( fcn ) { nfcns = types.length / narrays; if ( !isInteger( nfcns ) ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format('0jr0j') ); } } else { nfcns = fcns.length; if ( types.length !== nfcns*narrays ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format('0jr0j') ); } } if ( data && data.length !== nfcns ) { - throw new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' ); + throw new Error( format('0jr0k') ); } types = dtypes2enums( types ); return dispatcher; @@ -158,9 +158,9 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { argc = arguments.length; if ( argc !== nargs ) { if ( argc < nargs ) { - throw new Error( 'invalid invocation. Insufficient arguments.' ); + throw new Error( format('0jr0l') ); } - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('0jr0m') ); } arrays = []; dtypes = []; @@ -168,9 +168,9 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { v = arguments[ i ]; if ( !isndarrayLike( v ) ) { if ( i < nin ) { - throw new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) ); + throw new TypeError( format( '0jr5h', v ) ); } else { - throw new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) ); + throw new TypeError( format( '0jr5i', v ) ); } } arrays.push( v ); @@ -181,7 +181,7 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { // Check whether we were able to successfully resolve an ndarray function: if ( idx < 0 ) { - throw new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' ); + throw new TypeError( format('0jr0n') ); } // Retrieve the ndarray function: if ( fcn ) { diff --git a/package.json b/package.json index 2c100bf..1713c63 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@stdlib/ndarray-base-dtype-resolve-enum": "^0.2.2", "@stdlib/ndarray-base-dtypes2enums": "github:stdlib-js/ndarray-base-dtypes2enums#main", "@stdlib/ndarray-dtype": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 3c9f1127afb5e50652a38f69aefc19246c72e259 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 14 Sep 2025 09:59:27 +0000 Subject: [PATCH 105/109] Remove files --- index.d.ts | 334 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5181 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index c49a4e4..0000000 --- a/index.d.ts +++ /dev/null @@ -1,334 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* ndarray function. -* -* @param arrays - array containing input and output ndarrays -* @param data - ndarray function data (e.g., a callback) -* -* @example -* var numel = require( '@stdlib/ndarray-base-numel' ); -* var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -* -* function ndarrayFcn( arrays, fcn ) { -* var xord; -* var yord; -* var opts; -* var sub; -* var sh; -* var N; -* var x; -* var y; -* var v; -* var i; -* -* x = arrays[ 0 ]; -* y = arrays[ 1 ]; -* sh = x.shape; -* N = numel( sh ); -* if ( N <= 0 ) { -* return; -* } -* xord = x.order; -* yord = y.order; -* opts = {}; -* opts.order = xord; -* for ( i = 0; i < N; i++ ) { -* // Convert a linear index to subscripts: -* opts.order = xord; -* sub = ind2sub( sh, i, opts ); -* -* // Retrieve an element from `x`: -* v = x.get.apply( x, sub ); -* -* // Convert a linear index to subscripts: -* opts.order = yord; -* sub = ind2sub( sh, i, opts ); -* -* // Append the result of applying the callback: -* sub.push( fcn( v ) ); -* -* // Assign the result to an element in `y`: -* y.set.apply( y, sub ); -* } -* } -*/ -type ndarrayFcn = ( arrays: Array, data?: any ) => void; - -/** -* Interface describing an ndarray function dispatcher. -*/ -interface Dispatcher { - /** - * Invokes an ndarray function based on the provided array data type(s). - * - * @param x - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array - * - * @example - * var nullary = require( '@stdlib/ndarray-base-nullary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function value() { - * return 3.14; - * } - * - * var types = [ 'float64' ]; - * var data = [ value ]; - * - * var fcn = dispatch( nullary, types, data, 1, 0, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( 5 ); - * var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x ); - * // xbuf => [ 3.14, 3.14, 3.14, 3.14, 3.14 ] - */ - ( x: ndarray ): ndarray | void; - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var unary = require( '@stdlib/ndarray-base-unary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * var abs = require( '@stdlib/math-base-special-abs' ); - * - * var types = [ 'float64', 'float64' ]; - * var data = [ abs ]; - * - * var fcn = dispatch( unary, types, data, 2, 1, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - * var ybuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y ); - * // ybuf => [ 1.0, 2.0, 3.0 ] - */ - ( x: ndarray, y: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var ternary = require( '@stdlib/ndarray-base-ternary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function add2( x, y ) { - * return x + y; - * } - * - * var types = [ 'float64', 'float64', 'float64' ]; - * var data = [ add2 ]; - * - * var fcn = dispatch( ternary, types, data, 3, 2, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z ); - * // zbuf => [ 2.0, 4.0, 6.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quaternary = require( '@stdlib/ndarray-base-quaternary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function add3( x, y, z ) { - * return x + y + z; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add3 ]; - * - * var fcn = dispatch( quaternary, types, data, 4, 3, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w ); - * // wbuf => [ 3.0, 6.0, 9.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @param args - ndarray arguments - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quinary = require( '@stdlib/ndarray-base-quinary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function add4( x, y, z, w ) { - * return x + y + z + w; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add4 ]; - * - * var fcn = dispatch( quinary, types, data, 5, 4, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ubuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var u = ndarray( 'float64', ubuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w, u ); - * // ubuf => [ 4.0, 8.0, 12.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray, ...args: Array ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures -} - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param fcns - list of ndarray functions -* @param types - one-dimensional list of ndarray argument data types -* @param data - ndarray function data (e.g., callbacks) -* @param nargs - total number of ndarray function interface arguments -* @param nin - number of input ndarrays -* @param nout - number of output ndarrays -* @throws first argument must be either a function or an array of functions -* @throws second argument must be an array-like object -* @throws third argument must be an array-like object or `null` -* @throws third and first arguments must have the same number of elements -* @throws fourth argument must be a positive integer -* @throws fifth argument must be a nonnegative integer -* @throws sixth argument must be a nonnegative integer -* @throws fourth argument must equal the specified number of input and output arrays -* @throws number of types must match the number of functions times the total number of array arguments for each function -* @throws interface must accept at least one input and/or output ndarray -* @returns ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var fcn = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* fcn( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function dispatch( fcns: ndarrayFcn | ArrayLike, types: ArrayLike, data: ArrayLike | null, nargs: number, nin: number, nout: number ): Dispatcher; - - -// EXPORTS // - -export = dispatch; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index d8bef9e..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import{isPrimitive as t}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtypes2enums@esm/index.mjs";function f(f,l,p,w,v,a){var g,c,y;if(i(f))y=f;else if(!s(f))throw new TypeError(d("0jr5d",f));if(!n(l))throw new TypeError(d("0jr2y",l));if(!n(p)&&null!==p)throw new TypeError(d("0jr5e",p));if(!e(w))throw new TypeError(d("0jr5f",w));if(!r(v))throw new TypeError(d("0jr5X",v));if(!r(a))throw new TypeError(d("0jr5g",a));if(0===(g=v+a))throw new Error(d("0jr0h"));if(w!==g)throw new Error(d("0jr0i"));if(y){if(c=l.length/g,!t(c))throw new Error(d("0jr0j"))}else if(c=f.length,l.length!==c*g)throw new Error(d("0jr0j"));if(p&&p.length!==c)throw new Error(d("0jr0k"));return l=h(l),function(){var r,e,t,s,i,n,h;if(t=arguments.length,t!==w){if(t [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0jr5d', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0jr2y', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( '0jr5e', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0jr5f', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0jr5X', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0jr5g', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format('0jr0h') );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format('0jr0i') );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format('0jr0k') );\n\t}\n\ttypes = dtypes2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format('0jr0l') );\n\t\t\t}\n\t\t\tthrow new Error( format('0jr0m') );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( '0jr5h', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( '0jr5i', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = indexOfTypes( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format('0jr0n') );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Returns the first row index at which a given one-dimensional array of types can be found in a two-dimensional reference array of types (or `-1` if not found).\n*\n* ## Notes\n*\n* - The intended use case for this function is for type dispatch (i.e., given a set of array data types, find a matching interface according the interface's accepted array data types).\n* - The function assumes that `x` is stored in row-major order.\n* - The function assumes that the number of indexed elements in `y` equals the number of columns in `x`.\n* - The function returns a row index. To convert to a linear index, multiply `strideX1` by the return value.\n*\n* @private\n* @param {NonNegativeInteger} N - number of rows in `x` (size of first dimension)\n* @param {NonNegativeInteger} M - number of columns in `x` (size of second dimension)\n* @param {ArrayLikeObject} x - input two-dimensional reference array\n* @param {integer} strideX1 - `x` stride length along first dimension\n* @param {integer} strideX2 - `x` stride length along second dimension\n* @param {NonNegativeInteger} offsetX - `x` starting index\n* @param {ArrayLikeObject} y - search array\n* @param {integer} strideY - `y` stride length\n* @param {NonNegativeInteger} offsetY - `y` starting index\n* @returns {integer} row index (if found) and `-1` otherwise\n*\n* @example\n* // Define a reference array to search:\n* var types = [\n* 'float64', 'float64', 'float64',\n* 'float32', 'float32', 'float32',\n* 'uint32', 'uint32', 'float64',\n* 'int32', 'int32', 'float64',\n* 'uint16', 'uint16', 'float64',\n* 'int16', 'int16', 'float64',\n* 'uint8', 'uint8', 'float64',\n* 'int8', 'int8', 'float64'\n* ];\n*\n* // Define reference array dimensions:\n* var N = 8; // rows\n* var M = 3; // columns\n*\n* // Define a search array:\n* y1 = [\n* 'float32', 'float32', 'float32',\n* ];\n*\n* // Find the list of types:\n* var r1 = indexOfTypes( N, M, types, M, 1, 0, y1, 1, 0 );\n* // returns 1\n*\n// Define a search array:\n* y2 = [\n* 'float32', 'float32', 'float64',\n* ];\n*\n* // Find the list of types:\n* var r2 = indexOfTypes( N, M, types, M, 1, 0, y2, 1, 0 );\n* // returns -1\n*/\nfunction indexOfTypes( N, M, x, strideX1, strideX2, offsetX, y, strideY, offsetY ) { // eslint-disable-line max-len\n\tvar ix;\n\tvar iy;\n\tvar i;\n\tvar j;\n\n\t// Search for the first row which matches `y`...\n\tix = offsetX;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tiy = offsetY;\n\t\tfor ( j = 0; j < M; j++ ) {\n\t\t\tif ( x[ ix+(j*strideX2) ] !== y[ iy ] ) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tiy += strideY;\n\t\t}\n\t\t// If we successfully iterated over all columns, then that means we've found a match...\n\t\tif ( j === M ) {\n\t\t\treturn i;\n\t\t}\n\t\tix += strideX1;\n\t}\n\treturn -1;\n}\n\n\n// EXPORTS //\n\nexport default indexOfTypes;\n"],"names":["dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","dtypes2enums","arrays","dtypes","argc","idx","v","f","i","arguments","isndarrayLike","push","resolveEnum","getDType","N","M","x","strideX1","strideX2","offsetX","y","strideY","offsetY","ix","iy","j","indexOfTypes","slice"],"mappings":";;ukCAsFA,SAASA,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAO,UAEzB,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAO,UAEzB,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAO,eAIzB,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAO,UAG1B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAO,UAGzB,OADAX,EAAQkB,EAAclB,GAgBtB,WACC,IAAImB,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GADAJ,EAAOK,UAAUV,OACZK,IAASnB,EAAQ,CACrB,GAAKmB,EAAOnB,EACX,MAAM,IAAIa,MAAOJ,EAAO,UAEzB,MAAM,IAAII,MAAOJ,EAAO,SACxB,CAGD,IAFAQ,EAAS,GACTC,EAAS,GACHK,EAAI,EAAGA,EAAIvB,EAAOuB,IAAM,CAE7B,IAAME,EADNJ,EAAIG,UAAWD,IAEd,MAAKA,EAAItB,EACF,IAAIO,UAAWC,EAAQ,QAASY,IAEhC,IAAIb,UAAWC,EAAQ,QAASY,IAGxCJ,EAAOS,KAAML,GACbH,EAAOQ,KAAMC,EAAaC,EAAUP,IACpC,CAKD,IAHAD,ECtGF,SAAuBS,EAAGC,EAAGC,EAAGC,EAAUC,EAAUC,EAASC,EAAGC,EAASC,GACxE,IAAIC,EACAC,EACAhB,EACAiB,EAIJ,IADAF,EAAKJ,EACCX,EAAI,EAAGA,EAAIM,EAAGN,IAAM,CAEzB,IADAgB,EAAKF,EACCG,EAAI,EAAGA,EAAIV,GACXC,EAAGO,EAAIE,EAAEP,KAAgBE,EAAGI,GADdC,IAInBD,GAAMH,EAGP,GAAKI,IAAMV,EACV,OAAOP,EAERe,GAAMN,CACN,CACD,OAAQ,CACT,CD+EQS,CAAcrC,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGe,EAAQ,EAAG,IAG1D,EACV,MAAM,IAAIV,UAAWC,EAAO,UAI5Ba,EADIjB,GAGAR,EAAMuB,GAGNrB,EACJuB,EAAGL,EAAQlB,EAAMqB,IAEjBE,EAAGL,GAEJ,GAAc,IAATf,EACJ,OAAOe,EAAQd,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOe,EAAOyB,MAAOzC,EACrB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 2342a52..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From d7d0dab69a9519d278808f53f99a771ed78a01af Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 14 Sep 2025 10:00:02 +0000 Subject: [PATCH 106/109] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 199 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 259 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 61 +- SECURITY.md | 5 - benchmark/benchmark.dispatch_size.js | 156 - benchmark/benchmark.js | 81 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 87 - docs/types/test.ts | 615 --- examples/add.js | 121 - examples/sin.js | 142 - examples/unary.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/main.js | 211 - package.json | 81 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/binary.js | 38 - test/fixtures/fill.js | 76 - test/fixtures/foreach.js | 72 - test/fixtures/map1n.js | 74 - test/fixtures/nullary.js | 36 - test/fixtures/quaternary.js | 40 - test/fixtures/quinary.js | 41 - test/fixtures/sum.js | 98 - test/fixtures/ternary.js | 39 - test/test.js | 363 -- test/test.two_arrays.js | 814 --- 56 files changed, 4876 insertions(+), 6994 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.dispatch_size.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/add.js delete mode 100644 examples/sin.js delete mode 100644 examples/unary.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/fixtures/binary.js delete mode 100644 test/fixtures/fill.js delete mode 100644 test/fixtures/foreach.js delete mode 100644 test/fixtures/map1n.js delete mode 100644 test/fixtures/nullary.js delete mode 100644 test/fixtures/quaternary.js delete mode 100644 test/fixtures/quinary.js delete mode 100644 test/fixtures/sum.js delete mode 100644 test/fixtures/ternary.js delete mode 100644 test/test.js delete mode 100644 test/test.two_arrays.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 731bd4f..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/contributing/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 5e92c3e..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2b4fac7..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '43 7 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -304,7 +295,7 @@ console.log( ybuf ); ## 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. +This package is part of [stdlib][stdlib], a standard library 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]. @@ -367,11 +358,11 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-dispatch/main/LICENSE -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.dispatch_size.js b/benchmark/benchmark.dispatch_size.js deleted file mode 100644 index 15805ba..0000000 --- a/benchmark/benchmark.dispatch_size.js +++ /dev/null @@ -1,156 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib/main.js' ); - - -// FUNCTIONS // - -/** -* Evaluates the identity function. -* -* @private -* @param {*} v - value -* @returns {*} input value -*/ -function identity( v ) { - return v; -} - -/** -* Dummy function which throws an error. -* -* @private -* @throws {Error} unexpected error -*/ -function throwError() { - throw new Error( 'unexpected error' ); -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} size - dispatch size -* @returns {Function} benchmark function -*/ -function createBenchmark( size ) { - var types; - var data; - var fcn; - var x; - var y; - var t; - var i; - - types = []; - - // Create dummy types... - for ( i = 0; i < (size-1)*2; i += 2 ) { - t = 'foo' + i; - types.push( t ); - types.push( t ); - } - // Append test types: - types.push( 'float64' ); - types.push( 'float64' ); - - // Define a list of callbacks: - data = []; - for ( i = 0; i < size-1; i++ ) { - data.push( throwError ); - } - // Append a test callback: - data.push( identity ); - - // Create the dispatcher: - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - // Create sample arrays: - x = new Float64Array( 1 ); - y = new Float64Array( x.length ); - - x = ndarray( 'float64', x, [ 1 ], [ 1 ], 0, 'row-major' ); - y = ndarray( 'float64', y, [ 1 ], [ 1 ], 0, 'row-major' ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var z; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x.data[ 0 ] = i; - z = fcn( x, y ); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var size; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - size = pow( 2, i ); - f = createBenchmark( size ); - bench( pkg+':size='+size, f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 3c6f450..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::fcns_array', function benchmark( b ) { - var types; - var fcns; - var data; - var out; - var i; - - fcns = [ unary ]; - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( fcns, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::fcn_arg', function benchmark( b ) { - var types; - var data; - var out; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( unary, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0aae4af..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch" -%% click B href "https://github.com/stdlib-js/ndarray-dispatch/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-dispatch/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-dispatch/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-dispatch/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-dispatch/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch -[production-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 1295a44..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import dispatch from '../docs/types/index'; -export = dispatch; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 945d47d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var q=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var b=q(function(S,y){"use strict";var w=require("@stdlib/assert-is-nonnegative-integer").isPrimitive,T=require("@stdlib/assert-is-positive-integer"),V=require("@stdlib/assert-is-integer").isPrimitive,x=require("@stdlib/assert-is-function-array"),F=require("@stdlib/assert-is-function"),c=require("@stdlib/assert-is-collection"),I=require("@stdlib/assert-is-ndarray-like"),n=require("@stdlib/string-format"),k=require("@stdlib/ndarray-dtype"),j=require("@stdlib/ndarray-base-dtype-resolve-enum"),A=require("@stdlib/ndarray-base-dtypes2enums"),P=require("@stdlib/blas-ext-base-gindex-of-row").ndarray;function U(e,r,i,t,v,m){var a,u,d;if(F(e))d=e;else if(!x(e))throw new TypeError(n("invalid argument. First argument must be either a function or an array of functions. Value: `%s`.",e));if(!c(r))throw new TypeError(n("invalid argument. Second argument must be an array-like object. Value: `%s`.",r));if(!c(i)&&i!==null)throw new TypeError(n("invalid argument. Third argument must be an array-like object or null. Value: `%s`.",i));if(!T(t))throw new TypeError(n("invalid argument. Fourth argument must be a positive integer. Value: `%s`.",t));if(!w(v))throw new TypeError(n("invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.",v));if(!w(m))throw new TypeError(n("invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.",m));if(a=v+m,a===0)throw new Error("invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.");if(t!==a)throw new Error("invalid arguments. Fourth argument does not equal the number of input and output ndarrays.");if(d){if(u=r.length/a,!V(u))throw new Error("invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.")}else if(u=e.length,r.length!==u*a)throw new Error("invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.");if(i&&i.length!==u)throw new Error("invalid argument. The third argument must have the same number of elements as the first argument.");return r=A(r),E;function E(){var o,g,p,f,s,h,l;if(p=arguments.length,p!==t)throw p [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' );\n\t}\n\ttypes = dtypes2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( 'invalid invocation. Insufficient arguments.' );\n\t\t\t}\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = gindexOfRow( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 );\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = dispatch;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an ndarray function interface which performs multiple dispatch.\n*\n* @module @stdlib/ndarray-dispatch\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var unary = require( '@stdlib/ndarray-base-unary' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var Float64Array = require( '@stdlib/array-float64' );\n* var dispatch = require( '@stdlib/ndarray-dispatch' );\n*\n* var types = [\n* 'float64', 'float64'\n* ];\n*\n* var data = [\n* abs\n* ];\n*\n* var absolute = dispatch( unary, types, data, 2, 1, 1 );\n*\n* // ...\n*\n* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] );\n* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] );\n*\n* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' );\n* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' );\n*\n* absolute( x, y );\n* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAoB,QAAS,oCAAqC,EAClEC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAkB,QAAS,kCAAmC,EAC9DC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAc,QAAS,yCAA0C,EACjEC,EAAe,QAAS,mCAAoC,EAC5DC,EAAc,QAAS,qCAAsC,EAAE,QAqDnE,SAASC,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,EAAO,CACxD,IAAIC,EACAC,EACAC,EAEJ,GAAKjB,EAAYS,CAAK,EACrBQ,EAAMR,UACK,CAACV,EAAiBU,CAAK,EAClC,MAAM,IAAI,UAAWN,EAAQ,oGAAqGM,CAAK,CAAE,EAE1I,GAAK,CAACR,EAAcS,CAAM,EACzB,MAAM,IAAI,UAAWP,EAAQ,+EAAgFO,CAAM,CAAE,EAEtH,GAAK,CAACT,EAAcU,CAAK,GAAKA,IAAS,KACtC,MAAM,IAAI,UAAWR,EAAQ,sFAAuFQ,CAAK,CAAE,EAE5H,GAAK,CAACd,EAAmBe,CAAM,EAC9B,MAAM,IAAI,UAAWT,EAAQ,6EAA8ES,CAAM,CAAE,EAEpH,GAAK,CAAChB,EAAsBiB,CAAI,EAC/B,MAAM,IAAI,UAAWV,EAAQ,+EAAgFU,CAAI,CAAE,EAEpH,GAAK,CAACjB,EAAsBkB,CAAK,EAChC,MAAM,IAAI,UAAWX,EAAQ,+EAAgFW,CAAK,CAAE,EAGrH,GADAC,EAAUF,EAAMC,EACXC,IAAY,EAChB,MAAM,IAAI,MAAO,4IAA6I,EAE/J,GAAKH,IAAUG,EACd,MAAM,IAAI,MAAO,4FAA6F,EAE/G,GAAKE,GAEJ,GADAD,EAAQN,EAAM,OAASK,EAClB,CAACjB,EAAWkB,CAAM,EACtB,MAAM,IAAI,MAAO,8IAA+I,UAGjKA,EAAQP,EAAK,OACRC,EAAM,SAAWM,EAAMD,EAC3B,MAAM,IAAI,MAAO,8IAA+I,EAGlK,GAAKJ,GAAQA,EAAK,SAAWK,EAC5B,MAAM,IAAI,MAAO,mGAAoG,EAEtH,OAAAN,EAAQJ,EAAcI,CAAM,EACrBQ,EAeP,SAASA,GAAa,CACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GADAJ,EAAO,UAAU,OACZA,IAAST,EACb,MAAKS,EAAOT,EACL,IAAI,MAAO,6CAA8C,EAE1D,IAAI,MAAO,yCAA0C,EAI5D,IAFAO,EAAS,CAAC,EACVC,EAAS,CAAC,EACJK,EAAI,EAAGA,EAAIb,EAAOa,IAAM,CAE7B,GADAF,EAAI,UAAWE,CAAE,EACZ,CAACvB,EAAeqB,CAAE,EACtB,MAAKE,EAAIZ,EACF,IAAI,UAAWV,EAAQ,6EAA8EoB,CAAE,CAAE,EAEzG,IAAI,UAAWpB,EAAQ,8EAA+EoB,CAAE,CAAE,EAGlHJ,EAAO,KAAMI,CAAE,EACfH,EAAO,KAAMf,EAAaD,EAAUmB,CAAE,CAAE,CAAE,CAC3C,CAKA,GAHAD,EAAMf,EAAaS,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGK,EAAQ,EAAG,CAAE,EAGjEE,EAAM,EACV,MAAM,IAAI,UAAW,6GAA8G,EAcpI,GAXKL,EACJO,EAAIP,EAEJO,EAAIf,EAAMa,CAAI,EAGVX,EACJa,EAAGL,EAAQR,EAAMW,CAAI,CAAE,EAEvBE,EAAGL,CAAO,EAENL,IAAS,EACb,OAAOK,EAAQJ,EAAQ,CAAE,EAE1B,GAAKD,IAAS,EAGd,OAAOK,EAAO,MAAON,CAAI,CAC1B,CACD,CAKAlB,EAAO,QAAUa,IC1JjB,IAAIkB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isNonNegativeInteger", "isPositiveInteger", "isInteger", "isFunctionArray", "isFunction", "isCollection", "isndarrayLike", "format", "getDType", "resolveEnum", "dtypes2enums", "gindexOfRow", "dispatch", "fcns", "types", "data", "nargs", "nin", "nout", "narrays", "nfcns", "fcn", "dispatcher", "arrays", "dtypes", "argc", "idx", "v", "f", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 02fe150..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,87 +0,0 @@ - -{{alias}}( fcns, types, data, nargs, nin, nout ) - Returns an ndarray function interface which performs multiple dispatch. - - An ndarray function interface has the following signature: - - f( x, y, ... ) - - where - - - x: ndarray. - - y: ndarray. - - ...: additional ndarrays. - - The number of parameters is derived from `nargs`, the number of input - ndarrays is derived from `nin`, and the number of output ndarrays is derived - from `nout`. - - Parameters - ---------- - fcns: Function|ArrayLikeObject - List of ndarray functions. An ndarray function should have the following - signature: - - f( arrays, data ) - - where - - - arrays: array containing input and output ndarrays. - - data: ndarray function data (e.g., a callback). - - For convenience, a single ndarray function may be provided which will be - invoked whenever the ndarray argument data types match a sequence of - types in `types`. Providing a single ndarray function is particularly - convenient for the case where, regardless of array data types, - traversing arrays remains the same, but the ndarray function `data` - differs (e.g., callbacks which differ based on the array data types). - - types: ArrayLikeObject - One-dimensional list of ndarray argument data types. - - data: ArrayLikeObject|null - ndarray function data (e.g., callbacks). If `null`, a returned ndarray - function interface does **not** provide a `data` argument to an invoked - ndarray function. - - nargs: integer - Total number of ndarray function interface arguments. - - nin: integer - Number of input ndarrays. - - nout: integer - Number of output ndarrays. - - Returns - ------- - fcn: Function - ndarray function interface. - - Examples - -------- - // Define ndarray argument data types: - > var t = [ 'float64', 'float64', 'float32', 'float32' ]; - - // Define a list of ndarray function data (callbacks): - > var d = [ {{alias:@stdlib/math/base/special/abs}}, {{alias:@stdlib/math/base/special/absf}} ]; - - // Create an ndarray function interface for applying unary callbacks: - > var f = {{alias}}( {{alias:@stdlib/ndarray/base/unary}}, t, d, 2, 1, 1 ); - - // Create an input ndarray: - > var xbuf = new {{alias:@stdlib/array/float64}}( [ -1.0, -2.0, -3.0, -4.0 ] ); - > var x = {{alias:@stdlib/ndarray/ctor}}( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Create an output ndarray: - > var ybuf = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 0.0, 0.0 ] ); - > var y = {{alias:@stdlib/ndarray/ctor}}( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Compute the element-wise absolute value: - > f( x, y ); - > ybuf - [ 1.0, 2.0, 3.0, 4.0 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 3fece39..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,615 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable max-lines, prefer-const */ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import ind2sub = require( '@stdlib/ndarray-ind2sub' ); -import dispatch = require( './index' ); - - -// FUNCTIONS // - -/** -* Nullary callback. -* -* @returns input value -*/ -function nullary(): any { - return 5.0; -} - -/** -* Unary callback. -* -* @param x - input value -* @returns input value -*/ -function unary( x: any ): any { - return x; -} - -/** -* Binary callback. -* -* @param x - input value -* @param y - input value -* @returns output value -*/ -function binary( x: number, y: number ): number { - return x + y; -} - -/** -* Ternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @returns output value -*/ -function ternary( x: number, y: number, z: number ): number { - return x + y + z; -} - -/** -* Quaternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @param w - input value -* @returns output value -*/ -function quaternary( x: number, y: number, z: number, w: number ): number { - return x + y + z + w; -} - -/** -* Mock ndarray function. -* -* @param arrays - ndarrays -* @param fcn - callback -*/ -function ndarrayFcn( arrays: Array, fcn: ( x: any ) => any ): void { - let xord; - let yord; - let opts; - let sub; - let sh; - let N; - let x; - let y; - let v; - let i; - - x = arrays[ 0 ]; - y = arrays[ 1 ]; - sh = x.shape; - if ( sh.length === 0 ) { - return; - } - N = 1; - for ( i = 0; i < sh.length; i += 1 ) { - N *= sh[ i ]; - } - xord = x.order; - yord = y.order; - opts = { - 'order': xord - }; - for ( i = 0; i < N; i += 1 ) { - // Convert a linear index to subscripts: - opts.order = xord; - sub = ind2sub( sh, i, opts ); - - // Retrieve an element from `x`: - v = x.get.apply( x, sub ); - - // Convert a linear index to subscripts: - opts.order = yord; - sub = ind2sub( sh, i, opts ); - - // Append the result of applying the callback: - sub[ sub.length ] = fcn( v ) as number; - - // Assign the result to an element in `y`: - y.set.apply( y, sub ); - } -} - -/** -* Mock function to create an ndarray-like object. -* -* @returns ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a dispatch function... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, 1 ); // $ExpectType Dispatcher - dispatch( [ ndarrayFcn ], types, data, 2, 1, 1 ); // $ExpectType Dispatcher -} - -// The compiler throws an error if the function is provided a first argument which is not either an ndarray function or an array-like object containing ndarray functions... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( '10', types, data, 2, 1, 1 ); // $ExpectError - dispatch( 10, types, data, 2, 1, 1 ); // $ExpectError - dispatch( true, types, data, 2, 1, 1 ); // $ExpectError - dispatch( false, types, data, 2, 1, 1 ); // $ExpectError - dispatch( null, types, data, 2, 1, 1 ); // $ExpectError - dispatch( undefined, types, data, 2, 1, 1 ); // $ExpectError - dispatch( [ '1' ], types, data, 2, 1, 1 ); // $ExpectError - dispatch( {}, types, data, 2, 1, 1 ); // $ExpectError - dispatch( ( x: number ): number => x, types, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object... -{ - const data = [ unary ]; - - dispatch( ndarrayFcn, 10, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, true, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, false, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, null, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, undefined, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, {}, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object or null... -{ - const types = [ 'float64', 'float64' ]; - - dispatch( ndarrayFcn, types, 10, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, true, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, false, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, undefined, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, {}, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, '10', 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, true, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, false, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, null, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, undefined, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, [ '1' ], 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, {}, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, ( x: number ): number => x, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, '10', 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, true, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, false, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, null, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, undefined, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, [ '1' ], 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, {}, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, ( x: number ): number => x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, '10' ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, true ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, false ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, null ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, undefined ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, [ '1' ] ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, {} ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch(); // $ExpectError - dispatch( ndarrayFcn ); // $ExpectError - dispatch( ndarrayFcn, types ); // $ExpectError - dispatch( ndarrayFcn, types, data ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, 1, 0 ); // $ExpectError -} - -// The function returns a dispatch function... -{ - const x = array(); - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const t1 = [ 'float64' ]; - const d1 = [ nullary ]; - const f1 = dispatch( ndarrayFcn, t1, d1, 1, 1, 0 ); - f1( x ); // $ExpectType void | ndarray - - const t2 = [ 'float64', 'float64' ]; - const d2 = [ unary ]; - const f2 = dispatch( ndarrayFcn, t2, d2, 2, 1, 1 ); - f2( x, y ); // $ExpectType void | ndarray - - const t3 = [ 'float64', 'float64', 'float64' ]; - const d3 = [ binary ]; - const f3 = dispatch( ndarrayFcn, t3, d3, 3, 2, 1 ); - f3( x, y, z ); // $ExpectType void | ndarray - - const t4 = [ 'float64', 'float64', 'float64', 'float64' ]; - const d4 = [ ternary ]; - const f4 = dispatch( ndarrayFcn, t4, d4, 4, 3, 1 ); - f4( x, y, z, w ); // $ExpectType void | ndarray - - const t5 = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const d5 = [ quaternary ]; - const f5 = dispatch( ndarrayFcn, t5, d5, 5, 4, 1 ); - f5( x, y, z, w, u ); // $ExpectType void | ndarray -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (1 ndarray)... -{ - const types = [ 'float64' ]; - const data = [ nullary ]; - - const f = dispatch( ndarrayFcn, types, data, 1, 0, 1 ); - f( '10' ); // $ExpectError - f( 10 ); // $ExpectError - f( true ); // $ExpectError - f( false ); // $ExpectError - f( null ); // $ExpectError - f( undefined ); // $ExpectError - f( [ '1' ] ); // $ExpectError - f( {} ); // $ExpectError - f( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( 10, y ); // $ExpectError - f( '10', y ); // $ExpectError - f( true, y ); // $ExpectError - f( false, y ); // $ExpectError - f( null, y ); // $ExpectError - f( undefined, y ); // $ExpectError - f( [ '1' ], y ); // $ExpectError - f( {}, y ); // $ExpectError - f( ( x: number ): number => x, y ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const x = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( x, 10 ); // $ExpectError - f( x, '10' ); // $ExpectError - f( x, true ); // $ExpectError - f( x, false ); // $ExpectError - f( x, null ); // $ExpectError - f( x, undefined ); // $ExpectError - f( x, [ '1' ] ); // $ExpectError - f( x, {} ); // $ExpectError - f( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( 10, y, z ); // $ExpectError - f( '10', y, z ); // $ExpectError - f( true, y, z ); // $ExpectError - f( false, y, z ); // $ExpectError - f( null, y, z ); // $ExpectError - f( undefined, y, z ); // $ExpectError - f( [ '1' ], y, z ); // $ExpectError - f( {}, y, z ); // $ExpectError - f( ( x: number ): number => x, y, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, 10, z ); // $ExpectError - f( x, '10', z ); // $ExpectError - f( x, true, z ); // $ExpectError - f( x, false, z ); // $ExpectError - f( x, null, z ); // $ExpectError - f( x, undefined, z ); // $ExpectError - f( x, [ '1' ], z ); // $ExpectError - f( x, {}, z ); // $ExpectError - f( x, ( x: number ): number => x, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, y, '10' ); // $ExpectError - f( x, y, true ); // $ExpectError - f( x, y, false ); // $ExpectError - f( x, y, null ); // $ExpectError - f( x, y, undefined ); // $ExpectError - f( x, y, [ '1' ] ); // $ExpectError - f( x, y, {} ); // $ExpectError - f( x, y, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( 10, y, z, w ); // $ExpectError - f( '10', y, z, w ); // $ExpectError - f( true, y, z, w ); // $ExpectError - f( false, y, z, w ); // $ExpectError - f( null, y, z, w ); // $ExpectError - f( undefined, y, z, w ); // $ExpectError - f( [ '1' ], y, z, w ); // $ExpectError - f( {}, y, z, w ); // $ExpectError - f( ( x: number ): number => x, y, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, 10, z, w ); // $ExpectError - f( x, '10', z, w ); // $ExpectError - f( x, true, z, w ); // $ExpectError - f( x, false, z, w ); // $ExpectError - f( x, null, z, w ); // $ExpectError - f( x, undefined, z, w ); // $ExpectError - f( x, [ '1' ], z, w ); // $ExpectError - f( x, {}, z, w ); // $ExpectError - f( x, ( x: number ): number => x, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, 10, w ); // $ExpectError - f( x, y, '10', w ); // $ExpectError - f( x, y, true, w ); // $ExpectError - f( x, y, false, w ); // $ExpectError - f( x, y, null, w ); // $ExpectError - f( x, y, undefined, w ); // $ExpectError - f( x, y, [ '1' ], w ); // $ExpectError - f( x, y, {}, w ); // $ExpectError - f( x, y, ( x: number ): number => x, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, z, 10 ); // $ExpectError - f( x, y, z, '10' ); // $ExpectError - f( x, y, z, true ); // $ExpectError - f( x, y, z, false ); // $ExpectError - f( x, y, z, null ); // $ExpectError - f( x, y, z, undefined ); // $ExpectError - f( x, y, z, [ '1' ] ); // $ExpectError - f( x, y, z, {} ); // $ExpectError - f( x, y, z, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( 10, y, z, w, u ); // $ExpectError - f( '10', y, z, w, u ); // $ExpectError - f( true, y, z, w, u ); // $ExpectError - f( false, y, z, w, u ); // $ExpectError - f( null, y, z, w, u ); // $ExpectError - f( undefined, y, z, w, u ); // $ExpectError - f( [ '1' ], y, z, w, u ); // $ExpectError - f( {}, y, z, w, u ); // $ExpectError - f( ( x: number ): number => x, y, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, 10, z, w, u ); // $ExpectError - f( x, '10', z, w, u ); // $ExpectError - f( x, true, z, w, u ); // $ExpectError - f( x, false, z, w, u ); // $ExpectError - f( x, null, z, w, u ); // $ExpectError - f( x, undefined, z, w, u ); // $ExpectError - f( x, [ '1' ], z, w, u ); // $ExpectError - f( x, {}, z, w, u ); // $ExpectError - f( x, ( x: number ): number => x, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, 10, w, u ); // $ExpectError - f( x, y, '10', w, u ); // $ExpectError - f( x, y, true, w, u ); // $ExpectError - f( x, y, false, w, u ); // $ExpectError - f( x, y, null, w, u ); // $ExpectError - f( x, y, undefined, w, u ); // $ExpectError - f( x, y, [ '1' ], w, u ); // $ExpectError - f( x, y, {}, w, u ); // $ExpectError - f( x, y, ( x: number ): number => x, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, 10, u ); // $ExpectError - f( x, y, z, '10', u ); // $ExpectError - f( x, y, z, true, u ); // $ExpectError - f( x, y, z, false, u ); // $ExpectError - f( x, y, z, null, u ); // $ExpectError - f( x, y, z, undefined, u ); // $ExpectError - f( x, y, z, [ '1' ], u ); // $ExpectError - f( x, y, z, {}, u ); // $ExpectError - f( x, y, z, ( x: number ): number => x, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fifth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, w, 10 ); // $ExpectError - f( x, y, z, w, '10' ); // $ExpectError - f( x, y, z, w, true ); // $ExpectError - f( x, y, z, w, false ); // $ExpectError - f( x, y, z, w, null ); // $ExpectError - f( x, y, z, w, undefined ); // $ExpectError - f( x, y, z, w, [ '1' ] ); // $ExpectError - f( x, y, z, w, {} ); // $ExpectError - f( x, y, z, w, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/add.js b/examples/add.js deleted file mode 100644 index 775b711..0000000 --- a/examples/add.js +++ /dev/null @@ -1,121 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var dispatch = require( './../lib' ); - -function add2( arrays ) { - var opts; - var xo; - var yo; - var zo; - var sx; - var sy; - var sz; - var sh; - var N; - var x; - var y; - var z; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - z = arrays[ 2 ]; - xo = x.order; - yo = y.order; - zo = z.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - opts.order = yo; - sy = ind2sub( sh, i, opts ); - v = x.get.apply( x, sx ) + y.get.apply( y, sy ); - - opts.order = zo; - sz = ind2sub( sh, i, opts ); - sz.push( v ); - z.set.apply( z, sz ); - } -} - -var fcns = [ - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2 -]; - -var types = [ - dtypes.float64, dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.int32, dtypes.int32, - dtypes.uint32, dtypes.uint32, dtypes.uint32, - dtypes.int16, dtypes.int16, dtypes.int16, - dtypes.uint16, dtypes.uint16, dtypes.uint16, - dtypes.int8, dtypes.int8, dtypes.int8, - dtypes.uint8, dtypes.uint8, dtypes.uint8, - dtypes.uint8c, dtypes.uint8c, dtypes.uint8c -]; - -var add = dispatch( fcns, types, null, 3, 2, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var zbuf = new Float64Array( xbuf.length ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var z = ndarray( 'float64', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); - -xbuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -ybuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -zbuf = new Int32Array( xbuf.length ); - -x = ndarray( 'int32', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'int32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -z = ndarray( 'int32', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); diff --git a/examples/sin.js b/examples/sin.js deleted file mode 100644 index 8cd4871..0000000 --- a/examples/sin.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int8Array = require( '@stdlib/array-int8' ); -var sin = require( '@stdlib/math-base-special-sin' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/strided-dtypes' ); -var dispatch = require( './../lib' ); - -function apply( arrays, fcn ) { - var opts; - var xo; - var yo; - var sx; - var sy; - var sh; - var N; - var x; - var y; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - xo = x.order; - yo = y.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - v = fcn( x.get.apply( x, sx ) ); - - opts.order = yo; - sy = ind2sub( sh, i, opts ); - sy.push( v ); - y.set.apply( y, sy ); - } -} - -var fcns = [ - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply -]; - -var types = [ - dtypes.float64, dtypes.float64, - dtypes.float32, dtypes.float64, - dtypes.float32, dtypes.float32, - dtypes.int32, dtypes.float64, - dtypes.uint32, dtypes.float64, - dtypes.int16, dtypes.float64, - dtypes.int16, dtypes.float32, - dtypes.uint16, dtypes.float64, - dtypes.uint16, dtypes.float32, - dtypes.int8, dtypes.float64, - dtypes.int8, dtypes.float32, - dtypes.uint8, dtypes.float64, - dtypes.uint8, dtypes.float32, - dtypes.uint8c, dtypes.float64, - dtypes.uint8c, dtypes.float32 -]; - -var data = [ - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin -]; - -var sine = dispatch( fcns, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); - -xbuf = new Int8Array( [ 1, 2, 3, 4, 5 ] ); -ybuf = new Float32Array( xbuf.length ); - -x = ndarray( 'int8', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'float32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); diff --git a/examples/unary.js b/examples/unary.js deleted file mode 100644 index e9c3fb4..0000000 --- a/examples/unary.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -var unary = require( '@stdlib/ndarray-base-unary' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var dispatch = require( './../lib' ); - -var types = [ 'float64', 'float64' ]; - -var data = [ - abs -]; - -var absolute = dispatch( unary, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -absolute( x, y ); -console.log( ybuf ); -// => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 5f280a1..c49a4e4 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..fcc70b0 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtypes2enums@esm/index.mjs";import{ndarray as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/blas-ext-base-gindex-of-row@esm/index.mjs";function p(p,f,w,v,a,g){var c,y,b;if(i(p))b=p;else if(!t(p))throw new TypeError(d("0jr5d",p));if(!n(f))throw new TypeError(d("0jr2y",f));if(!n(w)&&null!==w)throw new TypeError(d("0jr5e",w));if(!e(v))throw new TypeError(d("0jr5f",v));if(!r(a))throw new TypeError(d("0jr5X",a));if(!r(g))throw new TypeError(d("0jr5g",g));if(0===(c=a+g))throw new Error(d("0jr0h"));if(v!==c)throw new Error(d("0jr0i"));if(b){if(y=f.length/c,!s(y))throw new Error(d("0jr0j"))}else if(y=p.length,f.length!==y*c)throw new Error(d("0jr0j"));if(w&&w.length!==y)throw new Error(d("0jr0k"));return f=h(f),function(){var r,e,s,t,i,n,h;if(s=arguments.length,s!==v){if(s [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0jr5d', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0jr2y', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( '0jr5e', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0jr5f', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0jr5X', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0jr5g', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format('0jr0h') );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format('0jr0i') );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format('0jr0k') );\n\t}\n\ttypes = dtypes2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format('0jr0l') );\n\t\t\t}\n\t\t\tthrow new Error( format('0jr0m') );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( '0jr5h', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( '0jr5i', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = gindexOfRow( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 );\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format('0jr0n') );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n"],"names":["dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","dtypes2enums","arrays","dtypes","argc","idx","v","f","i","arguments","isndarrayLike","push","resolveEnum","getDType","gindexOfRow","slice"],"mappings":";;irCAsFA,SAASA,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAO,UAEzB,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAO,UAEzB,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAO,eAIzB,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAO,UAG1B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAO,UAGzB,OADAX,EAAQkB,EAAclB,GAgBtB,WACC,IAAImB,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GADAJ,EAAOK,UAAUV,OACZK,IAASnB,EAAQ,CACrB,GAAKmB,EAAOnB,EACX,MAAM,IAAIa,MAAOJ,EAAO,UAEzB,MAAM,IAAII,MAAOJ,EAAO,SACxB,CAGD,IAFAQ,EAAS,GACTC,EAAS,GACHK,EAAI,EAAGA,EAAIvB,EAAOuB,IAAM,CAE7B,IAAME,EADNJ,EAAIG,UAAWD,IAEd,MAAKA,EAAItB,EACF,IAAIO,UAAWC,EAAQ,QAASY,IAEhC,IAAIb,UAAWC,EAAQ,QAASY,IAGxCJ,EAAOS,KAAML,GACbH,EAAOQ,KAAMC,EAAaC,EAAUP,IACpC,CAKD,IAHAD,EAAMS,EAAazB,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGe,EAAQ,EAAG,IAGzD,EACV,MAAM,IAAIV,UAAWC,EAAO,UAI5Ba,EADIjB,GAGAR,EAAMuB,GAGNrB,EACJuB,EAAGL,EAAQlB,EAAMqB,IAEjBE,EAAGL,GAEJ,GAAc,IAATf,EACJ,OAAOe,EAAQd,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOe,EAAOa,MAAO7B,EACrB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 88f0e3e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Create an ndarray function interface which performs multiple dispatch. -* -* @module @stdlib/ndarray-dispatch -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var dispatch = require( '@stdlib/ndarray-dispatch' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c8b8f74..0000000 --- a/lib/main.js +++ /dev/null @@ -1,211 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isFunctionArray = require( '@stdlib/assert-is-function-array' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var resolveEnum = require( '@stdlib/ndarray-base-dtype-resolve-enum' ); -var dtypes2enums = require( '@stdlib/ndarray-base-dtypes2enums' ); -var gindexOfRow = require( '@stdlib/blas-ext-base-gindex-of-row' ).ndarray; - - -// MAIN // - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param {(FunctionArray|Function)} fcns - list of ndarray functions -* @param {Collection} types - one-dimensional list of ndarray argument data types -* @param {(Collection|null)} data - ndarray function data (e.g., callbacks) -* @param {PositiveInteger} nargs - total number of ndarray function interface arguments -* @param {NonNegativeInteger} nin - number of input ndarrays -* @param {NonNegativeInteger} nout - number of output ndarrays -* @throws {TypeError} first argument must be either a function or an array of functions -* @throws {TypeError} second argument must be an array-like object -* @throws {TypeError} third argument must be an array-like object or `null` -* @throws {Error} third and first arguments must have the same number of elements -* @throws {TypeError} fourth argument must be a positive integer -* @throws {TypeError} fifth argument must be a nonnegative integer -* @throws {TypeError} sixth argument must be a nonnegative integer -* @throws {Error} fourth argument must equal the specified number of input and output arrays -* @throws {Error} number of types must match the number of functions times the total number of array arguments for each function -* @throws {Error} interface must accept at least one input and/or output ndarray -* @returns {Function} ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function dispatch( fcns, types, data, nargs, nin, nout ) { - var narrays; - var nfcns; - var fcn; - - if ( isFunction( fcns ) ) { - fcn = fcns; - } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( '0jr5d', fcns ) ); - } - if ( !isCollection( types ) ) { - throw new TypeError( format( '0jr2y', types ) ); - } - if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( '0jr5e', data ) ); - } - if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( '0jr5f', nargs ) ); - } - if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( '0jr5X', nin ) ); - } - if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( '0jr5g', nout ) ); - } - narrays = nin + nout; - if ( narrays === 0 ) { - throw new Error( format('0jr0h') ); - } - if ( nargs !== narrays ) { - throw new Error( format('0jr0i') ); - } - if ( fcn ) { - nfcns = types.length / narrays; - if ( !isInteger( nfcns ) ) { - throw new Error( format('0jr0j') ); - } - } else { - nfcns = fcns.length; - if ( types.length !== nfcns*narrays ) { - throw new Error( format('0jr0j') ); - } - } - if ( data && data.length !== nfcns ) { - throw new Error( format('0jr0k') ); - } - types = dtypes2enums( types ); - return dispatcher; - - /** - * ndarray function interface which performs multiple dispatch. - * - * @private - * @param {ndarrayLike} x - ndarray - * @param {...ndarrayLike} args - ndarray arguments - * @throws {Error} insufficient arguments - * @throws {Error} too many arguments - * @throws {TypeError} input array arguments must be ndarray-like objects - * @throws {TypeError} output array arguments must be ndarray-like objects - * @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types - * @returns {(ndarrayLike|Array|void)} destination array(s) - */ - function dispatcher() { - var arrays; - var dtypes; - var argc; - var idx; - var v; - var f; - var i; - - argc = arguments.length; - if ( argc !== nargs ) { - if ( argc < nargs ) { - throw new Error( format('0jr0l') ); - } - throw new Error( format('0jr0m') ); - } - arrays = []; - dtypes = []; - for ( i = 0; i < nargs; i++ ) { - v = arguments[ i ]; - if ( !isndarrayLike( v ) ) { - if ( i < nin ) { - throw new TypeError( format( '0jr5h', v ) ); - } else { - throw new TypeError( format( '0jr5i', v ) ); - } - } - arrays.push( v ); - dtypes.push( resolveEnum( getDType( v ) ) ); - } - // Resolve the ndarray function satisfying the input array types: - idx = gindexOfRow( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); - - // Check whether we were able to successfully resolve an ndarray function: - if ( idx < 0 ) { - throw new TypeError( format('0jr0n') ); - } - // Retrieve the ndarray function: - if ( fcn ) { - f = fcn; - } else { - f = fcns[ idx ]; - } - // Evaluate the ndarray function: - if ( data ) { - f( arrays, data[ idx ] ); - } else { - f( arrays ); - } - if ( nout === 1 ) { - return arrays[ narrays-1 ]; - } - if ( nout === 0 ) { - return; - } - return arrays.slice( nin ); - } -} - - -// EXPORTS // - -module.exports = dispatch; diff --git a/package.json b/package.json index 1713c63..e6c8bad 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Create an ndarray function interface which performs multiple dispatch.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,59 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-function-array": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer": "^0.2.2", - "@stdlib/assert-is-positive-integer": "^0.2.2", - "@stdlib/blas-ext-base-gindex-of-row": "github:stdlib-js/blas-ext-base-gindex-of-row#main", - "@stdlib/ndarray-base-dtype-resolve-enum": "^0.2.2", - "@stdlib/ndarray-base-dtypes2enums": "github:stdlib-js/ndarray-base-dtypes2enums#main", - "@stdlib/ndarray-dtype": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.2.2", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/array-int8": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/math-base-assert-is-nan": "^0.2.2", - "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/math-base-special-pow": "^0.3.0", - "@stdlib/math-base-special-sin": "^0.3.0", - "@stdlib/ndarray-base-buffer-dtype": "^0.3.0", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-unary": "^0.2.1", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-dtypes": "^0.3.0", - "@stdlib/ndarray-ind2sub": "^0.2.2", - "@stdlib/strided-dtypes": "^0.3.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "ndarray", @@ -102,7 +26,6 @@ "multimethod", "multimethods" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..c6e4370 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/fixtures/binary.js b/test/fixtures/binary.js deleted file mode 100644 index a60dfa2..0000000 --- a/test/fixtures/binary.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Binary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @returns {number} sum -*/ -function binary( x, y ) { - return x + y; -} - - -// EXPORTS // - -module.exports = binary; diff --git a/test/fixtures/fill.js b/test/fixtures/fill.js deleted file mode 100644 index 41b2958..0000000 --- a/test/fixtures/fill.js +++ /dev/null @@ -1,76 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which fills one or more ndarrays. -* -* @private -* @param {*} value - fill value -* @returns {Function} ndarray function -*/ -function fill( value ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - */ - function ndarrayFcn( arrays ) { - var opts; - var sub; - var arr; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - opts = { - 'order': '' - }; - for ( j = 0; j < M; j++ ) { - arr = arrays[ j ]; - opts.order = arrays[ j ].order; - for ( i = 0; i < N; i++ ) { - sub = ind2sub( sh, i, opts ); - sub.push( value ); - arr.set.apply( arr, sub ); - } - } - } -} - - -// EXPORTS // - -module.exports = fill; diff --git a/test/fixtures/foreach.js b/test/fixtures/foreach.js deleted file mode 100644 index a426290..0000000 --- a/test/fixtures/foreach.js +++ /dev/null @@ -1,72 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function forEach( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - fcn.apply( null, args ); - } -} - - -// EXPORTS // - -module.exports = forEach; diff --git a/test/fixtures/map1n.js b/test/fixtures/map1n.js deleted file mode 100644 index 614196b..0000000 --- a/test/fixtures/map1n.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function which maps the return value of a callback to `N` arrays. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function map1N( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var v; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - v = fcn(); - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - sub.push( v ); - arrays[ j ].set.apply( arrays[ j ], sub ); - } - } -} - - -// EXPORTS // - -module.exports = map1N; diff --git a/test/fixtures/nullary.js b/test/fixtures/nullary.js deleted file mode 100644 index 4f22126..0000000 --- a/test/fixtures/nullary.js +++ /dev/null @@ -1,36 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Nullary callback. -* -* @private -* @returns {number} value -*/ -function nullary() { - return 3.0; -} - - -// EXPORTS // - -module.exports = nullary; diff --git a/test/fixtures/quaternary.js b/test/fixtures/quaternary.js deleted file mode 100644 index 548437b..0000000 --- a/test/fixtures/quaternary.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quaternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @returns {number} sum -*/ -function quaternary( x, y, z, w ) { - return x + y + z + w; -} - - -// EXPORTS // - -module.exports = quaternary; diff --git a/test/fixtures/quinary.js b/test/fixtures/quinary.js deleted file mode 100644 index 36068de..0000000 --- a/test/fixtures/quinary.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quinary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @param {number} u - input value -* @returns {number} sum -*/ -function quinary( x, y, z, w, u ) { - return x + y + z + w + u; -} - - -// EXPORTS // - -module.exports = quinary; diff --git a/test/fixtures/sum.js b/test/fixtures/sum.js deleted file mode 100644 index efdbb1b..0000000 --- a/test/fixtures/sum.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which computes the sum across one or more ndarrays. -* -* @private -* @param {Object} ctx - context -* @param {number} ctx.sum - initial sum -* @returns {Function} ndarray function -*/ -function wrapper( ctx ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - * @param {Function} [fcn] - callback - */ - function ndarrayFcn( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var f; - var i; - var j; - - if ( arguments.length > 1 ) { - f = fcn; - } - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - if ( f ) { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - ctx.sum += f.apply( null, args ); - } - } else { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - ctx.sum += arrays[ j ].get.apply( arrays[ j ], sub ); - } - } - } - } -} - - -// EXPORTS // - -module.exports = wrapper; diff --git a/test/fixtures/ternary.js b/test/fixtures/ternary.js deleted file mode 100644 index 0595d5f..0000000 --- a/test/fixtures/ternary.js +++ /dev/null @@ -1,39 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Ternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @returns {number} sum -*/ -function ternary( x, y, z ) { - return x + y + z; -} - - -// EXPORTS // - -module.exports = ternary; diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d6c2c8e..0000000 --- a/test/test.js +++ /dev/null @@ -1,363 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var fill = require( './fixtures/fill.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either a function or an array of functions as a first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( value, types, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object as a second argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided either an array-like object or `null` as a third argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - dispatch( unary, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a positive integer for a fourth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 0, - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a fifth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, value, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a sixth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, 1, value ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function array)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var fcns = [ unary, unary, unary ]; - var data = [ abs, abs, abs ]; - dispatch( fcns, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function argument)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs, abs, abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the length of `data` argument does not match the number of ndarray functions', function test( t ) { - var values; - var i; - - values = [ - [], - [ abs, abs ], - [ abs, abs, abs ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var fcns = [ unary ]; - dispatch( fcns, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the fourth argument is incompatible with the number of input and output ndarrays', function test( t ) { - var values; - var i; - - values = [ - 0, - 1, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of specified input and output ndarrays is zero', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var types = [ 'float64' ]; - dispatch( fill( 3 ), types, null, 1, 0, 0 ); - } -}); - -tape( 'the function returns an ndarray function interface', function test( t ) { - var types; - var data; - var f; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - f = dispatch( unary, types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ unary ], types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( fill( 3 ), types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ fill( 3 ) ], types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.two_arrays.js b/test/test.two_arrays.js deleted file mode 100644 index 16eb61b..0000000 --- a/test/test.two_arrays.js +++ /dev/null @@ -1,814 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var dtype = require( '@stdlib/ndarray-base-buffer-dtype' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var forEach = require( './fixtures/foreach.js' ); -var map1N = require( './fixtures/map1n.js' ); -var fill = require( './fixtures/fill.js' ); -var sum = require( './fixtures/sum.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the first argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var ybuf = new Float64Array( 10 ); - var y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( value, y ); - }; - } -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the second argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var xbuf = new Float64Array( 10 ); - var x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( x, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided insufficient arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var f; - var x; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [], - [ x ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided too many arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var ybuf; - var f; - var x; - var y; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [ x, y, y ], - [ x, y, y, y ], - [ x, y, y, y, y ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if unable to resolve a ndarray function supporting the provided array argument data types', function test( t ) { - var values; - var types; - var data; - var xbuf; - var fcn; - var x; - var i; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ abs, abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 4 ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - values = [ - new Uint8Array( 4 ), - new Int32Array( 4 ), - [ 0, 0, 0, 0 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided an array having data type: ' + dtype( values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var y = ndarray( dtype( value ), value, [ value.length ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - }; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only input arrays)', function test( t ) { - var types; - var xbuf; - var ybuf; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only output arrays)', function test( t ) { - var expected; - var types; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only input arrays)', function test( t ) { - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var ctx; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcns = [ - sum( ctx ), - sum( ctx ) - ]; - fcn = dispatch( fcns, types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only output arrays)', function test( t ) { - var expected; - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcns = [ - fill( 3.0 ), - fill( 4.0 ) - ]; - fcn = dispatch( fcns, types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - - fcn = dispatch( forEach, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - - fcn = dispatch( map1N, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - fcns = [ - forEach, - forEach - ]; - fcn = dispatch( fcns, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - fcns = [ - map1N, - map1N - ]; - fcn = dispatch( fcns, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - fcns = [ - unary, - unary - ]; - fcn = dispatch( fcns, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which returns one or more output arrays, if one or more output arrays is specified, and otherwise returns `undefined`', function test( t ) { - var types; - var data; - var xbuf; - var ybuf; - var out; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - // No output arrays... - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, void 0, 'returns expected value' ); - - // One output array... - data = [ - abs, - abs - ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - fcn = dispatch( fill( 3.0 ), types, null, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - // Two output arrays... - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.end(); -}); From f0f383dbd095ebf4a29b1fae8e8c60312afac331 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 21 Sep 2025 09:27:31 +0000 Subject: [PATCH 107/109] Transform error messages --- lib/main.js | 34 +++++++++++++++++----------------- package.json | 2 +- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/main.js b/lib/main.js index 29d8984..c8b8f74 100644 --- a/lib/main.js +++ b/lib/main.js @@ -27,7 +27,7 @@ var isFunctionArray = require( '@stdlib/assert-is-function-array' ); var isFunction = require( '@stdlib/assert-is-function' ); var isCollection = require( '@stdlib/assert-is-collection' ); var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var getDType = require( '@stdlib/ndarray-dtype' ); var resolveEnum = require( '@stdlib/ndarray-base-dtype-resolve-enum' ); var dtypes2enums = require( '@stdlib/ndarray-base-dtypes2enums' ); @@ -92,43 +92,43 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { if ( isFunction( fcns ) ) { fcn = fcns; } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) ); + throw new TypeError( format( '0jr5d', fcns ) ); } if ( !isCollection( types ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) ); + throw new TypeError( format( '0jr2y', types ) ); } if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) ); + throw new TypeError( format( '0jr5e', data ) ); } if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) ); + throw new TypeError( format( '0jr5f', nargs ) ); } if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) ); + throw new TypeError( format( '0jr5X', nin ) ); } if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) ); + throw new TypeError( format( '0jr5g', nout ) ); } narrays = nin + nout; if ( narrays === 0 ) { - throw new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' ); + throw new Error( format('0jr0h') ); } if ( nargs !== narrays ) { - throw new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' ); + throw new Error( format('0jr0i') ); } if ( fcn ) { nfcns = types.length / narrays; if ( !isInteger( nfcns ) ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format('0jr0j') ); } } else { nfcns = fcns.length; if ( types.length !== nfcns*narrays ) { - throw new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' ); + throw new Error( format('0jr0j') ); } } if ( data && data.length !== nfcns ) { - throw new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' ); + throw new Error( format('0jr0k') ); } types = dtypes2enums( types ); return dispatcher; @@ -158,9 +158,9 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { argc = arguments.length; if ( argc !== nargs ) { if ( argc < nargs ) { - throw new Error( 'invalid invocation. Insufficient arguments.' ); + throw new Error( format('0jr0l') ); } - throw new Error( 'invalid invocation. Too many arguments.' ); + throw new Error( format('0jr0m') ); } arrays = []; dtypes = []; @@ -168,9 +168,9 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { v = arguments[ i ]; if ( !isndarrayLike( v ) ) { if ( i < nin ) { - throw new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) ); + throw new TypeError( format( '0jr5h', v ) ); } else { - throw new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) ); + throw new TypeError( format( '0jr5i', v ) ); } } arrays.push( v ); @@ -181,7 +181,7 @@ function dispatch( fcns, types, data, nargs, nin, nout ) { // Check whether we were able to successfully resolve an ndarray function: if ( idx < 0 ) { - throw new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' ); + throw new TypeError( format('0jr0n') ); } // Retrieve the ndarray function: if ( fcn ) { diff --git a/package.json b/package.json index 0d34d20..db19487 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@stdlib/ndarray-base-dtype-resolve-enum": "^0.2.2", "@stdlib/ndarray-base-dtypes2enums": "github:stdlib-js/ndarray-base-dtypes2enums#main", "@stdlib/ndarray-dtype": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 597286ad7620fbbd29f66bc22b72fa24d964b0d8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 21 Sep 2025 09:32:07 +0000 Subject: [PATCH 108/109] Remove files --- index.d.ts | 334 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5181 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index c49a4e4..0000000 --- a/index.d.ts +++ /dev/null @@ -1,334 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* ndarray function. -* -* @param arrays - array containing input and output ndarrays -* @param data - ndarray function data (e.g., a callback) -* -* @example -* var numel = require( '@stdlib/ndarray-base-numel' ); -* var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -* -* function ndarrayFcn( arrays, fcn ) { -* var xord; -* var yord; -* var opts; -* var sub; -* var sh; -* var N; -* var x; -* var y; -* var v; -* var i; -* -* x = arrays[ 0 ]; -* y = arrays[ 1 ]; -* sh = x.shape; -* N = numel( sh ); -* if ( N <= 0 ) { -* return; -* } -* xord = x.order; -* yord = y.order; -* opts = {}; -* opts.order = xord; -* for ( i = 0; i < N; i++ ) { -* // Convert a linear index to subscripts: -* opts.order = xord; -* sub = ind2sub( sh, i, opts ); -* -* // Retrieve an element from `x`: -* v = x.get.apply( x, sub ); -* -* // Convert a linear index to subscripts: -* opts.order = yord; -* sub = ind2sub( sh, i, opts ); -* -* // Append the result of applying the callback: -* sub.push( fcn( v ) ); -* -* // Assign the result to an element in `y`: -* y.set.apply( y, sub ); -* } -* } -*/ -type ndarrayFcn = ( arrays: Array, data?: any ) => void; - -/** -* Interface describing an ndarray function dispatcher. -*/ -interface Dispatcher { - /** - * Invokes an ndarray function based on the provided array data type(s). - * - * @param x - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array - * - * @example - * var nullary = require( '@stdlib/ndarray-base-nullary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function value() { - * return 3.14; - * } - * - * var types = [ 'float64' ]; - * var data = [ value ]; - * - * var fcn = dispatch( nullary, types, data, 1, 0, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( 5 ); - * var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x ); - * // xbuf => [ 3.14, 3.14, 3.14, 3.14, 3.14 ] - */ - ( x: ndarray ): ndarray | void; - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var unary = require( '@stdlib/ndarray-base-unary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * var abs = require( '@stdlib/math-base-special-abs' ); - * - * var types = [ 'float64', 'float64' ]; - * var data = [ abs ]; - * - * var fcn = dispatch( unary, types, data, 2, 1, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - * var ybuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y ); - * // ybuf => [ 1.0, 2.0, 3.0 ] - */ - ( x: ndarray, y: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var ternary = require( '@stdlib/ndarray-base-ternary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function add2( x, y ) { - * return x + y; - * } - * - * var types = [ 'float64', 'float64', 'float64' ]; - * var data = [ add2 ]; - * - * var fcn = dispatch( ternary, types, data, 3, 2, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z ); - * // zbuf => [ 2.0, 4.0, 6.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quaternary = require( '@stdlib/ndarray-base-quaternary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function add3( x, y, z ) { - * return x + y + z; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add3 ]; - * - * var fcn = dispatch( quaternary, types, data, 4, 3, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w ); - * // wbuf => [ 3.0, 6.0, 9.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures - - /** - * Invokes an ndarray function based on the provided array data types. - * - * @param x - ndarray - * @param y - ndarray - * @param z - ndarray - * @param w - ndarray - * @param args - ndarray arguments - * @throws input array arguments must be ndarray-like objects - * @throws output array arguments must be ndarray-like objects - * @throws unable to resolve an ndarray function supporting the provided array argument data types - * @returns destination array(s) - * - * @example - * var quinary = require( '@stdlib/ndarray-base-quinary' ); - * var Float64Array = require( '@stdlib/array-float64' ); - * var ndarray = require( '@stdlib/ndarray-ctor' ); - * - * function add4( x, y, z, w ) { - * return x + y + z + w; - * } - * - * var types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - * var data = [ add4 ]; - * - * var fcn = dispatch( quinary, types, data, 5, 4, 1 ); - * - * // ... - * - * var xbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ybuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var zbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var wbuf = new Float64Array( [ 1.0, 2.0, 3.0 ] ); - * var ubuf = new Float64Array( xbuf.length ); - * - * var x = ndarray( 'float64', xbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var y = ndarray( 'float64', ybuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var z = ndarray( 'float64', zbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var w = ndarray( 'float64', wbuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * var u = ndarray( 'float64', ubuf, [ 3 ], [ 1 ], 0, 'row-major' ); - * - * fcn( x, y, z, w, u ); - * // ubuf => [ 4.0, 8.0, 12.0 ] - */ - ( x: ndarray, y: ndarray, z: ndarray, w: ndarray, ...args: Array ): ndarray | void; // eslint-disable-line @typescript-eslint/unified-signatures -} - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param fcns - list of ndarray functions -* @param types - one-dimensional list of ndarray argument data types -* @param data - ndarray function data (e.g., callbacks) -* @param nargs - total number of ndarray function interface arguments -* @param nin - number of input ndarrays -* @param nout - number of output ndarrays -* @throws first argument must be either a function or an array of functions -* @throws second argument must be an array-like object -* @throws third argument must be an array-like object or `null` -* @throws third and first arguments must have the same number of elements -* @throws fourth argument must be a positive integer -* @throws fifth argument must be a nonnegative integer -* @throws sixth argument must be a nonnegative integer -* @throws fourth argument must equal the specified number of input and output arrays -* @throws number of types must match the number of functions times the total number of array arguments for each function -* @throws interface must accept at least one input and/or output ndarray -* @returns ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var fcn = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* fcn( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -declare function dispatch( fcns: ndarrayFcn | ArrayLike, types: ArrayLike, data: ArrayLike | null, nargs: number, nin: number, nout: number ): Dispatcher; - - -// EXPORTS // - -export = dispatch; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index fcc70b0..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtypes2enums@esm/index.mjs";import{ndarray as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/blas-ext-base-gindex-of-row@esm/index.mjs";function p(p,f,w,v,a,g){var c,y,b;if(i(p))b=p;else if(!t(p))throw new TypeError(d("0jr5d",p));if(!n(f))throw new TypeError(d("0jr2y",f));if(!n(w)&&null!==w)throw new TypeError(d("0jr5e",w));if(!e(v))throw new TypeError(d("0jr5f",v));if(!r(a))throw new TypeError(d("0jr5X",a));if(!r(g))throw new TypeError(d("0jr5g",g));if(0===(c=a+g))throw new Error(d("0jr0h"));if(v!==c)throw new Error(d("0jr0i"));if(b){if(y=f.length/c,!s(y))throw new Error(d("0jr0j"))}else if(y=p.length,f.length!==y*c)throw new Error(d("0jr0j"));if(w&&w.length!==y)throw new Error(d("0jr0k"));return f=h(f),function(){var r,e,s,t,i,n,h;if(s=arguments.length,s!==v){if(s [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0jr5d', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0jr2y', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( '0jr5e', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0jr5f', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0jr5X', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0jr5g', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format('0jr0h') );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format('0jr0i') );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format('0jr0k') );\n\t}\n\ttypes = dtypes2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format('0jr0l') );\n\t\t\t}\n\t\t\tthrow new Error( format('0jr0m') );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( '0jr5h', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( '0jr5i', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = gindexOfRow( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 );\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format('0jr0n') );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n"],"names":["dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","dtypes2enums","arrays","dtypes","argc","idx","v","f","i","arguments","isndarrayLike","push","resolveEnum","getDType","gindexOfRow","slice"],"mappings":";;irCAsFA,SAASA,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAO,UAEzB,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAO,UAEzB,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAO,eAIzB,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAO,UAG1B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAO,UAGzB,OADAX,EAAQkB,EAAclB,GAgBtB,WACC,IAAImB,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GADAJ,EAAOK,UAAUV,OACZK,IAASnB,EAAQ,CACrB,GAAKmB,EAAOnB,EACX,MAAM,IAAIa,MAAOJ,EAAO,UAEzB,MAAM,IAAII,MAAOJ,EAAO,SACxB,CAGD,IAFAQ,EAAS,GACTC,EAAS,GACHK,EAAI,EAAGA,EAAIvB,EAAOuB,IAAM,CAE7B,IAAME,EADNJ,EAAIG,UAAWD,IAEd,MAAKA,EAAItB,EACF,IAAIO,UAAWC,EAAQ,QAASY,IAEhC,IAAIb,UAAWC,EAAQ,QAASY,IAGxCJ,EAAOS,KAAML,GACbH,EAAOQ,KAAMC,EAAaC,EAAUP,IACpC,CAKD,IAHAD,EAAMS,EAAazB,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGe,EAAQ,EAAG,IAGzD,EACV,MAAM,IAAIV,UAAWC,EAAO,UAI5Ba,EADIjB,GAGAR,EAAMuB,GAGNrB,EACJuB,EAAGL,EAAQlB,EAAMqB,IAEjBE,EAAGL,GAEJ,GAAc,IAATf,EACJ,OAAOe,EAAQd,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOe,EAAOa,MAAO7B,EACrB,CACF"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index c6e4370..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 3ecd03f9f8c9be6cb08f895fd7310c99d5445f4f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 21 Sep 2025 09:32:40 +0000 Subject: [PATCH 109/109] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 199 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 261 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 61 +- SECURITY.md | 5 - benchmark/benchmark.dispatch_size.js | 156 - benchmark/benchmark.js | 81 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 19 - dist/index.js.map | 7 - docs/repl.txt | 87 - docs/types/test.ts | 615 --- examples/add.js | 121 - examples/sin.js | 142 - examples/unary.js | 43 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/index.js | 62 - lib/main.js | 211 - package.json | 80 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/fixtures/binary.js | 38 - test/fixtures/fill.js | 76 - test/fixtures/foreach.js | 72 - test/fixtures/map1n.js | 74 - test/fixtures/nullary.js | 36 - test/fixtures/quaternary.js | 40 - test/fixtures/quinary.js | 41 - test/fixtures/sum.js | 98 - test/fixtures/ternary.js | 39 - test/test.js | 363 -- test/test.two_arrays.js | 814 --- 56 files changed, 4876 insertions(+), 6995 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.dispatch_size.js delete mode 100644 benchmark/benchmark.js delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/add.js delete mode 100644 examples/sin.js delete mode 100644 examples/unary.js rename docs/types/index.d.ts => index.d.ts (99%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/index.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/fixtures/binary.js delete mode 100644 test/fixtures/fill.js delete mode 100644 test/fixtures/foreach.js delete mode 100644 test/fixtures/map1n.js delete mode 100644 test/fixtures/nullary.js delete mode 100644 test/fixtures/quaternary.js delete mode 100644 test/fixtures/quinary.js delete mode 100644 test/fixtures/sum.js delete mode 100644 test/fixtures/ternary.js delete mode 100644 test/test.js delete mode 100644 test/test.two_arrays.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 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. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 731bd4f..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/contributing/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 5e92c3e..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2b4fac7..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '43 7 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -304,7 +295,7 @@ console.log( ybuf ); ## 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. +This package is part of [stdlib][stdlib], a standard library 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]. @@ -367,11 +358,11 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-dispatch/main/LICENSE -[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array +[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.dispatch_size.js b/benchmark/benchmark.dispatch_size.js deleted file mode 100644 index 15805ba..0000000 --- a/benchmark/benchmark.dispatch_size.js +++ /dev/null @@ -1,156 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var Float64Array = require( '@stdlib/array-float64' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib/main.js' ); - - -// FUNCTIONS // - -/** -* Evaluates the identity function. -* -* @private -* @param {*} v - value -* @returns {*} input value -*/ -function identity( v ) { - return v; -} - -/** -* Dummy function which throws an error. -* -* @private -* @throws {Error} unexpected error -*/ -function throwError() { - throw new Error( 'unexpected error' ); -} - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} size - dispatch size -* @returns {Function} benchmark function -*/ -function createBenchmark( size ) { - var types; - var data; - var fcn; - var x; - var y; - var t; - var i; - - types = []; - - // Create dummy types... - for ( i = 0; i < (size-1)*2; i += 2 ) { - t = 'foo' + i; - types.push( t ); - types.push( t ); - } - // Append test types: - types.push( 'float64' ); - types.push( 'float64' ); - - // Define a list of callbacks: - data = []; - for ( i = 0; i < size-1; i++ ) { - data.push( throwError ); - } - // Append a test callback: - data.push( identity ); - - // Create the dispatcher: - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - // Create sample arrays: - x = new Float64Array( 1 ); - y = new Float64Array( x.length ); - - x = ndarray( 'float64', x, [ 1 ], [ 1 ], 0, 'row-major' ); - y = ndarray( 'float64', y, [ 1 ], [ 1 ], 0, 'row-major' ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var z; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - x.data[ 0 ] = i; - z = fcn( x, y ); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( z.data[ 0 ] ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var size; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - size = pow( 2, i ); - f = createBenchmark( size ); - bench( pkg+':size='+size, f ); - } -} - -main(); diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index 3c6f450..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,81 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var dispatch = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::fcns_array', function benchmark( b ) { - var types; - var fcns; - var data; - var out; - var i; - - fcns = [ unary ]; - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( fcns, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::fcn_arg', function benchmark( b ) { - var types; - var data; - var out; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = dispatch( unary, types, data, 2, 1, 1 ); - if ( typeof out !== 'function' ) { - b.fail( 'should return a function' ); - } - } - b.toc(); - if ( !isFunction( out ) ) { - b.fail( 'should return a function' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0aae4af..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch" -%% click B href "https://github.com/stdlib-js/ndarray-dispatch/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-dispatch/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-dispatch/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-dispatch/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-dispatch/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dispatch -[production-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-dispatch/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-dispatch/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 1295a44..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import dispatch from '../docs/types/index'; -export = dispatch; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 945d47d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict";var q=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var b=q(function(S,y){"use strict";var w=require("@stdlib/assert-is-nonnegative-integer").isPrimitive,T=require("@stdlib/assert-is-positive-integer"),V=require("@stdlib/assert-is-integer").isPrimitive,x=require("@stdlib/assert-is-function-array"),F=require("@stdlib/assert-is-function"),c=require("@stdlib/assert-is-collection"),I=require("@stdlib/assert-is-ndarray-like"),n=require("@stdlib/string-format"),k=require("@stdlib/ndarray-dtype"),j=require("@stdlib/ndarray-base-dtype-resolve-enum"),A=require("@stdlib/ndarray-base-dtypes2enums"),P=require("@stdlib/blas-ext-base-gindex-of-row").ndarray;function U(e,r,i,t,v,m){var a,u,d;if(F(e))d=e;else if(!x(e))throw new TypeError(n("invalid argument. First argument must be either a function or an array of functions. Value: `%s`.",e));if(!c(r))throw new TypeError(n("invalid argument. Second argument must be an array-like object. Value: `%s`.",r));if(!c(i)&&i!==null)throw new TypeError(n("invalid argument. Third argument must be an array-like object or null. Value: `%s`.",i));if(!T(t))throw new TypeError(n("invalid argument. Fourth argument must be a positive integer. Value: `%s`.",t));if(!w(v))throw new TypeError(n("invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.",v));if(!w(m))throw new TypeError(n("invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.",m));if(a=v+m,a===0)throw new Error("invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.");if(t!==a)throw new Error("invalid arguments. Fourth argument does not equal the number of input and output ndarrays.");if(d){if(u=r.length/a,!V(u))throw new Error("invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.")}else if(u=e.length,r.length!==u*a)throw new Error("invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.");if(i&&i.length!==u)throw new Error("invalid argument. The third argument must have the same number of elements as the first argument.");return r=A(r),E;function E(){var o,g,p,f,s,h,l;if(p=arguments.length,p!==t)throw p [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. First argument must be either a function or an array of functions. Value: `%s`.', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Second argument must be an array-like object. Value: `%s`.', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be an array-like object or null. Value: `%s`.', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a positive integer. Value: `%s`.', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fifth argument must be a nonnegative integer. Value: `%s`.', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Sixth argument must be a nonnegative integer. Value: `%s`.', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( 'invalid arguments. Interface must accept at least one input and/or output ndarray. Based on the provided arguments, `nin+nout` equals `0`.' );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( 'invalid arguments. Fourth argument does not equal the number of input and output ndarrays.' );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( 'invalid argument. Unexpected number of types. A type must be specified for each input and output ndarray for each provided ndarray function.' );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' );\n\t}\n\ttypes = dtypes2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( 'invalid invocation. Insufficient arguments.' );\n\t\t\t}\n\t\t\tthrow new Error( 'invalid invocation. Too many arguments.' );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Input array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( 'invalid argument. Output array must be an ndarray-like object. Value: `%s`.', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = gindexOfRow( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 );\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( 'invalid arguments. Unable to resolve an ndarray function supporting the provided array argument data types.' );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = dispatch;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Create an ndarray function interface which performs multiple dispatch.\n*\n* @module @stdlib/ndarray-dispatch\n*\n* @example\n* var ndarray = require( '@stdlib/ndarray-ctor' );\n* var unary = require( '@stdlib/ndarray-base-unary' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var Float64Array = require( '@stdlib/array-float64' );\n* var dispatch = require( '@stdlib/ndarray-dispatch' );\n*\n* var types = [\n* 'float64', 'float64'\n* ];\n*\n* var data = [\n* abs\n* ];\n*\n* var absolute = dispatch( unary, types, data, 2, 1, 1 );\n*\n* // ...\n*\n* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] );\n* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] );\n*\n* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' );\n* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' );\n*\n* absolute( x, y );\n* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"], - "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAuB,QAAS,uCAAwC,EAAE,YAC1EC,EAAoB,QAAS,oCAAqC,EAClEC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAkB,QAAS,kCAAmC,EAC9DC,EAAa,QAAS,4BAA6B,EACnDC,EAAe,QAAS,8BAA+B,EACvDC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAS,QAAS,uBAAwB,EAC1CC,EAAW,QAAS,uBAAwB,EAC5CC,EAAc,QAAS,yCAA0C,EACjEC,EAAe,QAAS,mCAAoC,EAC5DC,EAAc,QAAS,qCAAsC,EAAE,QAqDnE,SAASC,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,EAAO,CACxD,IAAIC,EACAC,EACAC,EAEJ,GAAKjB,EAAYS,CAAK,EACrBQ,EAAMR,UACK,CAACV,EAAiBU,CAAK,EAClC,MAAM,IAAI,UAAWN,EAAQ,oGAAqGM,CAAK,CAAE,EAE1I,GAAK,CAACR,EAAcS,CAAM,EACzB,MAAM,IAAI,UAAWP,EAAQ,+EAAgFO,CAAM,CAAE,EAEtH,GAAK,CAACT,EAAcU,CAAK,GAAKA,IAAS,KACtC,MAAM,IAAI,UAAWR,EAAQ,sFAAuFQ,CAAK,CAAE,EAE5H,GAAK,CAACd,EAAmBe,CAAM,EAC9B,MAAM,IAAI,UAAWT,EAAQ,6EAA8ES,CAAM,CAAE,EAEpH,GAAK,CAAChB,EAAsBiB,CAAI,EAC/B,MAAM,IAAI,UAAWV,EAAQ,+EAAgFU,CAAI,CAAE,EAEpH,GAAK,CAACjB,EAAsBkB,CAAK,EAChC,MAAM,IAAI,UAAWX,EAAQ,+EAAgFW,CAAK,CAAE,EAGrH,GADAC,EAAUF,EAAMC,EACXC,IAAY,EAChB,MAAM,IAAI,MAAO,4IAA6I,EAE/J,GAAKH,IAAUG,EACd,MAAM,IAAI,MAAO,4FAA6F,EAE/G,GAAKE,GAEJ,GADAD,EAAQN,EAAM,OAASK,EAClB,CAACjB,EAAWkB,CAAM,EACtB,MAAM,IAAI,MAAO,8IAA+I,UAGjKA,EAAQP,EAAK,OACRC,EAAM,SAAWM,EAAMD,EAC3B,MAAM,IAAI,MAAO,8IAA+I,EAGlK,GAAKJ,GAAQA,EAAK,SAAWK,EAC5B,MAAM,IAAI,MAAO,mGAAoG,EAEtH,OAAAN,EAAQJ,EAAcI,CAAM,EACrBQ,EAeP,SAASA,GAAa,CACrB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GADAJ,EAAO,UAAU,OACZA,IAAST,EACb,MAAKS,EAAOT,EACL,IAAI,MAAO,6CAA8C,EAE1D,IAAI,MAAO,yCAA0C,EAI5D,IAFAO,EAAS,CAAC,EACVC,EAAS,CAAC,EACJK,EAAI,EAAGA,EAAIb,EAAOa,IAAM,CAE7B,GADAF,EAAI,UAAWE,CAAE,EACZ,CAACvB,EAAeqB,CAAE,EACtB,MAAKE,EAAIZ,EACF,IAAI,UAAWV,EAAQ,6EAA8EoB,CAAE,CAAE,EAEzG,IAAI,UAAWpB,EAAQ,8EAA+EoB,CAAE,CAAE,EAGlHJ,EAAO,KAAMI,CAAE,EACfH,EAAO,KAAMf,EAAaD,EAAUmB,CAAE,CAAE,CAAE,CAC3C,CAKA,GAHAD,EAAMf,EAAaS,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGK,EAAQ,EAAG,CAAE,EAGjEE,EAAM,EACV,MAAM,IAAI,UAAW,6GAA8G,EAcpI,GAXKL,EACJO,EAAIP,EAEJO,EAAIf,EAAMa,CAAI,EAGVX,EACJa,EAAGL,EAAQR,EAAMW,CAAI,CAAE,EAEvBE,EAAGL,CAAO,EAENL,IAAS,EACb,OAAOK,EAAQJ,EAAQ,CAAE,EAE1B,GAAKD,IAAS,EAGd,OAAOK,EAAO,MAAON,CAAI,CAC1B,CACD,CAKAlB,EAAO,QAAUa,IC1JjB,IAAIkB,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_main", "__commonJSMin", "exports", "module", "isNonNegativeInteger", "isPositiveInteger", "isInteger", "isFunctionArray", "isFunction", "isCollection", "isndarrayLike", "format", "getDType", "resolveEnum", "dtypes2enums", "gindexOfRow", "dispatch", "fcns", "types", "data", "nargs", "nin", "nout", "narrays", "nfcns", "fcn", "dispatcher", "arrays", "dtypes", "argc", "idx", "v", "f", "i", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 02fe150..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,87 +0,0 @@ - -{{alias}}( fcns, types, data, nargs, nin, nout ) - Returns an ndarray function interface which performs multiple dispatch. - - An ndarray function interface has the following signature: - - f( x, y, ... ) - - where - - - x: ndarray. - - y: ndarray. - - ...: additional ndarrays. - - The number of parameters is derived from `nargs`, the number of input - ndarrays is derived from `nin`, and the number of output ndarrays is derived - from `nout`. - - Parameters - ---------- - fcns: Function|ArrayLikeObject - List of ndarray functions. An ndarray function should have the following - signature: - - f( arrays, data ) - - where - - - arrays: array containing input and output ndarrays. - - data: ndarray function data (e.g., a callback). - - For convenience, a single ndarray function may be provided which will be - invoked whenever the ndarray argument data types match a sequence of - types in `types`. Providing a single ndarray function is particularly - convenient for the case where, regardless of array data types, - traversing arrays remains the same, but the ndarray function `data` - differs (e.g., callbacks which differ based on the array data types). - - types: ArrayLikeObject - One-dimensional list of ndarray argument data types. - - data: ArrayLikeObject|null - ndarray function data (e.g., callbacks). If `null`, a returned ndarray - function interface does **not** provide a `data` argument to an invoked - ndarray function. - - nargs: integer - Total number of ndarray function interface arguments. - - nin: integer - Number of input ndarrays. - - nout: integer - Number of output ndarrays. - - Returns - ------- - fcn: Function - ndarray function interface. - - Examples - -------- - // Define ndarray argument data types: - > var t = [ 'float64', 'float64', 'float32', 'float32' ]; - - // Define a list of ndarray function data (callbacks): - > var d = [ {{alias:@stdlib/math/base/special/abs}}, {{alias:@stdlib/math/base/special/absf}} ]; - - // Create an ndarray function interface for applying unary callbacks: - > var f = {{alias}}( {{alias:@stdlib/ndarray/base/unary}}, t, d, 2, 1, 1 ); - - // Create an input ndarray: - > var xbuf = new {{alias:@stdlib/array/float64}}( [ -1.0, -2.0, -3.0, -4.0 ] ); - > var x = {{alias:@stdlib/ndarray/ctor}}( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Create an output ndarray: - > var ybuf = new {{alias:@stdlib/array/float64}}( [ 0.0, 0.0, 0.0, 0.0 ] ); - > var y = {{alias:@stdlib/ndarray/ctor}}( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - // Compute the element-wise absolute value: - > f( x, y ); - > ybuf - [ 1.0, 2.0, 3.0, 4.0 ] - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 3fece39..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,615 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable max-lines, prefer-const */ - -/// - -import { ndarray } from '@stdlib/types/ndarray'; -import ind2sub = require( '@stdlib/ndarray-ind2sub' ); -import dispatch = require( './index' ); - - -// FUNCTIONS // - -/** -* Nullary callback. -* -* @returns input value -*/ -function nullary(): any { - return 5.0; -} - -/** -* Unary callback. -* -* @param x - input value -* @returns input value -*/ -function unary( x: any ): any { - return x; -} - -/** -* Binary callback. -* -* @param x - input value -* @param y - input value -* @returns output value -*/ -function binary( x: number, y: number ): number { - return x + y; -} - -/** -* Ternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @returns output value -*/ -function ternary( x: number, y: number, z: number ): number { - return x + y + z; -} - -/** -* Quaternary callback. -* -* @param x - input value -* @param y - input value -* @param z - input value -* @param w - input value -* @returns output value -*/ -function quaternary( x: number, y: number, z: number, w: number ): number { - return x + y + z + w; -} - -/** -* Mock ndarray function. -* -* @param arrays - ndarrays -* @param fcn - callback -*/ -function ndarrayFcn( arrays: Array, fcn: ( x: any ) => any ): void { - let xord; - let yord; - let opts; - let sub; - let sh; - let N; - let x; - let y; - let v; - let i; - - x = arrays[ 0 ]; - y = arrays[ 1 ]; - sh = x.shape; - if ( sh.length === 0 ) { - return; - } - N = 1; - for ( i = 0; i < sh.length; i += 1 ) { - N *= sh[ i ]; - } - xord = x.order; - yord = y.order; - opts = { - 'order': xord - }; - for ( i = 0; i < N; i += 1 ) { - // Convert a linear index to subscripts: - opts.order = xord; - sub = ind2sub( sh, i, opts ); - - // Retrieve an element from `x`: - v = x.get.apply( x, sub ); - - // Convert a linear index to subscripts: - opts.order = yord; - sub = ind2sub( sh, i, opts ); - - // Append the result of applying the callback: - sub[ sub.length ] = fcn( v ) as number; - - // Assign the result to an element in `y`: - y.set.apply( y, sub ); - } -} - -/** -* Mock function to create an ndarray-like object. -* -* @returns ndarray-like object -*/ -function array(): ndarray { - const obj: ndarray = { - 'byteLength': 80, - 'BYTES_PER_ELEMENT': 8, - 'data': new Float64Array( 10 ), - 'dtype': 'float64', - 'flags': { - 'ROW_MAJOR_CONTIGUOUS': true, - 'COLUMN_MAJOR_CONTIGUOUS': false - }, - 'length': 10, - 'ndims': 1, - 'offset': 0, - 'order': 'row-major', - 'shape': [ 10 ], - 'strides': [ 1 ], - 'get': (): number => 0, - 'set': (): ndarray => obj - }; - return obj; -} - - -// TESTS // - -// The function returns a dispatch function... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, 1 ); // $ExpectType Dispatcher - dispatch( [ ndarrayFcn ], types, data, 2, 1, 1 ); // $ExpectType Dispatcher -} - -// The compiler throws an error if the function is provided a first argument which is not either an ndarray function or an array-like object containing ndarray functions... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( '10', types, data, 2, 1, 1 ); // $ExpectError - dispatch( 10, types, data, 2, 1, 1 ); // $ExpectError - dispatch( true, types, data, 2, 1, 1 ); // $ExpectError - dispatch( false, types, data, 2, 1, 1 ); // $ExpectError - dispatch( null, types, data, 2, 1, 1 ); // $ExpectError - dispatch( undefined, types, data, 2, 1, 1 ); // $ExpectError - dispatch( [ '1' ], types, data, 2, 1, 1 ); // $ExpectError - dispatch( {}, types, data, 2, 1, 1 ); // $ExpectError - dispatch( ( x: number ): number => x, types, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an array-like object... -{ - const data = [ unary ]; - - dispatch( ndarrayFcn, 10, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, true, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, false, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, null, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, undefined, data, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, {}, data, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not an array-like object or null... -{ - const types = [ 'float64', 'float64' ]; - - dispatch( ndarrayFcn, types, 10, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, true, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, false, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, undefined, 2, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, {}, 2, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, '10', 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, true, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, false, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, null, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, undefined, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, [ '1' ], 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, {}, 1, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, ( x: number ): number => x, 1, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fifth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, '10', 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, true, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, false, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, null, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, undefined, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, [ '1' ], 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, {}, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, ( x: number ): number => x, 1 ); // $ExpectError -} - -// The compiler throws an error if the function is provided a sixth argument which is not a number... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch( ndarrayFcn, types, data, 2, 1, '10' ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, true ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, false ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, null ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, undefined ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, [ '1' ] ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, {} ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - dispatch(); // $ExpectError - dispatch( ndarrayFcn ); // $ExpectError - dispatch( ndarrayFcn, types ); // $ExpectError - dispatch( ndarrayFcn, types, data ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1 ); // $ExpectError - dispatch( ndarrayFcn, types, data, 2, 1, 1, 0 ); // $ExpectError -} - -// The function returns a dispatch function... -{ - const x = array(); - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const t1 = [ 'float64' ]; - const d1 = [ nullary ]; - const f1 = dispatch( ndarrayFcn, t1, d1, 1, 1, 0 ); - f1( x ); // $ExpectType void | ndarray - - const t2 = [ 'float64', 'float64' ]; - const d2 = [ unary ]; - const f2 = dispatch( ndarrayFcn, t2, d2, 2, 1, 1 ); - f2( x, y ); // $ExpectType void | ndarray - - const t3 = [ 'float64', 'float64', 'float64' ]; - const d3 = [ binary ]; - const f3 = dispatch( ndarrayFcn, t3, d3, 3, 2, 1 ); - f3( x, y, z ); // $ExpectType void | ndarray - - const t4 = [ 'float64', 'float64', 'float64', 'float64' ]; - const d4 = [ ternary ]; - const f4 = dispatch( ndarrayFcn, t4, d4, 4, 3, 1 ); - f4( x, y, z, w ); // $ExpectType void | ndarray - - const t5 = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const d5 = [ quaternary ]; - const f5 = dispatch( ndarrayFcn, t5, d5, 5, 4, 1 ); - f5( x, y, z, w, u ); // $ExpectType void | ndarray -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (1 ndarray)... -{ - const types = [ 'float64' ]; - const data = [ nullary ]; - - const f = dispatch( ndarrayFcn, types, data, 1, 0, 1 ); - f( '10' ); // $ExpectError - f( 10 ); // $ExpectError - f( true ); // $ExpectError - f( false ); // $ExpectError - f( null ); // $ExpectError - f( undefined ); // $ExpectError - f( [ '1' ] ); // $ExpectError - f( {} ); // $ExpectError - f( ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( 10, y ); // $ExpectError - f( '10', y ); // $ExpectError - f( true, y ); // $ExpectError - f( false, y ); // $ExpectError - f( null, y ); // $ExpectError - f( undefined, y ); // $ExpectError - f( [ '1' ], y ); // $ExpectError - f( {}, y ); // $ExpectError - f( ( x: number ): number => x, y ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (2 ndarrays)... -{ - const types = [ 'float64', 'float64' ]; - const data = [ unary ]; - - const x = array(); - - const f = dispatch( ndarrayFcn, types, data, 2, 1, 1 ); - f( x, 10 ); // $ExpectError - f( x, '10' ); // $ExpectError - f( x, true ); // $ExpectError - f( x, false ); // $ExpectError - f( x, null ); // $ExpectError - f( x, undefined ); // $ExpectError - f( x, [ '1' ] ); // $ExpectError - f( x, {} ); // $ExpectError - f( x, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( 10, y, z ); // $ExpectError - f( '10', y, z ); // $ExpectError - f( true, y, z ); // $ExpectError - f( false, y, z ); // $ExpectError - f( null, y, z ); // $ExpectError - f( undefined, y, z ); // $ExpectError - f( [ '1' ], y, z ); // $ExpectError - f( {}, y, z ); // $ExpectError - f( ( x: number ): number => x, y, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, 10, z ); // $ExpectError - f( x, '10', z ); // $ExpectError - f( x, true, z ); // $ExpectError - f( x, false, z ); // $ExpectError - f( x, null, z ); // $ExpectError - f( x, undefined, z ); // $ExpectError - f( x, [ '1' ], z ); // $ExpectError - f( x, {}, z ); // $ExpectError - f( x, ( x: number ): number => x, z ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (3 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64' ]; - const data = [ binary ]; - - const x = array(); - const y = array(); - - const f = dispatch( ndarrayFcn, types, data, 3, 2, 1 ); - f( x, y, '10' ); // $ExpectError - f( x, y, true ); // $ExpectError - f( x, y, false ); // $ExpectError - f( x, y, null ); // $ExpectError - f( x, y, undefined ); // $ExpectError - f( x, y, [ '1' ] ); // $ExpectError - f( x, y, {} ); // $ExpectError - f( x, y, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( 10, y, z, w ); // $ExpectError - f( '10', y, z, w ); // $ExpectError - f( true, y, z, w ); // $ExpectError - f( false, y, z, w ); // $ExpectError - f( null, y, z, w ); // $ExpectError - f( undefined, y, z, w ); // $ExpectError - f( [ '1' ], y, z, w ); // $ExpectError - f( {}, y, z, w ); // $ExpectError - f( ( x: number ): number => x, y, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, 10, z, w ); // $ExpectError - f( x, '10', z, w ); // $ExpectError - f( x, true, z, w ); // $ExpectError - f( x, false, z, w ); // $ExpectError - f( x, null, z, w ); // $ExpectError - f( x, undefined, z, w ); // $ExpectError - f( x, [ '1' ], z, w ); // $ExpectError - f( x, {}, z, w ); // $ExpectError - f( x, ( x: number ): number => x, z, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, 10, w ); // $ExpectError - f( x, y, '10', w ); // $ExpectError - f( x, y, true, w ); // $ExpectError - f( x, y, false, w ); // $ExpectError - f( x, y, null, w ); // $ExpectError - f( x, y, undefined, w ); // $ExpectError - f( x, y, [ '1' ], w ); // $ExpectError - f( x, y, {}, w ); // $ExpectError - f( x, y, ( x: number ): number => x, w ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (4 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64' ]; - const data = [ ternary ]; - - const x = array(); - const y = array(); - const z = array(); - - const f = dispatch( ndarrayFcn, types, data, 4, 3, 1 ); - f( x, y, z, 10 ); // $ExpectError - f( x, y, z, '10' ); // $ExpectError - f( x, y, z, true ); // $ExpectError - f( x, y, z, false ); // $ExpectError - f( x, y, z, null ); // $ExpectError - f( x, y, z, undefined ); // $ExpectError - f( x, y, z, [ '1' ] ); // $ExpectError - f( x, y, z, {} ); // $ExpectError - f( x, y, z, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a first argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const y = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( 10, y, z, w, u ); // $ExpectError - f( '10', y, z, w, u ); // $ExpectError - f( true, y, z, w, u ); // $ExpectError - f( false, y, z, w, u ); // $ExpectError - f( null, y, z, w, u ); // $ExpectError - f( undefined, y, z, w, u ); // $ExpectError - f( [ '1' ], y, z, w, u ); // $ExpectError - f( {}, y, z, w, u ); // $ExpectError - f( ( x: number ): number => x, y, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a second argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const z = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, 10, z, w, u ); // $ExpectError - f( x, '10', z, w, u ); // $ExpectError - f( x, true, z, w, u ); // $ExpectError - f( x, false, z, w, u ); // $ExpectError - f( x, null, z, w, u ); // $ExpectError - f( x, undefined, z, w, u ); // $ExpectError - f( x, [ '1' ], z, w, u ); // $ExpectError - f( x, {}, z, w, u ); // $ExpectError - f( x, ( x: number ): number => x, z, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a third argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const w = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, 10, w, u ); // $ExpectError - f( x, y, '10', w, u ); // $ExpectError - f( x, y, true, w, u ); // $ExpectError - f( x, y, false, w, u ); // $ExpectError - f( x, y, null, w, u ); // $ExpectError - f( x, y, undefined, w, u ); // $ExpectError - f( x, y, [ '1' ], w, u ); // $ExpectError - f( x, y, {}, w, u ); // $ExpectError - f( x, y, ( x: number ): number => x, w, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fourth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const u = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, 10, u ); // $ExpectError - f( x, y, z, '10', u ); // $ExpectError - f( x, y, z, true, u ); // $ExpectError - f( x, y, z, false, u ); // $ExpectError - f( x, y, z, null, u ); // $ExpectError - f( x, y, z, undefined, u ); // $ExpectError - f( x, y, z, [ '1' ], u ); // $ExpectError - f( x, y, z, {}, u ); // $ExpectError - f( x, y, z, ( x: number ): number => x, u ); // $ExpectError -} - -// The compiler throws an error if the returned function is provided a fifth argument which is not an ndarray (5 ndarrays)... -{ - const types = [ 'float64', 'float64', 'float64', 'float64', 'float64' ]; - const data = [ quaternary ]; - - const x = array(); - const y = array(); - const z = array(); - const w = array(); - - const f = dispatch( ndarrayFcn, types, data, 5, 4, 1 ); - f( x, y, z, w, 10 ); // $ExpectError - f( x, y, z, w, '10' ); // $ExpectError - f( x, y, z, w, true ); // $ExpectError - f( x, y, z, w, false ); // $ExpectError - f( x, y, z, w, null ); // $ExpectError - f( x, y, z, w, undefined ); // $ExpectError - f( x, y, z, w, [ '1' ] ); // $ExpectError - f( x, y, z, w, {} ); // $ExpectError - f( x, y, z, w, ( x: number ): number => x ); // $ExpectError -} diff --git a/examples/add.js b/examples/add.js deleted file mode 100644 index 3949bc0..0000000 --- a/examples/add.js +++ /dev/null @@ -1,121 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Int32Array = require( '@stdlib/array-int32' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var dispatch = require( './../lib' ); - -function add2( arrays ) { - var opts; - var xo; - var yo; - var zo; - var sx; - var sy; - var sz; - var sh; - var N; - var x; - var y; - var z; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - z = arrays[ 2 ]; - xo = x.order; - yo = y.order; - zo = z.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - opts.order = yo; - sy = ind2sub( sh, i, opts ); - v = x.get.apply( x, sx ) + y.get.apply( y, sy ); - - opts.order = zo; - sz = ind2sub( sh, i, opts ); - sz.push( v ); - z.set.apply( z, sz ); - } -} - -var fcns = [ - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2, - add2 -]; - -var types = [ - dtypes.float64.enum, dtypes.float64.enum, dtypes.float64.enum, - dtypes.float32.enum, dtypes.float32.enum, dtypes.float32.enum, - dtypes.int32.enum, dtypes.int32.enum, dtypes.int32.enum, - dtypes.uint32.enum, dtypes.uint32.enum, dtypes.uint32.enum, - dtypes.int16.enum, dtypes.int16.enum, dtypes.int16.enum, - dtypes.uint16.enum, dtypes.uint16.enum, dtypes.uint16.enum, - dtypes.int8.enum, dtypes.int8.enum, dtypes.int8.enum, - dtypes.uint8.enum, dtypes.uint8.enum, dtypes.uint8.enum, - dtypes.uint8c.enum, dtypes.uint8c.enum, dtypes.uint8c.enum -]; - -var add = dispatch( fcns, types, null, 3, 2, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var zbuf = new Float64Array( xbuf.length ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var z = ndarray( 'float64', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); - -xbuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -ybuf = new Int32Array( [ 10, 20, 30, 40, 50 ] ); -zbuf = new Int32Array( xbuf.length ); - -x = ndarray( 'int32', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'int32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -z = ndarray( 'int32', zbuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -add( x, y, z ); -console.log( zbuf ); diff --git a/examples/sin.js b/examples/sin.js deleted file mode 100644 index 106a586..0000000 --- a/examples/sin.js +++ /dev/null @@ -1,142 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int8Array = require( '@stdlib/array-int8' ); -var sin = require( '@stdlib/math-base-special-sin' ); -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var dtypes = require( '@stdlib/ndarray-dtypes' ); -var dispatch = require( './../lib' ); - -function apply( arrays, fcn ) { - var opts; - var xo; - var yo; - var sx; - var sy; - var sh; - var N; - var x; - var y; - var v; - var i; - - x = arrays[ 0 ]; - sh = x.shape; - N = numel( sh ); - if ( N <= 0 ) { - return; - } - y = arrays[ 1 ]; - xo = x.order; - yo = y.order; - opts = { - 'order': xo - }; - for ( i = 0; i < N; i++ ) { - opts.order = xo; - sx = ind2sub( sh, i, opts ); - v = fcn( x.get.apply( x, sx ) ); - - opts.order = yo; - sy = ind2sub( sh, i, opts ); - sy.push( v ); - y.set.apply( y, sy ); - } -} - -var fcns = [ - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply, - apply -]; - -var types = [ - dtypes.float64.enum, dtypes.float64.enum, - dtypes.float32.enum, dtypes.float64.enum, - dtypes.float32.enum, dtypes.float32.enum, - dtypes.int32.enum, dtypes.float64.enum, - dtypes.uint32.enum, dtypes.float64.enum, - dtypes.int16.enum, dtypes.float64.enum, - dtypes.int16.enum, dtypes.float32.enum, - dtypes.uint16.enum, dtypes.float64.enum, - dtypes.uint16.enum, dtypes.float32.enum, - dtypes.int8.enum, dtypes.float64.enum, - dtypes.int8.enum, dtypes.float32.enum, - dtypes.uint8.enum, dtypes.float64.enum, - dtypes.uint8.enum, dtypes.float32.enum, - dtypes.uint8c.enum, dtypes.float64.enum, - dtypes.uint8c.enum, dtypes.float32.enum -]; - -var data = [ - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin, - sin -]; - -var sine = dispatch( fcns, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); -var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); - -xbuf = new Int8Array( [ 1, 2, 3, 4, 5 ] ); -ybuf = new Float32Array( xbuf.length ); - -x = ndarray( 'int8', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -y = ndarray( 'float32', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -sine( x, y ); -console.log( ybuf ); diff --git a/examples/unary.js b/examples/unary.js deleted file mode 100644 index e9c3fb4..0000000 --- a/examples/unary.js +++ /dev/null @@ -1,43 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -var unary = require( '@stdlib/ndarray-base-unary' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var dispatch = require( './../lib' ); - -var types = [ 'float64', 'float64' ]; - -var data = [ - abs -]; - -var absolute = dispatch( unary, types, data, 2, 1, 1 ); - -var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - -var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); - -absolute( x, y ); -console.log( ybuf ); -// => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 99% rename from docs/types/index.d.ts rename to index.d.ts index 5f280a1..c49a4e4 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..2efc206 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-positive-integer@v0.2.2-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-integer@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function-array@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-collection@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtype-resolve-enum@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-dtypes2enums@esm/index.mjs";import{ndarray as l}from"https://cdn.jsdelivr.net/gh/stdlib-js/blas-ext-base-gindex-of-row@v0.0.0-esm/index.mjs";function p(p,f,w,v,a,g){var c,y,b;if(i(p))b=p;else if(!t(p))throw new TypeError(d("0jr5d",p));if(!n(f))throw new TypeError(d("0jr2y",f));if(!n(w)&&null!==w)throw new TypeError(d("0jr5e",w));if(!e(v))throw new TypeError(d("0jr5f",v));if(!r(a))throw new TypeError(d("0jr5X",a));if(!r(g))throw new TypeError(d("0jr5g",g));if(0===(c=a+g))throw new Error(d("0jr0h"));if(v!==c)throw new Error(d("0jr0i"));if(b){if(y=f.length/c,!s(y))throw new Error(d("0jr0j"))}else if(y=p.length,f.length!==y*c)throw new Error(d("0jr0j"));if(w&&w.length!==y)throw new Error(d("0jr0k"));return f=h(f),function(){var r,e,s,t,i,n,h;if(s=arguments.length,s!==v){if(s [ 1.0, 2.0, 3.0, 4.0, 5.0 ]\n*/\nfunction dispatch( fcns, types, data, nargs, nin, nout ) {\n\tvar narrays;\n\tvar nfcns;\n\tvar fcn;\n\n\tif ( isFunction( fcns ) ) {\n\t\tfcn = fcns;\n\t} else if ( !isFunctionArray( fcns ) ) {\n\t\tthrow new TypeError( format( '0jr5d', fcns ) );\n\t}\n\tif ( !isCollection( types ) ) {\n\t\tthrow new TypeError( format( '0jr2y', types ) );\n\t}\n\tif ( !isCollection( data ) && data !== null ) {\n\t\tthrow new TypeError( format( '0jr5e', data ) );\n\t}\n\tif ( !isPositiveInteger( nargs ) ) {\n\t\tthrow new TypeError( format( '0jr5f', nargs ) );\n\t}\n\tif ( !isNonNegativeInteger( nin ) ) {\n\t\tthrow new TypeError( format( '0jr5X', nin ) );\n\t}\n\tif ( !isNonNegativeInteger( nout ) ) {\n\t\tthrow new TypeError( format( '0jr5g', nout ) );\n\t}\n\tnarrays = nin + nout;\n\tif ( narrays === 0 ) {\n\t\tthrow new Error( format('0jr0h') );\n\t}\n\tif ( nargs !== narrays ) {\n\t\tthrow new Error( format('0jr0i') );\n\t}\n\tif ( fcn ) {\n\t\tnfcns = types.length / narrays;\n\t\tif ( !isInteger( nfcns ) ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t} else {\n\t\tnfcns = fcns.length;\n\t\tif ( types.length !== nfcns*narrays ) {\n\t\t\tthrow new Error( format('0jr0j') );\n\t\t}\n\t}\n\tif ( data && data.length !== nfcns ) {\n\t\tthrow new Error( format('0jr0k') );\n\t}\n\ttypes = dtypes2enums( types );\n\treturn dispatcher;\n\n\t/**\n\t* ndarray function interface which performs multiple dispatch.\n\t*\n\t* @private\n\t* @param {ndarrayLike} x - ndarray\n\t* @param {...ndarrayLike} args - ndarray arguments\n\t* @throws {Error} insufficient arguments\n\t* @throws {Error} too many arguments\n\t* @throws {TypeError} input array arguments must be ndarray-like objects\n\t* @throws {TypeError} output array arguments must be ndarray-like objects\n\t* @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types\n\t* @returns {(ndarrayLike|Array|void)} destination array(s)\n\t*/\n\tfunction dispatcher() {\n\t\tvar arrays;\n\t\tvar dtypes;\n\t\tvar argc;\n\t\tvar idx;\n\t\tvar v;\n\t\tvar f;\n\t\tvar i;\n\n\t\targc = arguments.length;\n\t\tif ( argc !== nargs ) {\n\t\t\tif ( argc < nargs ) {\n\t\t\t\tthrow new Error( format('0jr0l') );\n\t\t\t}\n\t\t\tthrow new Error( format('0jr0m') );\n\t\t}\n\t\tarrays = [];\n\t\tdtypes = [];\n\t\tfor ( i = 0; i < nargs; i++ ) {\n\t\t\tv = arguments[ i ];\n\t\t\tif ( !isndarrayLike( v ) ) {\n\t\t\t\tif ( i < nin ) {\n\t\t\t\t\tthrow new TypeError( format( '0jr5h', v ) );\n\t\t\t\t} else {\n\t\t\t\t\tthrow new TypeError( format( '0jr5i', v ) );\n\t\t\t\t}\n\t\t\t}\n\t\t\tarrays.push( v );\n\t\t\tdtypes.push( resolveEnum( getDType( v ) ) );\n\t\t}\n\t\t// Resolve the ndarray function satisfying the input array types:\n\t\tidx = gindexOfRow( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 );\n\n\t\t// Check whether we were able to successfully resolve an ndarray function:\n\t\tif ( idx < 0 ) {\n\t\t\tthrow new TypeError( format('0jr0n') );\n\t\t}\n\t\t// Retrieve the ndarray function:\n\t\tif ( fcn ) {\n\t\t\tf = fcn;\n\t\t} else {\n\t\t\tf = fcns[ idx ];\n\t\t}\n\t\t// Evaluate the ndarray function:\n\t\tif ( data ) {\n\t\t\tf( arrays, data[ idx ] );\n\t\t} else {\n\t\t\tf( arrays );\n\t\t}\n\t\tif ( nout === 1 ) {\n\t\t\treturn arrays[ narrays-1 ];\n\t\t}\n\t\tif ( nout === 0 ) {\n\t\t\treturn;\n\t\t}\n\t\treturn arrays.slice( nin );\n\t}\n}\n\n\n// EXPORTS //\n\nexport default dispatch;\n"],"names":["dispatch","fcns","types","data","nargs","nin","nout","narrays","nfcns","fcn","isFunction","isFunctionArray","TypeError","format","isCollection","isPositiveInteger","isNonNegativeInteger","Error","length","isInteger","dtypes2enums","arrays","dtypes","argc","idx","v","f","i","arguments","isndarrayLike","push","resolveEnum","getDType","gindexOfRow","slice"],"mappings":";;wrCAsFA,SAASA,EAAUC,EAAMC,EAAOC,EAAMC,EAAOC,EAAKC,GACjD,IAAIC,EACAC,EACAC,EAEJ,GAAKC,EAAYT,GAChBQ,EAAMR,OACA,IAAMU,EAAiBV,GAC7B,MAAM,IAAIW,UAAWC,EAAQ,QAASZ,IAEvC,IAAMa,EAAcZ,GACnB,MAAM,IAAIU,UAAWC,EAAQ,QAASX,IAEvC,IAAMY,EAAcX,IAAmB,OAATA,EAC7B,MAAM,IAAIS,UAAWC,EAAQ,QAASV,IAEvC,IAAMY,EAAmBX,GACxB,MAAM,IAAIQ,UAAWC,EAAQ,QAAST,IAEvC,IAAMY,EAAsBX,GAC3B,MAAM,IAAIO,UAAWC,EAAQ,QAASR,IAEvC,IAAMW,EAAsBV,GAC3B,MAAM,IAAIM,UAAWC,EAAQ,QAASP,IAGvC,GAAiB,KADjBC,EAAUF,EAAMC,GAEf,MAAM,IAAIW,MAAOJ,EAAO,UAEzB,GAAKT,IAAUG,EACd,MAAM,IAAIU,MAAOJ,EAAO,UAEzB,GAAKJ,GAEJ,GADAD,EAAQN,EAAMgB,OAASX,GACjBY,EAAWX,GAChB,MAAM,IAAIS,MAAOJ,EAAO,eAIzB,GADAL,EAAQP,EAAKiB,OACRhB,EAAMgB,SAAWV,EAAMD,EAC3B,MAAM,IAAIU,MAAOJ,EAAO,UAG1B,GAAKV,GAAQA,EAAKe,SAAWV,EAC5B,MAAM,IAAIS,MAAOJ,EAAO,UAGzB,OADAX,EAAQkB,EAAclB,GAgBtB,WACC,IAAImB,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAGJ,GADAJ,EAAOK,UAAUV,OACZK,IAASnB,EAAQ,CACrB,GAAKmB,EAAOnB,EACX,MAAM,IAAIa,MAAOJ,EAAO,UAEzB,MAAM,IAAII,MAAOJ,EAAO,SACxB,CAGD,IAFAQ,EAAS,GACTC,EAAS,GACHK,EAAI,EAAGA,EAAIvB,EAAOuB,IAAM,CAE7B,IAAME,EADNJ,EAAIG,UAAWD,IAEd,MAAKA,EAAItB,EACF,IAAIO,UAAWC,EAAQ,QAASY,IAEhC,IAAIb,UAAWC,EAAQ,QAASY,IAGxCJ,EAAOS,KAAML,GACbH,EAAOQ,KAAMC,EAAaC,EAAUP,IACpC,CAKD,IAHAD,EAAMS,EAAazB,EAAOD,EAASL,EAAOK,EAAS,EAAG,EAAGe,EAAQ,EAAG,IAGzD,EACV,MAAM,IAAIV,UAAWC,EAAO,UAI5Ba,EADIjB,GAGAR,EAAMuB,GAGNrB,EACJuB,EAAGL,EAAQlB,EAAMqB,IAEjBE,EAAGL,GAEJ,GAAc,IAATf,EACJ,OAAOe,EAAQd,EAAQ,GAExB,GAAc,IAATD,EACJ,OAED,OAAOe,EAAOa,MAAO7B,EACrB,CACF"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 88f0e3e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,62 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -/** -* Create an ndarray function interface which performs multiple dispatch. -* -* @module @stdlib/ndarray-dispatch -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var dispatch = require( '@stdlib/ndarray-dispatch' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index c8b8f74..0000000 --- a/lib/main.js +++ /dev/null @@ -1,211 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isPositiveInteger = require( '@stdlib/assert-is-positive-integer' ); -var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive; -var isFunctionArray = require( '@stdlib/assert-is-function-array' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var isCollection = require( '@stdlib/assert-is-collection' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var getDType = require( '@stdlib/ndarray-dtype' ); -var resolveEnum = require( '@stdlib/ndarray-base-dtype-resolve-enum' ); -var dtypes2enums = require( '@stdlib/ndarray-base-dtypes2enums' ); -var gindexOfRow = require( '@stdlib/blas-ext-base-gindex-of-row' ).ndarray; - - -// MAIN // - -/** -* Returns an ndarray function interface which performs multiple dispatch. -* -* @param {(FunctionArray|Function)} fcns - list of ndarray functions -* @param {Collection} types - one-dimensional list of ndarray argument data types -* @param {(Collection|null)} data - ndarray function data (e.g., callbacks) -* @param {PositiveInteger} nargs - total number of ndarray function interface arguments -* @param {NonNegativeInteger} nin - number of input ndarrays -* @param {NonNegativeInteger} nout - number of output ndarrays -* @throws {TypeError} first argument must be either a function or an array of functions -* @throws {TypeError} second argument must be an array-like object -* @throws {TypeError} third argument must be an array-like object or `null` -* @throws {Error} third and first arguments must have the same number of elements -* @throws {TypeError} fourth argument must be a positive integer -* @throws {TypeError} fifth argument must be a nonnegative integer -* @throws {TypeError} sixth argument must be a nonnegative integer -* @throws {Error} fourth argument must equal the specified number of input and output arrays -* @throws {Error} number of types must match the number of functions times the total number of array arguments for each function -* @throws {Error} interface must accept at least one input and/or output ndarray -* @returns {Function} ndarray function interface -* -* @example -* var unary = require( '@stdlib/ndarray-base-unary' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var Float64Array = require( '@stdlib/array-float64' ); -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var types = [ -* 'float64', 'float64' -* ]; -* -* var data = [ -* abs -* ]; -* -* var absolute = dispatch( unary, types, data, 2, 1, 1 ); -* -* // ... -* -* var xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0 ] ); -* var ybuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); -* -* var x = ndarray( 'float64', xbuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* var y = ndarray( 'float64', ybuf, [ 5 ], [ 1 ], 0, 'row-major' ); -* -* absolute( x, y ); -* // ybuf => [ 1.0, 2.0, 3.0, 4.0, 5.0 ] -*/ -function dispatch( fcns, types, data, nargs, nin, nout ) { - var narrays; - var nfcns; - var fcn; - - if ( isFunction( fcns ) ) { - fcn = fcns; - } else if ( !isFunctionArray( fcns ) ) { - throw new TypeError( format( '0jr5d', fcns ) ); - } - if ( !isCollection( types ) ) { - throw new TypeError( format( '0jr2y', types ) ); - } - if ( !isCollection( data ) && data !== null ) { - throw new TypeError( format( '0jr5e', data ) ); - } - if ( !isPositiveInteger( nargs ) ) { - throw new TypeError( format( '0jr5f', nargs ) ); - } - if ( !isNonNegativeInteger( nin ) ) { - throw new TypeError( format( '0jr5X', nin ) ); - } - if ( !isNonNegativeInteger( nout ) ) { - throw new TypeError( format( '0jr5g', nout ) ); - } - narrays = nin + nout; - if ( narrays === 0 ) { - throw new Error( format('0jr0h') ); - } - if ( nargs !== narrays ) { - throw new Error( format('0jr0i') ); - } - if ( fcn ) { - nfcns = types.length / narrays; - if ( !isInteger( nfcns ) ) { - throw new Error( format('0jr0j') ); - } - } else { - nfcns = fcns.length; - if ( types.length !== nfcns*narrays ) { - throw new Error( format('0jr0j') ); - } - } - if ( data && data.length !== nfcns ) { - throw new Error( format('0jr0k') ); - } - types = dtypes2enums( types ); - return dispatcher; - - /** - * ndarray function interface which performs multiple dispatch. - * - * @private - * @param {ndarrayLike} x - ndarray - * @param {...ndarrayLike} args - ndarray arguments - * @throws {Error} insufficient arguments - * @throws {Error} too many arguments - * @throws {TypeError} input array arguments must be ndarray-like objects - * @throws {TypeError} output array arguments must be ndarray-like objects - * @throws {TypeError} unable to resolve an ndarray function supporting the provided ndarray argument data types - * @returns {(ndarrayLike|Array|void)} destination array(s) - */ - function dispatcher() { - var arrays; - var dtypes; - var argc; - var idx; - var v; - var f; - var i; - - argc = arguments.length; - if ( argc !== nargs ) { - if ( argc < nargs ) { - throw new Error( format('0jr0l') ); - } - throw new Error( format('0jr0m') ); - } - arrays = []; - dtypes = []; - for ( i = 0; i < nargs; i++ ) { - v = arguments[ i ]; - if ( !isndarrayLike( v ) ) { - if ( i < nin ) { - throw new TypeError( format( '0jr5h', v ) ); - } else { - throw new TypeError( format( '0jr5i', v ) ); - } - } - arrays.push( v ); - dtypes.push( resolveEnum( getDType( v ) ) ); - } - // Resolve the ndarray function satisfying the input array types: - idx = gindexOfRow( nfcns, narrays, types, narrays, 1, 0, dtypes, 1, 0 ); - - // Check whether we were able to successfully resolve an ndarray function: - if ( idx < 0 ) { - throw new TypeError( format('0jr0n') ); - } - // Retrieve the ndarray function: - if ( fcn ) { - f = fcn; - } else { - f = fcns[ idx ]; - } - // Evaluate the ndarray function: - if ( data ) { - f( arrays, data[ idx ] ); - } else { - f( arrays ); - } - if ( nout === 1 ) { - return arrays[ narrays-1 ]; - } - if ( nout === 0 ) { - return; - } - return arrays.slice( nin ); - } -} - - -// EXPORTS // - -module.exports = dispatch; diff --git a/package.json b/package.json index db19487..e6c8bad 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.2", "description": "Create an ndarray function interface which performs multiple dispatch.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,58 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/assert-is-collection": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-function-array": "^0.2.2", - "@stdlib/assert-is-integer": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer": "^0.2.2", - "@stdlib/assert-is-positive-integer": "^0.2.2", - "@stdlib/blas-ext-base-gindex-of-row": "github:stdlib-js/blas-ext-base-gindex-of-row#main", - "@stdlib/ndarray-base-dtype-resolve-enum": "^0.2.2", - "@stdlib/ndarray-base-dtypes2enums": "github:stdlib-js/ndarray-base-dtypes2enums#main", - "@stdlib/ndarray-dtype": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.2.2", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/array-int32": "^0.2.2", - "@stdlib/array-int8": "^0.2.2", - "@stdlib/array-uint8": "^0.2.2", - "@stdlib/math-base-assert-is-nan": "^0.2.2", - "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/math-base-special-pow": "^0.3.0", - "@stdlib/math-base-special-sin": "^0.3.0", - "@stdlib/ndarray-base-buffer-dtype": "^0.3.0", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-unary": "^0.2.1", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-dtypes": "^0.3.0", - "@stdlib/ndarray-ind2sub": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "ndarray", @@ -101,7 +26,6 @@ "multimethod", "multimethods" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..6a59ed9 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/fixtures/binary.js b/test/fixtures/binary.js deleted file mode 100644 index a60dfa2..0000000 --- a/test/fixtures/binary.js +++ /dev/null @@ -1,38 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Binary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @returns {number} sum -*/ -function binary( x, y ) { - return x + y; -} - - -// EXPORTS // - -module.exports = binary; diff --git a/test/fixtures/fill.js b/test/fixtures/fill.js deleted file mode 100644 index 41b2958..0000000 --- a/test/fixtures/fill.js +++ /dev/null @@ -1,76 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which fills one or more ndarrays. -* -* @private -* @param {*} value - fill value -* @returns {Function} ndarray function -*/ -function fill( value ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - */ - function ndarrayFcn( arrays ) { - var opts; - var sub; - var arr; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - opts = { - 'order': '' - }; - for ( j = 0; j < M; j++ ) { - arr = arrays[ j ]; - opts.order = arrays[ j ].order; - for ( i = 0; i < N; i++ ) { - sub = ind2sub( sh, i, opts ); - sub.push( value ); - arr.set.apply( arr, sub ); - } - } - } -} - - -// EXPORTS // - -module.exports = fill; diff --git a/test/fixtures/foreach.js b/test/fixtures/foreach.js deleted file mode 100644 index a426290..0000000 --- a/test/fixtures/foreach.js +++ /dev/null @@ -1,72 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function forEach( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - fcn.apply( null, args ); - } -} - - -// EXPORTS // - -module.exports = forEach; diff --git a/test/fixtures/map1n.js b/test/fixtures/map1n.js deleted file mode 100644 index 614196b..0000000 --- a/test/fixtures/map1n.js +++ /dev/null @@ -1,74 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* ndarray function which maps the return value of a callback to `N` arrays. -* -* @private -* @param {Array} arrays - ndarrays -* @param {Function} fcn - callback -*/ -function map1N( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var v; - var i; - var j; - - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - for ( i = 0; i < N; i++ ) { - v = fcn(); - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - sub.push( v ); - arrays[ j ].set.apply( arrays[ j ], sub ); - } - } -} - - -// EXPORTS // - -module.exports = map1N; diff --git a/test/fixtures/nullary.js b/test/fixtures/nullary.js deleted file mode 100644 index 4f22126..0000000 --- a/test/fixtures/nullary.js +++ /dev/null @@ -1,36 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Nullary callback. -* -* @private -* @returns {number} value -*/ -function nullary() { - return 3.0; -} - - -// EXPORTS // - -module.exports = nullary; diff --git a/test/fixtures/quaternary.js b/test/fixtures/quaternary.js deleted file mode 100644 index 548437b..0000000 --- a/test/fixtures/quaternary.js +++ /dev/null @@ -1,40 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quaternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @returns {number} sum -*/ -function quaternary( x, y, z, w ) { - return x + y + z + w; -} - - -// EXPORTS // - -module.exports = quaternary; diff --git a/test/fixtures/quinary.js b/test/fixtures/quinary.js deleted file mode 100644 index 36068de..0000000 --- a/test/fixtures/quinary.js +++ /dev/null @@ -1,41 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MAIN // - -/** -* Quinary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @param {number} w - input value -* @param {number} u - input value -* @returns {number} sum -*/ -function quinary( x, y, z, w, u ) { - return x + y + z + w + u; -} - - -// EXPORTS // - -module.exports = quinary; diff --git a/test/fixtures/sum.js b/test/fixtures/sum.js deleted file mode 100644 index efdbb1b..0000000 --- a/test/fixtures/sum.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var ind2sub = require( '@stdlib/ndarray-ind2sub' ); -var numel = require( '@stdlib/ndarray-base-numel' ); - - -// MAIN // - -/** -* Return an ndarray function which computes the sum across one or more ndarrays. -* -* @private -* @param {Object} ctx - context -* @param {number} ctx.sum - initial sum -* @returns {Function} ndarray function -*/ -function wrapper( ctx ) { - return ndarrayFcn; - - /** - * ndarray function. - * - * @private - * @param {Array} arrays - ndarrays - * @param {Function} [fcn] - callback - */ - function ndarrayFcn( arrays, fcn ) { - var opts; - var ords; - var args; - var sub; - var sh; - var M; - var N; - var f; - var i; - var j; - - if ( arguments.length > 1 ) { - f = fcn; - } - sh = arrays[ 0 ].shape; - N = numel( sh ); - M = arrays.length; - ords = []; - args = []; - for ( j = 0; j < M; j++ ) { - ords.push( arrays[ j ].order ); - args.push( 0 ); - } - opts = { - 'order': '' - }; - if ( f ) { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - args[ j ] = arrays[ j ].get.apply( arrays[ j ], sub ); - } - ctx.sum += f.apply( null, args ); - } - } else { - for ( i = 0; i < N; i++ ) { - for ( j = 0; j < M; j++ ) { - opts.order = ords[ j ]; - sub = ind2sub( sh, i, opts ); - ctx.sum += arrays[ j ].get.apply( arrays[ j ], sub ); - } - } - } - } -} - - -// EXPORTS // - -module.exports = wrapper; diff --git a/test/fixtures/ternary.js b/test/fixtures/ternary.js deleted file mode 100644 index 0595d5f..0000000 --- a/test/fixtures/ternary.js +++ /dev/null @@ -1,39 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Ternary callback. -* -* @private -* @param {number} x - input value -* @param {number} y - input value -* @param {number} z - input value -* @returns {number} sum -*/ -function ternary( x, y, z ) { - return x + y + z; -} - - -// EXPORTS // - -module.exports = ternary; diff --git a/test/test.js b/test/test.js deleted file mode 100644 index d6c2c8e..0000000 --- a/test/test.js +++ /dev/null @@ -1,363 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var fill = require( './fixtures/fill.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either a function or an array of functions as a first argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( value, types, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided an array-like object as a second argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided either an array-like object or `null` as a third argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - void 0, - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - dispatch( unary, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a positive integer for a fourth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 0, - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a fifth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, value, 1 ); - }; - } -}); - -tape( 'the function throws an error if not provided a nonnegative integer for a sixth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - -1, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, 2, 1, value ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function array)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var fcns = [ unary, unary, unary ]; - var data = [ abs, abs, abs ]; - dispatch( fcns, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of types is incompatible with the number of types indicated by other function parameters (function argument)', function test( t ) { - var values; - var i; - - values = [ - [ 'float64' ], - [ 'float64', 'float64', 'float64' ], - [ 'float64', 'float32', 'float32' ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var data = [ abs, abs, abs ]; - dispatch( unary, value, data, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the length of `data` argument does not match the number of ndarray functions', function test( t ) { - var values; - var i; - - values = [ - [], - [ abs, abs ], - [ abs, abs, abs ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var fcns = [ unary ]; - dispatch( fcns, types, value, 2, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the fourth argument is incompatible with the number of input and output ndarrays', function test( t ) { - var values; - var i; - - values = [ - 0, - 1, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10 - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), Error, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var types = [ 'float64', 'float64' ]; - var data = [ abs ]; - dispatch( unary, types, data, value, 1, 1 ); - }; - } -}); - -tape( 'the function throws an error if the number of specified input and output ndarrays is zero', function test( t ) { - t.throws( badValue, Error, 'throws an error' ); - t.end(); - - function badValue() { - var types = [ 'float64' ]; - dispatch( fill( 3 ), types, null, 1, 0, 0 ); - } -}); - -tape( 'the function returns an ndarray function interface', function test( t ) { - var types; - var data; - var f; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - - f = dispatch( unary, types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ unary ], types, data, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( fill( 3 ), types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - f = dispatch( [ fill( 3 ) ], types, null, 2, 1, 1 ); - t.strictEqual( isFunction( f ), true, 'returns expected value' ); - - t.end(); -}); diff --git a/test/test.two_arrays.js b/test/test.two_arrays.js deleted file mode 100644 index 16eb61b..0000000 --- a/test/test.two_arrays.js +++ /dev/null @@ -1,814 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2021 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. -*/ - -/* eslint-disable array-element-newline */ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var unary = require( '@stdlib/ndarray-base-unary' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Float32Array = require( '@stdlib/array-float32' ); -var Int32Array = require( '@stdlib/array-int32' ); -var Uint8Array = require( '@stdlib/array-uint8' ); -var dtype = require( '@stdlib/ndarray-base-buffer-dtype' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var dispatch = require( './../lib' ); - - -// FIXTURES // - -var forEach = require( './fixtures/foreach.js' ); -var map1N = require( './fixtures/map1n.js' ); -var fill = require( './fixtures/fill.js' ); -var sum = require( './fixtures/sum.js' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof dispatch, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the first argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 5, - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var ybuf = new Float64Array( 10 ); - var y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( value, y ); - }; - } -}); - -tape( 'the function returns a function which throws an error if not provided an ndarray for the second argument', function test( t ) { - var values; - var types; - var data; - var fcn; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var xbuf = new Float64Array( 10 ); - var x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - fcn( x, value ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided insufficient arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var f; - var x; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [], - [ x ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if provided too many arguments', function test( t ) { - var values; - var types; - var data; - var xbuf; - var ybuf; - var f; - var x; - var y; - var i; - - types = [ 'float64', 'float64' ]; - data = [ abs ]; - f = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - values = [ - [ x, y, y ], - [ x, y, y, y ], - [ x, y, y, y, y ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( wrapper( values[i] ), Error, 'throws an error when provided ' + values[ i ].length + ' arguments' ); - } - t.end(); - - function wrapper( args ) { - return function fcn() { - f.apply( null, args ); - }; - } -}); - -tape( 'the function returns a function which throws an error if unable to resolve a ndarray function supporting the provided array argument data types', function test( t ) { - var values; - var types; - var data; - var xbuf; - var fcn; - var x; - var i; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ abs, abs ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 4 ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - values = [ - new Uint8Array( 4 ), - new Int32Array( 4 ), - [ 0, 0, 0, 0 ] - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided an array having data type: ' + dtype( values[i] ) ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var y = ndarray( dtype( value ), value, [ value.length ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - }; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only input arrays)', function test( t ) { - var types; - var xbuf; - var ybuf; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; no data; only output arrays)', function test( t ) { - var expected; - var types; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only input arrays)', function test( t ) { - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var ctx; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - ctx = { - 'sum': 0 - }; - fcns = [ - sum( ctx ), - sum( ctx ) - ]; - fcn = dispatch( fcns, types, null, 2, 2, 0 ); - - ctx.sum = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 20.0, 'returns expected value' ); - - ctx.sum = 5; - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - t.strictEqual( ctx.sum, 25.0, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; no data; only output arrays)', function test( t ) { - var expected; - var types; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - fcns = [ - fill( 3.0 ), - fill( 4.0 ) - ]; - fcn = dispatch( fcns, types, null, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( xbuf.length ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - - fcn = dispatch( forEach, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - - fcn = dispatch( map1N, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only input arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var cnt; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - clbk, - clbk - ]; - fcns = [ - forEach, - forEach - ]; - fcn = dispatch( fcns, types, data, 2, 2, 0 ); - cnt = 0; - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 4, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( cnt, 8, 'returns expected value' ); - - t.end(); - - function clbk() { - cnt += 1; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; only output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - three, - four - ]; - fcns = [ - map1N, - map1N - ]; - fcn = dispatch( fcns, types, data, 2, 0, 2 ); - - xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ 3.0, 3.0, 3.0, 3.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ 4.0, 4.0, 4.0, 4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); - - function three() { - return 3.0; - } - - function four() { - return 4.0; - } -}); - -tape( 'the function returns a function which invokes a callback for indexed ndarray elements (function array; data; input and output arrays)', function test( t ) { - var expected; - var types; - var data; - var fcns; - var xbuf; - var ybuf; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - data = [ - abs, - abs - ]; - fcns = [ - unary, - unary - ]; - fcn = dispatch( fcns, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float64', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float64', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float64Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - xbuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - x = ndarray( 'float32', xbuf, [ 4 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - y = ndarray( 'float32', ybuf, [ 4 ], [ 1 ], 0, 'row-major' ); - - fcn( x, y ); - - expected = new Float32Array( [ -1.0, -2.0, -3.0, -4.0 ] ); - t.deepEqual( xbuf, expected, 'returns expected value' ); - - expected = new Float32Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function returns a function which returns one or more output arrays, if one or more output arrays is specified, and otherwise returns `undefined`', function test( t ) { - var types; - var data; - var xbuf; - var ybuf; - var out; - var ctx; - var fcn; - var x; - var y; - - types = [ - 'float64', 'float64', - 'float32', 'float32' - ]; - - // No output arrays... - ctx = { - 'sum': 0 - }; - fcn = dispatch( sum( ctx ), types, null, 2, 2, 0 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, void 0, 'returns expected value' ); - - // One output array... - data = [ - abs, - abs - ]; - fcn = dispatch( unary, types, data, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - fcn = dispatch( fill( 3.0 ), types, null, 2, 1, 1 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out, y, 'returns expected value' ); - - // Two output arrays... - fcn = dispatch( fill( 3.0 ), types, null, 2, 0, 2 ); - - xbuf = new Float64Array( 10 ); - x = ndarray( 'float64', xbuf, [ 10 ], [ 1 ], 0, 'row-major' ); - ybuf = new Float64Array( xbuf.length ); - y = ndarray( 'float64', ybuf, [ 10 ], [ 1 ], 0, 'row-major' ); - - out = fcn( x, y ); - t.strictEqual( out.length, 2, 'returns expected value' ); - t.strictEqual( out[ 0 ], x, 'returns expected value' ); - t.strictEqual( out[ 1 ], y, 'returns expected value' ); - - t.end(); -});