From f885dd4f30e1003773e2fc1ecc7fbe8ddfd17acf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Apr 2022 09:48:07 +0000 Subject: [PATCH 01/91] Auto-generated commit 8d4c89adb1d84dbca7383b732ea7eef5c87322c6 --- CONTRIBUTORS | 28 + LICENSE | 481 +++++++++ NOTICE | 1 + README.md | 323 ++++++ index.d.ts | 257 +++++ index.mjs | 4 + index.mjs.map | 1 + package.json | 52 + stats.html | 2689 +++++++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 3836 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..d3daa7f --- /dev/null +++ b/README.md @@ -0,0 +1,323 @@ + + +# mapReduceRight + +[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] + +> Perform a single-pass map-reduce operation against each element in an array while iterating from right to left and return the accumulated result. + + + +
+ +
+ + + + + + + +
+ +## Usage + +```javascript +import mapReduceRight from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-map-reduce-right@esm/index.mjs'; +``` + +#### mapReduceRight( arr, initial, mapper, reducer\[, thisArg ] ) + +Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. + +```javascript +function square( value ) { + return value * value; +} + +function sum( accumulator, value ) { + return accumulator + value; +} + +var arr = [ 1, 2, 3, 4 ]; + +var out = mapReduceRight( arr, 0, square, sum ); +// returns 30 +``` + +The function accepts both array-like objects and [`ndarray`][@stdlib/ndarray/ctor]-like objects. + +```javascript +import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; + +function square( value ) { + return value * value; +} + +function sum( accumulator, value ) { + return accumulator + value; +} + +var opts = { + 'dtype': 'generic' +}; +var arr = array( [ [ 1, 2, 3 ], [ 4, 5, 6 ] ], opts ); + +var out = mapReduceRight( arr, 0, square, sum ); +// returns 91 +``` + +The mapping function is provided the following arguments: + +- **value**: array element. +- **index**: element index. +- **arr**: input array. + +The reducing function is provided the following arguments: + +- **accumulator**: accumulated value. +- **value**: result of applying the mapping function to the current array element. +- **index**: element index. +- **arr**: input array. + +To set the `this` context when invoking the reducing function, provide a `thisArg`. + + + +```javascript +function square( value ) { + return value * value; +} + +function sum( accumulator, value ) { + this.count += 1; + return accumulator + value; +} + +var arr = [ 1, 2, 3, 4 ]; + +var ctx = { + 'count': 0 +}; + +var out = mapReduceRight( arr, 0, square, sum, ctx ); +// returns 30 + +var mean = out / ctx.count; +// returns 7.5 +``` + +
+ + + + + +
+ +## Notes + +- The function supports array-like objects exposing getters and setters for array element access (e.g., [`Complex64Array`][@stdlib/array/complex64], [`Complex128Array`][@stdlib/array/complex128], etc). + + ```javascript + import Complex64Array from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-complex64@esm/index.mjs'; + import Complex64 from 'https://cdn.jsdelivr.net/gh/stdlib-js/complex-float32@esm/index.mjs'; + import cceil from 'https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-cceil@esm/index.mjs'; + import realf from 'https://cdn.jsdelivr.net/gh/stdlib-js/complex-realf@esm/index.mjs'; + import imagf from 'https://cdn.jsdelivr.net/gh/stdlib-js/complex-imagf@esm/index.mjs'; + + function sum( acc, z ) { + var re1 = realf( acc ); + var im1 = imagf( acc ); + var re2 = realf( z ); + var im2 = imagf( z ); + return new Complex64( re1+re2, im1+im2 ); + } + + var x = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] ); + + var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), cceil, sum ); + // returns + + var re = realf( v ); + // returns 20.0 + + var im = imagf( v ); + // returns 24.0 + ``` + +- For [`ndarray`][@stdlib/ndarray/ctor]-like objects, the function performs a single-pass map-reduce operation over the entire input [`ndarray`][@stdlib/ndarray/ctor] (i.e., higher-order [`ndarray`][@stdlib/ndarray/ctor] dimensions are flattened to a single-dimension). + +- When applying a function to [`ndarray`][@stdlib/ndarray/ctor]-like objects, performance will be best for [`ndarray`][@stdlib/ndarray/ctor]-like objects which are single-segment contiguous. + +
+ + + + + +
+ +## 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..41d747e --- /dev/null +++ b/index.d.ts @@ -0,0 +1,257 @@ +/* +* @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. +*/ + +// TypeScript Version: 2.0 + +/// + +import { Collection } from '@stdlib/types/object'; +import { ndarray } from '@stdlib/types/ndarray'; + +/** +* Callback invoked for each array element. +* +* @returns result +*/ +type Nullary = () => any; + +/** +* Callback invoked for each array element. +* +* @param value - array element +* @returns result +*/ +type Unary = ( value: any ) => any; + +/** +* Callback invoked for each array element. +* +* @param value - array element +* @param index - element index +* @returns result +*/ +type Binary = ( value: any, index: number ) => any; + +/** +* Callback invoked for each array element. +* +* @param value - array element +* @param index - element index +* @param arr - array +* @returns result +*/ +type Ternary = ( value: any, index: number, arr: ndarray ) => any; + +/** +* Callback invoked for each array element. +* +* @param value - array element +* @param index - element index +* @param arr - array +* @returns result +*/ +type ArrayTernary = ( value: any, index: number, arr: Collection ) => any; + +/** +* Callback invoked for each array element. +* +* @param value - array element +* @param index - element index +* @param arr - array +* @returns result +*/ +type Mapper = Nullary | Unary | Binary | Ternary; + +/** +* Callback invoked for each array element. +* +* @param value - array element +* @param index - element index +* @param arr - array +* @returns result +*/ +type ArrayMapper = Nullary | Unary | Binary | ArrayTernary; + +/** +* Function applied against an accumulator. +* +* @returns accumulator value +*/ +type NullaryReducer = () => void; + +/** +* Function applied against an accumulator. +* +* @param accumulator - accumulated value +* @returns accumulator value +*/ +type UnaryReducer = ( accumulator: any ) => any; + +/** +* Function applied against an accumulator. +* +* @param accumulator - accumulated value +* @param value - array element +* @returns accumulator value +*/ +type BinaryReducer = ( accumulator: any, value: any ) => any; + +/** +* Function applied against an accumulator. +* +* @param accumulator - accumulated value +* @param value - array element +* @param index - element index +* @returns accumulator value +*/ +type TernaryReducer = ( accumulator: any, value: any, index: number ) => any; + +/** +* Function applied against an accumulator. +* +* @param accumulator - accumulated value +* @param value - array element +* @param index - element index +* @param arr - array +* @returns accumulator value +*/ +type QuaternaryReducer = ( accumulator: any, value: any, index: number, arr: ndarray ) => any; // tslint:disable-line:max-line-length + +/** +* Function applied against an accumulator. +* +* @param accumulator - accumulated value +* @param value - array element +* @param index - element index +* @param arr - array +* @returns accumulator value +*/ +type ArrayQuaternaryReducer = ( accumulator: any, value: any, index: number, arr: Collection ) => any; // tslint:disable-line:max-line-length + +/** +* Function applied against an accumulator. +* +* @param accumulator - accumulated value +* @param value - array element +* @param index - element index +* @param arr - array +* @returns accumulator value +*/ +type Reducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | QuaternaryReducer; // tslint:disable-line:max-line-length + +/** +* Function applied against an accumulator. +* +* @param accumulator - accumulated value +* @param value - array element +* @param index - element index +* @param arr - array +* @returns accumulator value +*/ +type ArrayReducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | ArrayQuaternaryReducer; // tslint:disable-line:max-line-length + +/** +* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. +* +* ## Notes +* +* - The mapping function is provided four arguments: +* +* - **value**: array element. +* - **index**: element index. +* - **arr**: input array. +* +* - The reducing function is provided four arguments: +* +* - **accumulator**: accumulated value. +* - **value**: result after applying a mapping function to the current array element. +* - **index**: element index. +* - **arr**: input array. +* +* - If provided an empty array, the function returns the initial value. +* +* @param arr - input array +* @param initial - initial value +* @param mapper - mapping function +* @param reducer - reducing function +* @param thisArg - reducing function execution context +* @returns accumulated result +* +* @example +* var naryFunction = require( `@stdlib/utils/nary-function` ); +* var abs = require( `@stdlib/math/base/special/abs` ); +* var add = require( `@stdlib/math/base/ops/add` ); +* var array = require( `@stdlib/ndarray/array` ); +* +* var opts = { +* 'dtype': 'generic' +* }; +* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); +* +* var out = mapReduceRight( arr, 0, naryFunction( abs, 2 ), naryFunction( add, 2 ) ); +* // returns 21 +*/ +declare function mapReduceRight( arr: ndarray, initial: any, mapper: Mapper, reducer: Reducer, thisArg?: any ): any; // tslint:disable-line:max-line-length + +/** +* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. +* +* ## Notes +* +* - The mapping function is provided four arguments: +* +* - **value**: array element. +* - **index**: element index. +* - **arr**: input array. +* +* - The reducing function is provided four arguments: +* +* - **accumulator**: accumulated value. +* - **value**: result after applying a mapping function to the current array element. +* - **index**: element index. +* - **arr**: input array. +* +* - If provided an empty array, the function returns the initial value. +* +* @param arr - input array +* @param initial - initial value +* @param mapper - mapping function +* @param reducer - reducing function +* @param thisArg - reducing function execution context +* @returns accumulated result +* +* @example +* function square( value ) { +* return value * value; +* } +* +* function sum( acc, value ) { +* return acc + value; +* } +* +* var arr = [ 1, 2, 3, 4 ]; +* +* var out = mapReduceRight( arr, 0, square, sum ); +* // returns 30 +*/ +declare function mapReduceRight( arr: Collection, initial: any, mapper: ArrayMapper, reducer: ArrayReducer, thisArg?: any ): any; // tslint:disable-line:max-line-length + + +// EXPORTS // + +export = mapReduceRight; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..8b57935 --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@esm/index.mjs";var d=a;var o=r,m=t,l=e,f=s,j=n,u=i,h=function(r,t,e,s,n){var i,a,o,m,l,f,j,u,h,c,g;if(m=r.length,j=r.shape,i=r.data,u=r.strides,h=r.offset,a=r.order,l=r.getter,f=r.ref,0===j.length)return s.call(n,t,e(l(i,h),0,f),0,f);for(o=t,g=m-1;g>=0;g--)c=d(j,u,h,a,g,"throw"),o=s.call(n,o,e(l(i,c),g,f),g,f);return o},c=function(r,t,e,s,n){var i,a,d,o;for(i=r.data,a=r.getter,d=t,o=i.length-1;o>=0;o--)d=s.call(n,d,e(a(i,o),o,i),o,i);return d};var g=function(r,t,e,s,n){if(!l(e))throw new TypeError(u("invalid argument. Third argument must be a function. Value: `%s`.",e));if(!l(s))throw new TypeError(u("invalid argument. Fourth argument must be a function. Value: `%s`.",s));if(m(r))return h(f(r),t,e,s,n);if(o(r))return c(j(r),t,e,s,n);throw new TypeError(u("invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.",r))};export{g as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..bf3329f --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/ndarray.js","../lib/array.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Function} x.getter - callback for accessing `x` data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* var Complex64Array = require( '@stdlib/array-complex64' );\n* var Complex64 = require( '@stdlib/complex-float32' );\n* var realf = require( '@stdlib/complex-realf' );\n* var imagf = require( '@stdlib/complex-imagf' );\n* var cceil = require( '@stdlib/math-base-special-cceil' );\n* var cadd = require( '@stdlib/math-base-ops-cadd' );\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'getter': getter\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.getter;\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Function} x.getter - callback for accessing input array data elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'getter': getter\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.getter;\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar format = require( '@stdlib/string-format' );\nvar ndarrayFcn = require( './ndarray.js' );\nvar arrayFcn = require( './array.js' );\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/math-base-ops-add' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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* Perform a map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.\n*\n* @module @stdlib/utils-map-reduce-right\n*\n* @example\n* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' );\n*\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, sum );\n* // returns 30\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/math-base-ops-add' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],"names":["vind2bind","require$$0","isArrayLikeObject","isndarrayLike","require$$1","isFunction","require$$2","ndarraylike2object","require$$3","arraylike2object","require$$4","format","require$$5","ndarrayFcn","x","initial","mapper","reducer","thisArg","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","getter","call","arrayFcn","lib","arr","TypeError"],"mappings":";;4nBAsBA,IAAIA,EAAYC,EC4DhB,IC5DIC,EAAoBD,EACpBE,EAAgBC,EAChBC,EAAaC,EACbC,EAAqBC,EACrBC,EAAmBC,EACnBC,EAASC,EACTC,EFyEJ,SAAyBC,EAAGC,EAASC,EAAQC,EAASC,GACrD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMR,EAAEgB,OAGRL,EAAMX,EAAEiB,MAGRZ,EAAOL,EAAEkB,KAGTN,EAAKZ,EAAEmB,QAGPN,EAAKb,EAAEoB,OAGPd,EAAON,EAAEqB,MAGTZ,EAAMT,EAAEsB,OAGRZ,EAAMV,EAAEU,IAGY,IAAfC,EAAIK,OACR,OAAOb,EAAQoB,KAAMnB,EAASH,EAASC,EAAQO,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMN,EACAc,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAK5B,EAAWyB,EAAKC,EAAIC,EAAIP,EAAMS,EAtH1B,SAuHTR,EAAMJ,EAAQoB,KAAMnB,EAASG,EAAKL,EAAQO,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,GEvHJiB,ED8BJ,SAAyBxB,EAAGC,EAASC,EAAQC,EAASC,GACrD,IAAIC,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOL,EAAEkB,KAGTT,EAAMT,EAAEsB,OAGRf,EAAMN,EACAc,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMJ,EAAQoB,KAAMnB,EAASG,EAAKL,EAAQO,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,GCiCR,IC7CAkB,ED0BA,SAAyBC,EAAKzB,EAASC,EAAQC,EAASC,GACvD,IAAMb,EAAYW,GACjB,MAAM,IAAIyB,UAAW9B,EAAQ,oEAAqEK,IAEnG,IAAMX,EAAYY,GACjB,MAAM,IAAIwB,UAAW9B,EAAQ,qEAAsEM,IAEpG,GAAKd,EAAeqC,GACnB,OAAO3B,EAAYN,EAAoBiC,GAAOzB,EAASC,EAAQC,EAASC,GAEzE,GAAKhB,EAAmBsC,GACvB,OAAOF,EAAU7B,EAAkB+B,GAAOzB,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIuB,UAAW9B,EAAQ,4FAA6F6B"} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..84f1b78 --- /dev/null +++ b/package.json @@ -0,0 +1,52 @@ +{ + "name": "@stdlib/utils-map-reduce-right", + "version": "0.0.0", + "description": "Perform a single-pass map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.", + "license": "Apache-2.0", + "type": "module", + "main": "./index.mjs", + "homepage": "https://stdlib.io", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/utils-map-reduce-right.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "keywords": [ + "stdlib", + "stdutils", + "stdutil", + "utilities", + "utility", + "utils", + "util", + "map", + "transform", + "map-reduce", + "reduce", + "reducer", + "reduction", + "array.map", + "array.reduce", + "iterate", + "aggregate", + "accumulator", + "accumulate", + "accumulation", + "collection", + "typed-array", + "typed array", + "typed", + "array", + "array-like", + "ndarray", + "tensor", + "matrix", + "vector" + ], + "funding": { + "type": "patreon", + "url": "https://www.patreon.com/athan" + } +} diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..4ff22d3 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + From 89b807a0d3e3c495e783b7b48acb62827989d139 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 30 Jun 2022 23:12:32 +0000 Subject: [PATCH 02/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index d95cde3..c890358 100644 --- a/lib/main.js +++ b/lib/main.js @@ -25,7 +25,7 @@ var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); var isFunction = require( '@stdlib/assert-is-function' ); var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ndarrayFcn = require( './ndarray.js' ); var arrayFcn = require( './array.js' ); @@ -90,10 +90,10 @@ var arrayFcn = require( './array.js' ); */ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( !isFunction( mapper ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) ); + throw new TypeError( format( '0kW3Z', mapper ) ); } if ( !isFunction( reducer ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) ); + throw new TypeError( format( '0kW3E', reducer ) ); } if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len @@ -101,7 +101,7 @@ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( isArrayLikeObject( arr ) ) { return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len } - throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) ); + throw new TypeError( format( '0kWC4', arr ) ); } diff --git a/package.json b/package.json index a522b3d..35888db 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-ndarray-like": "^0.0.x", "@stdlib/ndarray-base-ndarraylike2object": "^0.0.x", "@stdlib/ndarray-base-vind2bind": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From be237ad4383478bb7dd7a83dabd3f12b5e9abe64 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 07:33:50 +0000 Subject: [PATCH 03/91] Remove files --- index.d.ts | 257 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2951 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 41d747e..0000000 --- a/index.d.ts +++ /dev/null @@ -1,257 +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. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Collection } from '@stdlib/types/object'; -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* Callback invoked for each array element. -* -* @returns result -*/ -type Nullary = () => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @returns result -*/ -type Unary = ( value: any ) => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @returns result -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Ternary = ( value: any, index: number, arr: ndarray ) => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayTernary = ( value: any, index: number, arr: Collection ) => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Mapper = Nullary | Unary | Binary | Ternary; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayMapper = Nullary | Unary | Binary | ArrayTernary; - -/** -* Function applied against an accumulator. -* -* @returns accumulator value -*/ -type NullaryReducer = () => void; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @returns accumulator value -*/ -type UnaryReducer = ( accumulator: any ) => any; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @returns accumulator value -*/ -type BinaryReducer = ( accumulator: any, value: any ) => any; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @returns accumulator value -*/ -type TernaryReducer = ( accumulator: any, value: any, index: number ) => any; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type QuaternaryReducer = ( accumulator: any, value: any, index: number, arr: ndarray ) => any; // tslint:disable-line:max-line-length - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayQuaternaryReducer = ( accumulator: any, value: any, index: number, arr: Collection ) => any; // tslint:disable-line:max-line-length - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type Reducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | QuaternaryReducer; // tslint:disable-line:max-line-length - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayReducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | ArrayQuaternaryReducer; // tslint:disable-line:max-line-length - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* var naryFunction = require( `@stdlib/utils/nary-function` ); -* var abs = require( `@stdlib/math/base/special/abs` ); -* var add = require( `@stdlib/math/base/ops/add` ); -* var array = require( `@stdlib/ndarray/array` ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 2 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -declare function mapReduceRight( arr: ndarray, initial: any, mapper: Mapper, reducer: Reducer, thisArg?: any ): any; // tslint:disable-line:max-line-length - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -*/ -declare function mapReduceRight( arr: Collection, initial: any, mapper: ArrayMapper, reducer: ArrayReducer, thisArg?: any ): any; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = mapReduceRight; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 8b57935..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@esm/index.mjs";var d=a;var o=r,m=t,l=e,f=s,j=n,u=i,h=function(r,t,e,s,n){var i,a,o,m,l,f,j,u,h,c,g;if(m=r.length,j=r.shape,i=r.data,u=r.strides,h=r.offset,a=r.order,l=r.getter,f=r.ref,0===j.length)return s.call(n,t,e(l(i,h),0,f),0,f);for(o=t,g=m-1;g>=0;g--)c=d(j,u,h,a,g,"throw"),o=s.call(n,o,e(l(i,c),g,f),g,f);return o},c=function(r,t,e,s,n){var i,a,d,o;for(i=r.data,a=r.getter,d=t,o=i.length-1;o>=0;o--)d=s.call(n,d,e(a(i,o),o,i),o,i);return d};var g=function(r,t,e,s,n){if(!l(e))throw new TypeError(u("invalid argument. Third argument must be a function. Value: `%s`.",e));if(!l(s))throw new TypeError(u("invalid argument. Fourth argument must be a function. Value: `%s`.",s));if(m(r))return h(f(r),t,e,s,n);if(o(r))return c(j(r),t,e,s,n);throw new TypeError(u("invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.",r))};export{g as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index bf3329f..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/ndarray.js","../lib/array.js","../lib/main.js","../lib/index.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Function} x.getter - callback for accessing `x` data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* var Complex64Array = require( '@stdlib/array-complex64' );\n* var Complex64 = require( '@stdlib/complex-float32' );\n* var realf = require( '@stdlib/complex-realf' );\n* var imagf = require( '@stdlib/complex-imagf' );\n* var cceil = require( '@stdlib/math-base-special-cceil' );\n* var cadd = require( '@stdlib/math-base-ops-cadd' );\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'getter': getter\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.getter;\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Function} x.getter - callback for accessing input array data elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'getter': getter\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.getter;\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar format = require( '@stdlib/string-format' );\nvar ndarrayFcn = require( './ndarray.js' );\nvar arrayFcn = require( './array.js' );\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/math-base-ops-add' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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* Perform a map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.\n*\n* @module @stdlib/utils-map-reduce-right\n*\n* @example\n* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' );\n*\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, sum );\n* // returns 30\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/math-base-ops-add' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],"names":["vind2bind","require$$0","isArrayLikeObject","isndarrayLike","require$$1","isFunction","require$$2","ndarraylike2object","require$$3","arraylike2object","require$$4","format","require$$5","ndarrayFcn","x","initial","mapper","reducer","thisArg","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","getter","call","arrayFcn","lib","arr","TypeError"],"mappings":";;4nBAsBA,IAAIA,EAAYC,EC4DhB,IC5DIC,EAAoBD,EACpBE,EAAgBC,EAChBC,EAAaC,EACbC,EAAqBC,EACrBC,EAAmBC,EACnBC,EAASC,EACTC,EFyEJ,SAAyBC,EAAGC,EAASC,EAAQC,EAASC,GACrD,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMR,EAAEgB,OAGRL,EAAMX,EAAEiB,MAGRZ,EAAOL,EAAEkB,KAGTN,EAAKZ,EAAEmB,QAGPN,EAAKb,EAAEoB,OAGPd,EAAON,EAAEqB,MAGTZ,EAAMT,EAAEsB,OAGRZ,EAAMV,EAAEU,IAGY,IAAfC,EAAIK,OACR,OAAOb,EAAQoB,KAAMnB,EAASH,EAASC,EAAQO,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMN,EACAc,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAK5B,EAAWyB,EAAKC,EAAIC,EAAIP,EAAMS,EAtH1B,SAuHTR,EAAMJ,EAAQoB,KAAMnB,EAASG,EAAKL,EAAQO,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,GEvHJiB,ED8BJ,SAAyBxB,EAAGC,EAASC,EAAQC,EAASC,GACrD,IAAIC,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOL,EAAEkB,KAGTT,EAAMT,EAAEsB,OAGRf,EAAMN,EACAc,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMJ,EAAQoB,KAAMnB,EAASG,EAAKL,EAAQO,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,GCiCR,IC7CAkB,ED0BA,SAAyBC,EAAKzB,EAASC,EAAQC,EAASC,GACvD,IAAMb,EAAYW,GACjB,MAAM,IAAIyB,UAAW9B,EAAQ,oEAAqEK,IAEnG,IAAMX,EAAYY,GACjB,MAAM,IAAIwB,UAAW9B,EAAQ,qEAAsEM,IAEpG,GAAKd,EAAeqC,GACnB,OAAO3B,EAAYN,EAAoBiC,GAAOzB,EAASC,EAAQC,EAASC,GAEzE,GAAKhB,EAAmBsC,GACvB,OAAOF,EAAU7B,EAAkB+B,GAAOzB,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIuB,UAAW9B,EAAQ,4FAA6F6B"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 4ff22d3..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From ae05ac6c197632a2d7fcf677af64c1218703ae1a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 07:34:49 +0000 Subject: [PATCH 04/91] 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 | 63 +- benchmark/benchmark.array.js | 98 - benchmark/benchmark.ndarray.js | 109 - branches.md | 53 - docs/repl.txt | 65 - docs/types/test.ts | 184 -- examples/index.js | 52 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/array.js | 83 - lib/index.js | 65 - lib/main.js | 110 - lib/ndarray.js | 155 -- package.json | 76 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 637 ----- 40 files changed, 2725 insertions(+), 4570 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.array.js delete mode 100644 benchmark/benchmark.ndarray.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/array.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/ndarray.js create mode 100644 stats.html delete mode 100644 test/test.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 6d0a4d1..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-06-30T22:50:24.553Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3b4c7b4..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/utils/map-reduce-right) 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 bbe0806..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/utils/map-reduce-right) 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 + + ```
@@ -260,7 +253,7 @@ console.log( 'sum: %d', out ); ## 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]. @@ -320,11 +313,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/utils-map-reduce-right/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/stdlib +[@stdlib/array/complex64]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/array/complex128]: https://github.com/stdlib-js/stdlib +[@stdlib/array/complex128]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.array.js b/benchmark/benchmark.array.js deleted file mode 100644 index e87feb5..0000000 --- a/benchmark/benchmark.array.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = filled( -3.0, len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::array:len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.ndarray.js b/benchmark/benchmark.ndarray.js deleted file mode 100644 index e3bfba2..0000000 --- a/benchmark/benchmark.ndarray.js +++ /dev/null @@ -1,109 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var xbuf; - var opts; - var x; - - xbuf = filled( -3.0, len ); - - opts = { - 'dtype': 'generic' - }; - x = array( xbuf, opts ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::ndarray:len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 651bb38..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/utils/map-reduce-right" -click B href "https://github.com/stdlib-js/utils-map-reduce-right/tree/main" -click C href "https://github.com/stdlib-js/utils-map-reduce-right/tree/production" -click D href "https://github.com/stdlib-js/utils-map-reduce-right/tree/esm" -click E href "https://github.com/stdlib-js/utils-map-reduce-right/tree/deno" -click F href "https://github.com/stdlib-js/utils-map-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/map-reduce-right -[production-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b580e87..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, initial, mapper, reducer[, thisArg] ) - Performs a map-reduce operation for each element in an array while iterating - from right to left and returns the accumulated result. - - When invoked, the mapping function is provided three arguments: - - - value: array element. - - index: element index. - - arr: input array. - - When invoked, the reducing function is provided four arguments: - - - accumulator: accumulated value. - - value: result after applying the mapping function to the current array - element. - - index: element index. - - arr: input array. - - If provided an empty array, the function returns the initial value. - - When provided an ndarray, the function performs a single-pass map-reduce - operation over the entire input ndarray (i.e., higher-order ndarray - dimensions are flattened to a single-dimension). - - Parameters - ---------- - arr: ArrayLikeObject|ndarray - Input array. - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - mapper: Function - Mapping function. - - reducer: Function - Reducing function. - - thisArg: any (optional) - Execution context for the reducing function. - - Returns - ------- - out: any - Accumulated result. - - Examples - -------- - // array-like object: - > var f1 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/special/abs}}, 1 ); - > var f2 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/ops/add}}, 2 ); - > var arr = [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0 ]; - > var out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - // ndarray: - > arr = {{alias:@stdlib/ndarray/array}}( arr, { 'shape': [ 2, 3 ] } ); - > out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 76168a1..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,184 +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. -*/ - -import array = require( '@stdlib/ndarray-array' ); -import mapReduceRight = require( './index' ); - -/** -* Mapping function. -* -* @param value - array element -* @returns result -*/ -function mapper( value: number ): number { - return value; -} - -/** -* Reducing function. -* -* @param acc - accumulated value -* @param v - array element -* @returns result -*/ -function reducer( acc: number, value: number ): number { - return acc + value; -} - - -// TESTS // - -// The function returns the accumulated value when provided a collection... -{ - mapReduceRight( [ 0, 1, 1, NaN, 2 ], 0, mapper, reducer ); // $ExpectType any - mapReduceRight( [ -1, 1, 2 ], 100, mapper, reducer ); // $ExpectType any - mapReduceRight( [ -1, 1, 2 ], 0, mapper, reducer, {} ); // $ExpectType any -} - -// The function returns the accumulated value when provided an ndarray... -{ - const arr = array( [ 1, 2, 3, 4, 5, 6 ] ); - - mapReduceRight( arr, 0, mapper, reducer ); // $ExpectType any - mapReduceRight( arr, 100, mapper, reducer ); // $ExpectType any - mapReduceRight( arr, 0, mapper, reducer, {} ); // $ExpectType any -} - -// The compiler throws an error if the function is provided a first argument which is not a collection or ndarray... -{ - mapReduceRight( 2, 0, mapper, reducer ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer ); // $ExpectError - - mapReduceRight( 2, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr1, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr2, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const arr1 = [ 1, 2, 3 ]; - - mapReduceRight(); // $ExpectError - mapReduceRight( arr1 ); // $ExpectError - mapReduceRight( arr1, 0 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ); // $ExpectError - mapReduceRight( arr1, 0, mapper, reducer, {}, 3 ); // $ExpectError - - const arr2 = array( [ 1, 2, 3 ] ); - - mapReduceRight(); // $ExpectError - mapReduceRight( arr2 ); // $ExpectError - mapReduceRight( arr2, 0 ); // $ExpectError - mapReduceRight( arr2, 0, mapper ); // $ExpectError - mapReduceRight( arr2, 0, mapper, reducer, {}, 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 7474059..0000000 --- a/examples/index.js +++ /dev/null @@ -1,52 +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. -*/ - -'use strict'; - -var filledarrayBy = require( '@stdlib/array-filled-by' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ).factory; -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var mapReduceRight = require( './../lib' ); - -function fill( i ) { - var rand = discreteUniform( -10*(i+1), 10*(i+1) ); - return filledarrayBy( 10, 'generic', rand ); -} - -// Create a two-dimensional ndarray (i.e., a matrix): -var x = array( filledarrayBy( 10, 'generic', fill ), { - 'dtype': 'generic', - 'flatten': true -}); - -// Create an explicit unary function: -var f1 = naryFunction( abs, 1 ); - -// Create an explicit binary function: -var f2 = naryFunction( add, 2 ); - -// Compute the sum of absolute values: -var out = mapReduceRight( x, 0, f1, f2 ); - -console.log( 'x:' ); -console.log( x.data ); - -console.log( 'sum: %d', out ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index a2eace0..41d747e 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Collection } from '@stdlib/types/object'; import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..6dac8d7 --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@esm/index.mjs";function o(o,a,m,l,j){if(!e(m))throw new TypeError(n("0kW3Z",m));if(!e(l))throw new TypeError(n("0kW3E",l));if(t(o))return function(r,t,e,s,i){var n,o,a,m,l,j,f,h,p,c,b;if(m=r.length,f=r.shape,n=r.data,h=r.strides,p=r.offset,o=r.order,l=r.getter,j=r.ref,0===f.length)return s.call(i,t,e(l(n,p),0,j),0,j);for(a=t,b=m-1;b>=0;b--)c=d(f,h,p,o,b,"throw"),a=s.call(i,a,e(l(n,c),b,j),b,j);return a}(s(o),a,m,l,j);if(r(o))return function(r,t,e,s,i){var n,d,o,a;for(n=r.data,d=r.getter,o=t,a=n.length-1;a>=0;a--)o=s.call(i,o,e(d(n,a),a,n),a,n);return o}(i(o),a,m,l,j);throw new TypeError(n("0kWC4",o))}export{o as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..703007b --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js","../lib/ndarray.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object' ;\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object' ;\nimport arraylike2object from '@stdlib/array-base-arraylike2object' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport ndarrayFcn from './ndarray.js' ;\nimport arrayFcn from './array.js' ;\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function' ;\n* import add from '@stdlib/math-base-ops-add' ;\n* import abs from '@stdlib/math-base-special-abs' ;\n* import array from '@stdlib/ndarray-array' ;\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '0kW3Z', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '0kW3E', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '0kWC4', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind' ;\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Function} x.getter - callback for accessing `x` data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64' ;\n* import Complex64 from '@stdlib/complex-float32' ;\n* import realf from '@stdlib/complex-realf' ;\n* import imagf from '@stdlib/complex-imagf' ;\n* import cceil from '@stdlib/math-base-special-cceil' ;\n* import cadd from '@stdlib/math-base-ops-cadd' ;\n* import naryFunction from '@stdlib/utils-nary-function' ;\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'getter': getter\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.getter;\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Function} x.getter - callback for accessing input array data elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'getter': getter\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.getter;\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","getter","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;qoBA0FA,SAASA,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,GAAKK,EAAeR,GACnB,OCGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,OAGRZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAtH1B,SAuHTR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,EDlDCkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OE1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,OAGRf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,EFyBCqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,QAASP"} \ No newline at end of file diff --git a/lib/array.js b/lib/array.js deleted file mode 100644 index 9f87c1f..0000000 --- a/lib/array.js +++ /dev/null @@ -1,83 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input array data -* @param {ArrayLikeObject} x.data - input array data -* @param {Function} x.getter - callback for accessing input array data elements -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf[ idx ]; -* } -* -* // Create the input array object: -* var x = { -* 'data': [ 1, 2, 3, 4 ], -* 'getter': getter -* }; -* -* // Compute the sum of squared values: -* var out = mapReduceRight( x, 0, square, sum ); -* // returns 30 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var get; - var acc; - var i; - - // Cache reference to the input data: - xbuf = x.data; - - // Cache the element accessor: - get = x.getter; - - // Iterate over each element... - acc = initial; - for ( i = xbuf.length-1; i >= 0; i-- ) { - acc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 522693e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +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. -*/ - -'use strict'; - -/** -* Perform a map-reduce operation against each element in an array while iterating from right to left and return the accumulated result. -* -* @module @stdlib/utils-map-reduce-right -* -* @example -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ - -// 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 c890358..0000000 --- a/lib/main.js +++ /dev/null @@ -1,110 +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. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ndarrayFcn = require( './ndarray.js' ); -var arrayFcn = require( './array.js' ); - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided the following arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided the following arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result of applying the mapping function against the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* @param {(ArrayLikeObject|ndarray)} arr - input array -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} [thisArg] - reduction function execution context -* @throws {TypeError} first argument must be an array-like object or an ndarray -* @throws {TypeError} third argument must be a function -* @throws {TypeError} fourth argument must be a function -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { - if ( !isFunction( mapper ) ) { - throw new TypeError( format( '0kW3Z', mapper ) ); - } - if ( !isFunction( reducer ) ) { - throw new TypeError( format( '0kW3E', reducer ) ); - } - if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like - return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - if ( isArrayLikeObject( arr ) ) { - return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - throw new TypeError( format( '0kWC4', arr ) ); -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/ndarray.js b/lib/ndarray.js deleted file mode 100644 index 8b2442d..0000000 --- a/lib/ndarray.js +++ /dev/null @@ -1,155 +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. -*/ - -'use strict'; - -// MODULES // - -var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); - - -// VARIABLES // - -var MODE = 'throw'; - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input ndarray meta data -* @param {string} x.ref - reference to original input ndarray-like object -* @param {string} x.dtype - data type -* @param {Collection} x.data - data buffer -* @param {NonNegativeInteger} x.length - number of elements -* @param {NonNegativeIntegerArray} x.shape - dimensions -* @param {IntegerArray} x.strides - stride lengths -* @param {NonNegativeInteger} x.offset - index offset -* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) -* @param {Function} x.getter - callback for accessing `x` data buffer elements -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var Complex64 = require( '@stdlib/complex-float32' ); -* var realf = require( '@stdlib/complex-realf' ); -* var imagf = require( '@stdlib/complex-imagf' ); -* var cceil = require( '@stdlib/math-base-special-cceil' ); -* var cadd = require( '@stdlib/math-base-ops-cadd' ); -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* -* // Create a data buffer: -* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] ); -* -* // Define the shape of the input array: -* var shape = [ 2, 2 ]; -* -* // Define the array strides: -* var sx = [ 2, 1 ]; -* -* // Define the index offset: -* var ox = 0; -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf.get( idx ); -* } -* -* // Create the input ndarray-like object: -* var x = { -* 'ref': null, -* 'dtype': 'complex64', -* 'data': xbuf, -* 'length': 4, -* 'shape': shape, -* 'strides': sx, -* 'offset': ox, -* 'order': 'row-major', -* 'getter': getter -* }; -* x.ref = x; -* -* // Compute the sum: -* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) ); -* -* var re = realf( v ); -* // returns 20.0 -* -* var im = imagf( v ); -* // returns 24.0 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var ordx; - var acc; - var len; - var get; - var ref; - var shx; - var sx; - var ox; - var ix; - var i; - - // Cache the total number of elements over which to iterate: - len = x.length; - - // Cache the input array shape: - shx = x.shape; - - // Cache reference to the input ndarray data buffer: - xbuf = x.data; - - // Cache reference to the stride array: - sx = x.strides; - - // Cache the index of the first indexed element: - ox = x.offset; - - // Cache the array order: - ordx = x.order; - - // Cache the element accessor: - get = x.getter; - - // Cache the reference to the original input array: - ref = x.ref; - - // Check for a zero-dimensional array... - if ( shx.length === 0 ) { - return reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len - } - // Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)... - acc = initial; - for ( i = len-1; i >= 0; i-- ) { - ix = vind2bind( shx, sx, ox, ordx, i, MODE ); - acc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/package.json b/package.json index 35888db..58c2ca2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.1", "description": "Perform a single-pass map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.", "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/array-base-arraylike2object": "^0.0.x", - "@stdlib/assert-is-array-like-object": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-ndarray-like": "^0.0.x", - "@stdlib/ndarray-base-ndarraylike2object": "^0.0.x", - "@stdlib/ndarray-base-vind2bind": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-base-filled": "^0.0.x", - "@stdlib/array-complex64": "^0.0.x", - "@stdlib/array-filled-by": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/complex-float32": "^0.0.x", - "@stdlib/complex-imagf": "^0.0.x", - "@stdlib/complex-realf": "^0.0.x", - "@stdlib/math-base-assert-is-nan": "^0.0.x", - "@stdlib/math-base-ops-add": "^0.0.x", - "@stdlib/math-base-ops-cadd": "^0.0.x", - "@stdlib/math-base-special-abs": "^0.0.x", - "@stdlib/math-base-special-cceil": "^0.0.x", - "@stdlib/math-base-special-pow": "^0.0.x", - "@stdlib/ndarray-array": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/random-base-discrete-uniform": "^0.0.x", - "@stdlib/utils-nary-function": "^0.0.x", - "@stdlib/utils-noop": "^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", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..4831851 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2c78efa..0000000 --- a/test/test.js +++ /dev/null @@ -1,637 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var cadd = require( '@stdlib/math-base-ops-cadd' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var cceil = require( '@stdlib/math-base-special-cceil' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var mapReduceRight = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapReduceRight, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a first argument which is either an array-like object or an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( value, 0, noop, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value, {} ); - }; - } -}); - -tape( 'the function performs a map-reduce operation for each element in an array (array-like object)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = [ -1, -2, -3 ]; - expected = 7; - actual = mapReduceRight( arr, 1, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (typed array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - expected = 7.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (complex number array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( cceil, 1 ); - f2 = naryFunction( cadd, 2 ); - - arr = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5 ] ); - expected = new Complex64( 12.0, 15.0 ); - actual = mapReduceRight( arr, new Complex64( 0.0, 0.0 ), f1, f2 ); - - t.strictEqual( realf( actual ), realf( expected ), 'returns expected value' ); - t.strictEqual( imagf( actual ), imagf( expected ), 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = array( [ -1.0, -2.0, -3.0, -4.0 ], { - 'dtype': 'generic' - }); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray; 0-dimensional)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = ndarray( 'generic', [ -10.0 ], [], [ 0 ], 0, 'row-major' ); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (array-like object)', function test( t ) { - var out = mapReduceRight( [], 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (ndarray)', function test( t ) { - var arr; - var out; - - arr = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 0, 2 ], [ 0, 2, 1 ], 0, 'row-major' ); - out = mapReduceRight( arr, 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function supports providing a `this` context (array-like object)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = [ -1.0, -2.0, -3.0 ]; - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function supports providing a `this` context (ndarray)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = array( [ -1.0, -2.0, -3.0 ], { - 'dtype': 'generic' - }); - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = array( [ 1, , , 4 ], { // eslint-disable-line no-sparse-arrays - 'dtype': 'generic' - }); - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); From 6a51edf62a00f0862eeda19fff25c1d12e3d7546 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 16:46:33 +0000 Subject: [PATCH 05/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index d95cde3..c890358 100644 --- a/lib/main.js +++ b/lib/main.js @@ -25,7 +25,7 @@ var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); var isFunction = require( '@stdlib/assert-is-function' ); var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ndarrayFcn = require( './ndarray.js' ); var arrayFcn = require( './array.js' ); @@ -90,10 +90,10 @@ var arrayFcn = require( './array.js' ); */ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( !isFunction( mapper ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) ); + throw new TypeError( format( '0kW3Z', mapper ) ); } if ( !isFunction( reducer ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) ); + throw new TypeError( format( '0kW3E', reducer ) ); } if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len @@ -101,7 +101,7 @@ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( isArrayLikeObject( arr ) ) { return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len } - throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) ); + throw new TypeError( format( '0kWC4', arr ) ); } diff --git a/package.json b/package.json index a522b3d..35888db 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-ndarray-like": "^0.0.x", "@stdlib/ndarray-base-ndarraylike2object": "^0.0.x", "@stdlib/ndarray-base-vind2bind": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From b0dd7e399ff712b5b5af889a97ab39e73956e3b5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Jul 2022 11:56:21 +0000 Subject: [PATCH 06/91] Remove files --- index.d.ts | 257 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2951 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 41d747e..0000000 --- a/index.d.ts +++ /dev/null @@ -1,257 +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. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Collection } from '@stdlib/types/object'; -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* Callback invoked for each array element. -* -* @returns result -*/ -type Nullary = () => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @returns result -*/ -type Unary = ( value: any ) => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @returns result -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Ternary = ( value: any, index: number, arr: ndarray ) => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayTernary = ( value: any, index: number, arr: Collection ) => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Mapper = Nullary | Unary | Binary | Ternary; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayMapper = Nullary | Unary | Binary | ArrayTernary; - -/** -* Function applied against an accumulator. -* -* @returns accumulator value -*/ -type NullaryReducer = () => void; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @returns accumulator value -*/ -type UnaryReducer = ( accumulator: any ) => any; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @returns accumulator value -*/ -type BinaryReducer = ( accumulator: any, value: any ) => any; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @returns accumulator value -*/ -type TernaryReducer = ( accumulator: any, value: any, index: number ) => any; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type QuaternaryReducer = ( accumulator: any, value: any, index: number, arr: ndarray ) => any; // tslint:disable-line:max-line-length - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayQuaternaryReducer = ( accumulator: any, value: any, index: number, arr: Collection ) => any; // tslint:disable-line:max-line-length - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type Reducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | QuaternaryReducer; // tslint:disable-line:max-line-length - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayReducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | ArrayQuaternaryReducer; // tslint:disable-line:max-line-length - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* var naryFunction = require( `@stdlib/utils/nary-function` ); -* var abs = require( `@stdlib/math/base/special/abs` ); -* var add = require( `@stdlib/math/base/ops/add` ); -* var array = require( `@stdlib/ndarray/array` ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 2 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -declare function mapReduceRight( arr: ndarray, initial: any, mapper: Mapper, reducer: Reducer, thisArg?: any ): any; // tslint:disable-line:max-line-length - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -*/ -declare function mapReduceRight( arr: Collection, initial: any, mapper: ArrayMapper, reducer: ArrayReducer, thisArg?: any ): any; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = mapReduceRight; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 6dac8d7..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@esm/index.mjs";function o(o,a,m,l,j){if(!e(m))throw new TypeError(n("0kW3Z",m));if(!e(l))throw new TypeError(n("0kW3E",l));if(t(o))return function(r,t,e,s,i){var n,o,a,m,l,j,f,h,p,c,b;if(m=r.length,f=r.shape,n=r.data,h=r.strides,p=r.offset,o=r.order,l=r.getter,j=r.ref,0===f.length)return s.call(i,t,e(l(n,p),0,j),0,j);for(a=t,b=m-1;b>=0;b--)c=d(f,h,p,o,b,"throw"),a=s.call(i,a,e(l(n,c),b,j),b,j);return a}(s(o),a,m,l,j);if(r(o))return function(r,t,e,s,i){var n,d,o,a;for(n=r.data,d=r.getter,o=t,a=n.length-1;a>=0;a--)o=s.call(i,o,e(d(n,a),a,n),a,n);return o}(i(o),a,m,l,j);throw new TypeError(n("0kWC4",o))}export{o as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 703007b..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js","../lib/ndarray.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object' ;\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object' ;\nimport arraylike2object from '@stdlib/array-base-arraylike2object' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport ndarrayFcn from './ndarray.js' ;\nimport arrayFcn from './array.js' ;\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function' ;\n* import add from '@stdlib/math-base-ops-add' ;\n* import abs from '@stdlib/math-base-special-abs' ;\n* import array from '@stdlib/ndarray-array' ;\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '0kW3Z', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '0kW3E', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '0kWC4', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind' ;\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Function} x.getter - callback for accessing `x` data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64' ;\n* import Complex64 from '@stdlib/complex-float32' ;\n* import realf from '@stdlib/complex-realf' ;\n* import imagf from '@stdlib/complex-imagf' ;\n* import cceil from '@stdlib/math-base-special-cceil' ;\n* import cadd from '@stdlib/math-base-ops-cadd' ;\n* import naryFunction from '@stdlib/utils-nary-function' ;\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'getter': getter\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.getter;\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Function} x.getter - callback for accessing input array data elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'getter': getter\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.getter;\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","getter","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;qoBA0FA,SAASA,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,GAAKK,EAAeR,GACnB,OCGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,OAGRZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAtH1B,SAuHTR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,EDlDCkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OE1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,OAGRf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,EFyBCqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,QAASP"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 4831851..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 382ab7b91780571140a012df60bc4f3c26125d00 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Jul 2022 11:57:18 +0000 Subject: [PATCH 07/91] 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 | 63 +- benchmark/benchmark.array.js | 98 - benchmark/benchmark.ndarray.js | 109 - branches.md | 53 - docs/repl.txt | 65 - docs/types/test.ts | 184 -- examples/index.js | 52 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/array.js | 83 - lib/index.js | 65 - lib/main.js | 110 - lib/ndarray.js | 155 -- package.json | 76 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 637 ----- 40 files changed, 2725 insertions(+), 4570 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.array.js delete mode 100644 benchmark/benchmark.ndarray.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/array.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/ndarray.js create mode 100644 stats.html delete mode 100644 test/test.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 498915b..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-07-01T01:40:33.855Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3b4c7b4..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/utils/map-reduce-right) 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 bbe0806..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/utils/map-reduce-right) 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 + + ```
@@ -260,7 +253,7 @@ console.log( 'sum: %d', out ); ## 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]. @@ -320,11 +313,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/utils-map-reduce-right/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/stdlib +[@stdlib/array/complex64]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/array/complex128]: https://github.com/stdlib-js/stdlib +[@stdlib/array/complex128]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.array.js b/benchmark/benchmark.array.js deleted file mode 100644 index e87feb5..0000000 --- a/benchmark/benchmark.array.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = filled( -3.0, len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::array:len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.ndarray.js b/benchmark/benchmark.ndarray.js deleted file mode 100644 index e3bfba2..0000000 --- a/benchmark/benchmark.ndarray.js +++ /dev/null @@ -1,109 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var xbuf; - var opts; - var x; - - xbuf = filled( -3.0, len ); - - opts = { - 'dtype': 'generic' - }; - x = array( xbuf, opts ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::ndarray:len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 651bb38..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/utils/map-reduce-right" -click B href "https://github.com/stdlib-js/utils-map-reduce-right/tree/main" -click C href "https://github.com/stdlib-js/utils-map-reduce-right/tree/production" -click D href "https://github.com/stdlib-js/utils-map-reduce-right/tree/esm" -click E href "https://github.com/stdlib-js/utils-map-reduce-right/tree/deno" -click F href "https://github.com/stdlib-js/utils-map-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/map-reduce-right -[production-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b580e87..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, initial, mapper, reducer[, thisArg] ) - Performs a map-reduce operation for each element in an array while iterating - from right to left and returns the accumulated result. - - When invoked, the mapping function is provided three arguments: - - - value: array element. - - index: element index. - - arr: input array. - - When invoked, the reducing function is provided four arguments: - - - accumulator: accumulated value. - - value: result after applying the mapping function to the current array - element. - - index: element index. - - arr: input array. - - If provided an empty array, the function returns the initial value. - - When provided an ndarray, the function performs a single-pass map-reduce - operation over the entire input ndarray (i.e., higher-order ndarray - dimensions are flattened to a single-dimension). - - Parameters - ---------- - arr: ArrayLikeObject|ndarray - Input array. - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - mapper: Function - Mapping function. - - reducer: Function - Reducing function. - - thisArg: any (optional) - Execution context for the reducing function. - - Returns - ------- - out: any - Accumulated result. - - Examples - -------- - // array-like object: - > var f1 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/special/abs}}, 1 ); - > var f2 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/ops/add}}, 2 ); - > var arr = [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0 ]; - > var out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - // ndarray: - > arr = {{alias:@stdlib/ndarray/array}}( arr, { 'shape': [ 2, 3 ] } ); - > out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 76168a1..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,184 +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. -*/ - -import array = require( '@stdlib/ndarray-array' ); -import mapReduceRight = require( './index' ); - -/** -* Mapping function. -* -* @param value - array element -* @returns result -*/ -function mapper( value: number ): number { - return value; -} - -/** -* Reducing function. -* -* @param acc - accumulated value -* @param v - array element -* @returns result -*/ -function reducer( acc: number, value: number ): number { - return acc + value; -} - - -// TESTS // - -// The function returns the accumulated value when provided a collection... -{ - mapReduceRight( [ 0, 1, 1, NaN, 2 ], 0, mapper, reducer ); // $ExpectType any - mapReduceRight( [ -1, 1, 2 ], 100, mapper, reducer ); // $ExpectType any - mapReduceRight( [ -1, 1, 2 ], 0, mapper, reducer, {} ); // $ExpectType any -} - -// The function returns the accumulated value when provided an ndarray... -{ - const arr = array( [ 1, 2, 3, 4, 5, 6 ] ); - - mapReduceRight( arr, 0, mapper, reducer ); // $ExpectType any - mapReduceRight( arr, 100, mapper, reducer ); // $ExpectType any - mapReduceRight( arr, 0, mapper, reducer, {} ); // $ExpectType any -} - -// The compiler throws an error if the function is provided a first argument which is not a collection or ndarray... -{ - mapReduceRight( 2, 0, mapper, reducer ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer ); // $ExpectError - - mapReduceRight( 2, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr1, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr2, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const arr1 = [ 1, 2, 3 ]; - - mapReduceRight(); // $ExpectError - mapReduceRight( arr1 ); // $ExpectError - mapReduceRight( arr1, 0 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ); // $ExpectError - mapReduceRight( arr1, 0, mapper, reducer, {}, 3 ); // $ExpectError - - const arr2 = array( [ 1, 2, 3 ] ); - - mapReduceRight(); // $ExpectError - mapReduceRight( arr2 ); // $ExpectError - mapReduceRight( arr2, 0 ); // $ExpectError - mapReduceRight( arr2, 0, mapper ); // $ExpectError - mapReduceRight( arr2, 0, mapper, reducer, {}, 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 7474059..0000000 --- a/examples/index.js +++ /dev/null @@ -1,52 +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. -*/ - -'use strict'; - -var filledarrayBy = require( '@stdlib/array-filled-by' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ).factory; -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var mapReduceRight = require( './../lib' ); - -function fill( i ) { - var rand = discreteUniform( -10*(i+1), 10*(i+1) ); - return filledarrayBy( 10, 'generic', rand ); -} - -// Create a two-dimensional ndarray (i.e., a matrix): -var x = array( filledarrayBy( 10, 'generic', fill ), { - 'dtype': 'generic', - 'flatten': true -}); - -// Create an explicit unary function: -var f1 = naryFunction( abs, 1 ); - -// Create an explicit binary function: -var f2 = naryFunction( add, 2 ); - -// Compute the sum of absolute values: -var out = mapReduceRight( x, 0, f1, f2 ); - -console.log( 'x:' ); -console.log( x.data ); - -console.log( 'sum: %d', out ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index a2eace0..41d747e 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Collection } from '@stdlib/types/object'; import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..6dac8d7 --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@esm/index.mjs";function o(o,a,m,l,j){if(!e(m))throw new TypeError(n("0kW3Z",m));if(!e(l))throw new TypeError(n("0kW3E",l));if(t(o))return function(r,t,e,s,i){var n,o,a,m,l,j,f,h,p,c,b;if(m=r.length,f=r.shape,n=r.data,h=r.strides,p=r.offset,o=r.order,l=r.getter,j=r.ref,0===f.length)return s.call(i,t,e(l(n,p),0,j),0,j);for(a=t,b=m-1;b>=0;b--)c=d(f,h,p,o,b,"throw"),a=s.call(i,a,e(l(n,c),b,j),b,j);return a}(s(o),a,m,l,j);if(r(o))return function(r,t,e,s,i){var n,d,o,a;for(n=r.data,d=r.getter,o=t,a=n.length-1;a>=0;a--)o=s.call(i,o,e(d(n,a),a,n),a,n);return o}(i(o),a,m,l,j);throw new TypeError(n("0kWC4",o))}export{o as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..703007b --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js","../lib/ndarray.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object' ;\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object' ;\nimport arraylike2object from '@stdlib/array-base-arraylike2object' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport ndarrayFcn from './ndarray.js' ;\nimport arrayFcn from './array.js' ;\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function' ;\n* import add from '@stdlib/math-base-ops-add' ;\n* import abs from '@stdlib/math-base-special-abs' ;\n* import array from '@stdlib/ndarray-array' ;\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '0kW3Z', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '0kW3E', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '0kWC4', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind' ;\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Function} x.getter - callback for accessing `x` data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64' ;\n* import Complex64 from '@stdlib/complex-float32' ;\n* import realf from '@stdlib/complex-realf' ;\n* import imagf from '@stdlib/complex-imagf' ;\n* import cceil from '@stdlib/math-base-special-cceil' ;\n* import cadd from '@stdlib/math-base-ops-cadd' ;\n* import naryFunction from '@stdlib/utils-nary-function' ;\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'getter': getter\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.getter;\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Function} x.getter - callback for accessing input array data elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'getter': getter\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.getter;\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","getter","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;qoBA0FA,SAASA,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,GAAKK,EAAeR,GACnB,OCGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,OAGRZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAtH1B,SAuHTR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,EDlDCkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OE1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,OAGRf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,EFyBCqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,QAASP"} \ No newline at end of file diff --git a/lib/array.js b/lib/array.js deleted file mode 100644 index 9f87c1f..0000000 --- a/lib/array.js +++ /dev/null @@ -1,83 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input array data -* @param {ArrayLikeObject} x.data - input array data -* @param {Function} x.getter - callback for accessing input array data elements -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf[ idx ]; -* } -* -* // Create the input array object: -* var x = { -* 'data': [ 1, 2, 3, 4 ], -* 'getter': getter -* }; -* -* // Compute the sum of squared values: -* var out = mapReduceRight( x, 0, square, sum ); -* // returns 30 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var get; - var acc; - var i; - - // Cache reference to the input data: - xbuf = x.data; - - // Cache the element accessor: - get = x.getter; - - // Iterate over each element... - acc = initial; - for ( i = xbuf.length-1; i >= 0; i-- ) { - acc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 522693e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +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. -*/ - -'use strict'; - -/** -* Perform a map-reduce operation against each element in an array while iterating from right to left and return the accumulated result. -* -* @module @stdlib/utils-map-reduce-right -* -* @example -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ - -// 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 c890358..0000000 --- a/lib/main.js +++ /dev/null @@ -1,110 +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. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ndarrayFcn = require( './ndarray.js' ); -var arrayFcn = require( './array.js' ); - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided the following arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided the following arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result of applying the mapping function against the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* @param {(ArrayLikeObject|ndarray)} arr - input array -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} [thisArg] - reduction function execution context -* @throws {TypeError} first argument must be an array-like object or an ndarray -* @throws {TypeError} third argument must be a function -* @throws {TypeError} fourth argument must be a function -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { - if ( !isFunction( mapper ) ) { - throw new TypeError( format( '0kW3Z', mapper ) ); - } - if ( !isFunction( reducer ) ) { - throw new TypeError( format( '0kW3E', reducer ) ); - } - if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like - return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - if ( isArrayLikeObject( arr ) ) { - return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - throw new TypeError( format( '0kWC4', arr ) ); -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/ndarray.js b/lib/ndarray.js deleted file mode 100644 index 8b2442d..0000000 --- a/lib/ndarray.js +++ /dev/null @@ -1,155 +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. -*/ - -'use strict'; - -// MODULES // - -var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); - - -// VARIABLES // - -var MODE = 'throw'; - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input ndarray meta data -* @param {string} x.ref - reference to original input ndarray-like object -* @param {string} x.dtype - data type -* @param {Collection} x.data - data buffer -* @param {NonNegativeInteger} x.length - number of elements -* @param {NonNegativeIntegerArray} x.shape - dimensions -* @param {IntegerArray} x.strides - stride lengths -* @param {NonNegativeInteger} x.offset - index offset -* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) -* @param {Function} x.getter - callback for accessing `x` data buffer elements -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var Complex64 = require( '@stdlib/complex-float32' ); -* var realf = require( '@stdlib/complex-realf' ); -* var imagf = require( '@stdlib/complex-imagf' ); -* var cceil = require( '@stdlib/math-base-special-cceil' ); -* var cadd = require( '@stdlib/math-base-ops-cadd' ); -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* -* // Create a data buffer: -* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] ); -* -* // Define the shape of the input array: -* var shape = [ 2, 2 ]; -* -* // Define the array strides: -* var sx = [ 2, 1 ]; -* -* // Define the index offset: -* var ox = 0; -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf.get( idx ); -* } -* -* // Create the input ndarray-like object: -* var x = { -* 'ref': null, -* 'dtype': 'complex64', -* 'data': xbuf, -* 'length': 4, -* 'shape': shape, -* 'strides': sx, -* 'offset': ox, -* 'order': 'row-major', -* 'getter': getter -* }; -* x.ref = x; -* -* // Compute the sum: -* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) ); -* -* var re = realf( v ); -* // returns 20.0 -* -* var im = imagf( v ); -* // returns 24.0 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var ordx; - var acc; - var len; - var get; - var ref; - var shx; - var sx; - var ox; - var ix; - var i; - - // Cache the total number of elements over which to iterate: - len = x.length; - - // Cache the input array shape: - shx = x.shape; - - // Cache reference to the input ndarray data buffer: - xbuf = x.data; - - // Cache reference to the stride array: - sx = x.strides; - - // Cache the index of the first indexed element: - ox = x.offset; - - // Cache the array order: - ordx = x.order; - - // Cache the element accessor: - get = x.getter; - - // Cache the reference to the original input array: - ref = x.ref; - - // Check for a zero-dimensional array... - if ( shx.length === 0 ) { - return reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len - } - // Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)... - acc = initial; - for ( i = len-1; i >= 0; i-- ) { - ix = vind2bind( shx, sx, ox, ordx, i, MODE ); - acc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/package.json b/package.json index 35888db..58c2ca2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.1", "description": "Perform a single-pass map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.", "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/array-base-arraylike2object": "^0.0.x", - "@stdlib/assert-is-array-like-object": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-ndarray-like": "^0.0.x", - "@stdlib/ndarray-base-ndarraylike2object": "^0.0.x", - "@stdlib/ndarray-base-vind2bind": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-base-filled": "^0.0.x", - "@stdlib/array-complex64": "^0.0.x", - "@stdlib/array-filled-by": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/complex-float32": "^0.0.x", - "@stdlib/complex-imagf": "^0.0.x", - "@stdlib/complex-realf": "^0.0.x", - "@stdlib/math-base-assert-is-nan": "^0.0.x", - "@stdlib/math-base-ops-add": "^0.0.x", - "@stdlib/math-base-ops-cadd": "^0.0.x", - "@stdlib/math-base-special-abs": "^0.0.x", - "@stdlib/math-base-special-cceil": "^0.0.x", - "@stdlib/math-base-special-pow": "^0.0.x", - "@stdlib/ndarray-array": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/random-base-discrete-uniform": "^0.0.x", - "@stdlib/utils-nary-function": "^0.0.x", - "@stdlib/utils-noop": "^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", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..1f6eab7 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2c78efa..0000000 --- a/test/test.js +++ /dev/null @@ -1,637 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var cadd = require( '@stdlib/math-base-ops-cadd' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var cceil = require( '@stdlib/math-base-special-cceil' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var mapReduceRight = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapReduceRight, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a first argument which is either an array-like object or an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( value, 0, noop, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value, {} ); - }; - } -}); - -tape( 'the function performs a map-reduce operation for each element in an array (array-like object)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = [ -1, -2, -3 ]; - expected = 7; - actual = mapReduceRight( arr, 1, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (typed array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - expected = 7.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (complex number array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( cceil, 1 ); - f2 = naryFunction( cadd, 2 ); - - arr = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5 ] ); - expected = new Complex64( 12.0, 15.0 ); - actual = mapReduceRight( arr, new Complex64( 0.0, 0.0 ), f1, f2 ); - - t.strictEqual( realf( actual ), realf( expected ), 'returns expected value' ); - t.strictEqual( imagf( actual ), imagf( expected ), 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = array( [ -1.0, -2.0, -3.0, -4.0 ], { - 'dtype': 'generic' - }); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray; 0-dimensional)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = ndarray( 'generic', [ -10.0 ], [], [ 0 ], 0, 'row-major' ); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (array-like object)', function test( t ) { - var out = mapReduceRight( [], 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (ndarray)', function test( t ) { - var arr; - var out; - - arr = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 0, 2 ], [ 0, 2, 1 ], 0, 'row-major' ); - out = mapReduceRight( arr, 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function supports providing a `this` context (array-like object)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = [ -1.0, -2.0, -3.0 ]; - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function supports providing a `this` context (ndarray)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = array( [ -1.0, -2.0, -3.0 ], { - 'dtype': 'generic' - }); - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = array( [ 1, , , 4 ], { // eslint-disable-line no-sparse-arrays - 'dtype': 'generic' - }); - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); From cacda2e06dda95924411e57cf11f9e4aa713babf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 5 Jul 2022 12:47:15 +0000 Subject: [PATCH 08/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index d95cde3..c890358 100644 --- a/lib/main.js +++ b/lib/main.js @@ -25,7 +25,7 @@ var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); var isFunction = require( '@stdlib/assert-is-function' ); var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ndarrayFcn = require( './ndarray.js' ); var arrayFcn = require( './array.js' ); @@ -90,10 +90,10 @@ var arrayFcn = require( './array.js' ); */ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( !isFunction( mapper ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) ); + throw new TypeError( format( '0kW3Z', mapper ) ); } if ( !isFunction( reducer ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) ); + throw new TypeError( format( '0kW3E', reducer ) ); } if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len @@ -101,7 +101,7 @@ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( isArrayLikeObject( arr ) ) { return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len } - throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) ); + throw new TypeError( format( '0kWC4', arr ) ); } diff --git a/package.json b/package.json index a522b3d..35888db 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-ndarray-like": "^0.0.x", "@stdlib/ndarray-base-ndarraylike2object": "^0.0.x", "@stdlib/ndarray-base-vind2bind": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From 64f7b7207dbd8952913d81ac73710fd11e502fa3 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 5 Jul 2022 13:11:15 +0000 Subject: [PATCH 09/91] Remove files --- index.d.ts | 257 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2951 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 41d747e..0000000 --- a/index.d.ts +++ /dev/null @@ -1,257 +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. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Collection } from '@stdlib/types/object'; -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* Callback invoked for each array element. -* -* @returns result -*/ -type Nullary = () => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @returns result -*/ -type Unary = ( value: any ) => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @returns result -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Ternary = ( value: any, index: number, arr: ndarray ) => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayTernary = ( value: any, index: number, arr: Collection ) => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Mapper = Nullary | Unary | Binary | Ternary; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayMapper = Nullary | Unary | Binary | ArrayTernary; - -/** -* Function applied against an accumulator. -* -* @returns accumulator value -*/ -type NullaryReducer = () => void; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @returns accumulator value -*/ -type UnaryReducer = ( accumulator: any ) => any; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @returns accumulator value -*/ -type BinaryReducer = ( accumulator: any, value: any ) => any; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @returns accumulator value -*/ -type TernaryReducer = ( accumulator: any, value: any, index: number ) => any; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type QuaternaryReducer = ( accumulator: any, value: any, index: number, arr: ndarray ) => any; // tslint:disable-line:max-line-length - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayQuaternaryReducer = ( accumulator: any, value: any, index: number, arr: Collection ) => any; // tslint:disable-line:max-line-length - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type Reducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | QuaternaryReducer; // tslint:disable-line:max-line-length - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayReducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | ArrayQuaternaryReducer; // tslint:disable-line:max-line-length - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* var naryFunction = require( `@stdlib/utils/nary-function` ); -* var abs = require( `@stdlib/math/base/special/abs` ); -* var add = require( `@stdlib/math/base/ops/add` ); -* var array = require( `@stdlib/ndarray/array` ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 2 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -declare function mapReduceRight( arr: ndarray, initial: any, mapper: Mapper, reducer: Reducer, thisArg?: any ): any; // tslint:disable-line:max-line-length - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -*/ -declare function mapReduceRight( arr: Collection, initial: any, mapper: ArrayMapper, reducer: ArrayReducer, thisArg?: any ): any; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = mapReduceRight; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 6dac8d7..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@esm/index.mjs";function o(o,a,m,l,j){if(!e(m))throw new TypeError(n("0kW3Z",m));if(!e(l))throw new TypeError(n("0kW3E",l));if(t(o))return function(r,t,e,s,i){var n,o,a,m,l,j,f,h,p,c,b;if(m=r.length,f=r.shape,n=r.data,h=r.strides,p=r.offset,o=r.order,l=r.getter,j=r.ref,0===f.length)return s.call(i,t,e(l(n,p),0,j),0,j);for(a=t,b=m-1;b>=0;b--)c=d(f,h,p,o,b,"throw"),a=s.call(i,a,e(l(n,c),b,j),b,j);return a}(s(o),a,m,l,j);if(r(o))return function(r,t,e,s,i){var n,d,o,a;for(n=r.data,d=r.getter,o=t,a=n.length-1;a>=0;a--)o=s.call(i,o,e(d(n,a),a,n),a,n);return o}(i(o),a,m,l,j);throw new TypeError(n("0kWC4",o))}export{o as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 703007b..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js","../lib/ndarray.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object' ;\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object' ;\nimport arraylike2object from '@stdlib/array-base-arraylike2object' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport ndarrayFcn from './ndarray.js' ;\nimport arrayFcn from './array.js' ;\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function' ;\n* import add from '@stdlib/math-base-ops-add' ;\n* import abs from '@stdlib/math-base-special-abs' ;\n* import array from '@stdlib/ndarray-array' ;\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '0kW3Z', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '0kW3E', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '0kWC4', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind' ;\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Function} x.getter - callback for accessing `x` data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64' ;\n* import Complex64 from '@stdlib/complex-float32' ;\n* import realf from '@stdlib/complex-realf' ;\n* import imagf from '@stdlib/complex-imagf' ;\n* import cceil from '@stdlib/math-base-special-cceil' ;\n* import cadd from '@stdlib/math-base-ops-cadd' ;\n* import naryFunction from '@stdlib/utils-nary-function' ;\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'getter': getter\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.getter;\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Function} x.getter - callback for accessing input array data elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'getter': getter\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.getter;\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","getter","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;qoBA0FA,SAASA,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,GAAKK,EAAeR,GACnB,OCGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,OAGRZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAtH1B,SAuHTR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,EDlDCkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OE1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,OAGRf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,EFyBCqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,QAASP"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 1f6eab7..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 499089683b16dd0ce1a149407300d8ea9b9d8130 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 5 Jul 2022 13:12:06 +0000 Subject: [PATCH 10/91] 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 | 63 +- benchmark/benchmark.array.js | 98 - benchmark/benchmark.ndarray.js | 109 - branches.md | 53 - docs/repl.txt | 65 - docs/types/test.ts | 184 -- examples/index.js | 52 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/array.js | 83 - lib/index.js | 65 - lib/main.js | 110 - lib/ndarray.js | 155 -- package.json | 76 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 637 ----- 39 files changed, 2725 insertions(+), 4535 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.array.js delete mode 100644 benchmark/benchmark.ndarray.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/array.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/ndarray.js create mode 100644 stats.html delete mode 100644 test/test.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 3b4c7b4..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/utils/map-reduce-right) 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 bbe0806..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/utils/map-reduce-right) 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 + + ```
@@ -260,7 +253,7 @@ console.log( 'sum: %d', out ); ## 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]. @@ -320,11 +313,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/utils-map-reduce-right/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/stdlib +[@stdlib/array/complex64]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/array/complex128]: https://github.com/stdlib-js/stdlib +[@stdlib/array/complex128]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.array.js b/benchmark/benchmark.array.js deleted file mode 100644 index e87feb5..0000000 --- a/benchmark/benchmark.array.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = filled( -3.0, len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::array:len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.ndarray.js b/benchmark/benchmark.ndarray.js deleted file mode 100644 index e3bfba2..0000000 --- a/benchmark/benchmark.ndarray.js +++ /dev/null @@ -1,109 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var xbuf; - var opts; - var x; - - xbuf = filled( -3.0, len ); - - opts = { - 'dtype': 'generic' - }; - x = array( xbuf, opts ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::ndarray:len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 651bb38..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/utils/map-reduce-right" -click B href "https://github.com/stdlib-js/utils-map-reduce-right/tree/main" -click C href "https://github.com/stdlib-js/utils-map-reduce-right/tree/production" -click D href "https://github.com/stdlib-js/utils-map-reduce-right/tree/esm" -click E href "https://github.com/stdlib-js/utils-map-reduce-right/tree/deno" -click F href "https://github.com/stdlib-js/utils-map-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/map-reduce-right -[production-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b580e87..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, initial, mapper, reducer[, thisArg] ) - Performs a map-reduce operation for each element in an array while iterating - from right to left and returns the accumulated result. - - When invoked, the mapping function is provided three arguments: - - - value: array element. - - index: element index. - - arr: input array. - - When invoked, the reducing function is provided four arguments: - - - accumulator: accumulated value. - - value: result after applying the mapping function to the current array - element. - - index: element index. - - arr: input array. - - If provided an empty array, the function returns the initial value. - - When provided an ndarray, the function performs a single-pass map-reduce - operation over the entire input ndarray (i.e., higher-order ndarray - dimensions are flattened to a single-dimension). - - Parameters - ---------- - arr: ArrayLikeObject|ndarray - Input array. - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - mapper: Function - Mapping function. - - reducer: Function - Reducing function. - - thisArg: any (optional) - Execution context for the reducing function. - - Returns - ------- - out: any - Accumulated result. - - Examples - -------- - // array-like object: - > var f1 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/special/abs}}, 1 ); - > var f2 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/ops/add}}, 2 ); - > var arr = [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0 ]; - > var out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - // ndarray: - > arr = {{alias:@stdlib/ndarray/array}}( arr, { 'shape': [ 2, 3 ] } ); - > out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 76168a1..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,184 +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. -*/ - -import array = require( '@stdlib/ndarray-array' ); -import mapReduceRight = require( './index' ); - -/** -* Mapping function. -* -* @param value - array element -* @returns result -*/ -function mapper( value: number ): number { - return value; -} - -/** -* Reducing function. -* -* @param acc - accumulated value -* @param v - array element -* @returns result -*/ -function reducer( acc: number, value: number ): number { - return acc + value; -} - - -// TESTS // - -// The function returns the accumulated value when provided a collection... -{ - mapReduceRight( [ 0, 1, 1, NaN, 2 ], 0, mapper, reducer ); // $ExpectType any - mapReduceRight( [ -1, 1, 2 ], 100, mapper, reducer ); // $ExpectType any - mapReduceRight( [ -1, 1, 2 ], 0, mapper, reducer, {} ); // $ExpectType any -} - -// The function returns the accumulated value when provided an ndarray... -{ - const arr = array( [ 1, 2, 3, 4, 5, 6 ] ); - - mapReduceRight( arr, 0, mapper, reducer ); // $ExpectType any - mapReduceRight( arr, 100, mapper, reducer ); // $ExpectType any - mapReduceRight( arr, 0, mapper, reducer, {} ); // $ExpectType any -} - -// The compiler throws an error if the function is provided a first argument which is not a collection or ndarray... -{ - mapReduceRight( 2, 0, mapper, reducer ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer ); // $ExpectError - - mapReduceRight( 2, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr1, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr2, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const arr1 = [ 1, 2, 3 ]; - - mapReduceRight(); // $ExpectError - mapReduceRight( arr1 ); // $ExpectError - mapReduceRight( arr1, 0 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ); // $ExpectError - mapReduceRight( arr1, 0, mapper, reducer, {}, 3 ); // $ExpectError - - const arr2 = array( [ 1, 2, 3 ] ); - - mapReduceRight(); // $ExpectError - mapReduceRight( arr2 ); // $ExpectError - mapReduceRight( arr2, 0 ); // $ExpectError - mapReduceRight( arr2, 0, mapper ); // $ExpectError - mapReduceRight( arr2, 0, mapper, reducer, {}, 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 7474059..0000000 --- a/examples/index.js +++ /dev/null @@ -1,52 +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. -*/ - -'use strict'; - -var filledarrayBy = require( '@stdlib/array-filled-by' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ).factory; -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var mapReduceRight = require( './../lib' ); - -function fill( i ) { - var rand = discreteUniform( -10*(i+1), 10*(i+1) ); - return filledarrayBy( 10, 'generic', rand ); -} - -// Create a two-dimensional ndarray (i.e., a matrix): -var x = array( filledarrayBy( 10, 'generic', fill ), { - 'dtype': 'generic', - 'flatten': true -}); - -// Create an explicit unary function: -var f1 = naryFunction( abs, 1 ); - -// Create an explicit binary function: -var f2 = naryFunction( add, 2 ); - -// Compute the sum of absolute values: -var out = mapReduceRight( x, 0, f1, f2 ); - -console.log( 'x:' ); -console.log( x.data ); - -console.log( 'sum: %d', out ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index a2eace0..41d747e 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Collection } from '@stdlib/types/object'; import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..6dac8d7 --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@esm/index.mjs";function o(o,a,m,l,j){if(!e(m))throw new TypeError(n("0kW3Z",m));if(!e(l))throw new TypeError(n("0kW3E",l));if(t(o))return function(r,t,e,s,i){var n,o,a,m,l,j,f,h,p,c,b;if(m=r.length,f=r.shape,n=r.data,h=r.strides,p=r.offset,o=r.order,l=r.getter,j=r.ref,0===f.length)return s.call(i,t,e(l(n,p),0,j),0,j);for(a=t,b=m-1;b>=0;b--)c=d(f,h,p,o,b,"throw"),a=s.call(i,a,e(l(n,c),b,j),b,j);return a}(s(o),a,m,l,j);if(r(o))return function(r,t,e,s,i){var n,d,o,a;for(n=r.data,d=r.getter,o=t,a=n.length-1;a>=0;a--)o=s.call(i,o,e(d(n,a),a,n),a,n);return o}(i(o),a,m,l,j);throw new TypeError(n("0kWC4",o))}export{o as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..703007b --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js","../lib/ndarray.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object' ;\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object' ;\nimport arraylike2object from '@stdlib/array-base-arraylike2object' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport ndarrayFcn from './ndarray.js' ;\nimport arrayFcn from './array.js' ;\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function' ;\n* import add from '@stdlib/math-base-ops-add' ;\n* import abs from '@stdlib/math-base-special-abs' ;\n* import array from '@stdlib/ndarray-array' ;\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '0kW3Z', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '0kW3E', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '0kWC4', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind' ;\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Function} x.getter - callback for accessing `x` data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64' ;\n* import Complex64 from '@stdlib/complex-float32' ;\n* import realf from '@stdlib/complex-realf' ;\n* import imagf from '@stdlib/complex-imagf' ;\n* import cceil from '@stdlib/math-base-special-cceil' ;\n* import cadd from '@stdlib/math-base-ops-cadd' ;\n* import naryFunction from '@stdlib/utils-nary-function' ;\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'getter': getter\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.getter;\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Function} x.getter - callback for accessing input array data elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'getter': getter\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.getter;\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","getter","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;qoBA0FA,SAASA,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,GAAKK,EAAeR,GACnB,OCGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,OAGRZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAtH1B,SAuHTR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,EDlDCkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OE1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,OAGRf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,EFyBCqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,QAASP"} \ No newline at end of file diff --git a/lib/array.js b/lib/array.js deleted file mode 100644 index 9f87c1f..0000000 --- a/lib/array.js +++ /dev/null @@ -1,83 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input array data -* @param {ArrayLikeObject} x.data - input array data -* @param {Function} x.getter - callback for accessing input array data elements -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf[ idx ]; -* } -* -* // Create the input array object: -* var x = { -* 'data': [ 1, 2, 3, 4 ], -* 'getter': getter -* }; -* -* // Compute the sum of squared values: -* var out = mapReduceRight( x, 0, square, sum ); -* // returns 30 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var get; - var acc; - var i; - - // Cache reference to the input data: - xbuf = x.data; - - // Cache the element accessor: - get = x.getter; - - // Iterate over each element... - acc = initial; - for ( i = xbuf.length-1; i >= 0; i-- ) { - acc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 522693e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +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. -*/ - -'use strict'; - -/** -* Perform a map-reduce operation against each element in an array while iterating from right to left and return the accumulated result. -* -* @module @stdlib/utils-map-reduce-right -* -* @example -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ - -// 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 c890358..0000000 --- a/lib/main.js +++ /dev/null @@ -1,110 +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. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ndarrayFcn = require( './ndarray.js' ); -var arrayFcn = require( './array.js' ); - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided the following arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided the following arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result of applying the mapping function against the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* @param {(ArrayLikeObject|ndarray)} arr - input array -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} [thisArg] - reduction function execution context -* @throws {TypeError} first argument must be an array-like object or an ndarray -* @throws {TypeError} third argument must be a function -* @throws {TypeError} fourth argument must be a function -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { - if ( !isFunction( mapper ) ) { - throw new TypeError( format( '0kW3Z', mapper ) ); - } - if ( !isFunction( reducer ) ) { - throw new TypeError( format( '0kW3E', reducer ) ); - } - if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like - return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - if ( isArrayLikeObject( arr ) ) { - return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - throw new TypeError( format( '0kWC4', arr ) ); -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/ndarray.js b/lib/ndarray.js deleted file mode 100644 index 8b2442d..0000000 --- a/lib/ndarray.js +++ /dev/null @@ -1,155 +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. -*/ - -'use strict'; - -// MODULES // - -var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); - - -// VARIABLES // - -var MODE = 'throw'; - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input ndarray meta data -* @param {string} x.ref - reference to original input ndarray-like object -* @param {string} x.dtype - data type -* @param {Collection} x.data - data buffer -* @param {NonNegativeInteger} x.length - number of elements -* @param {NonNegativeIntegerArray} x.shape - dimensions -* @param {IntegerArray} x.strides - stride lengths -* @param {NonNegativeInteger} x.offset - index offset -* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) -* @param {Function} x.getter - callback for accessing `x` data buffer elements -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var Complex64 = require( '@stdlib/complex-float32' ); -* var realf = require( '@stdlib/complex-realf' ); -* var imagf = require( '@stdlib/complex-imagf' ); -* var cceil = require( '@stdlib/math-base-special-cceil' ); -* var cadd = require( '@stdlib/math-base-ops-cadd' ); -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* -* // Create a data buffer: -* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] ); -* -* // Define the shape of the input array: -* var shape = [ 2, 2 ]; -* -* // Define the array strides: -* var sx = [ 2, 1 ]; -* -* // Define the index offset: -* var ox = 0; -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf.get( idx ); -* } -* -* // Create the input ndarray-like object: -* var x = { -* 'ref': null, -* 'dtype': 'complex64', -* 'data': xbuf, -* 'length': 4, -* 'shape': shape, -* 'strides': sx, -* 'offset': ox, -* 'order': 'row-major', -* 'getter': getter -* }; -* x.ref = x; -* -* // Compute the sum: -* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) ); -* -* var re = realf( v ); -* // returns 20.0 -* -* var im = imagf( v ); -* // returns 24.0 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var ordx; - var acc; - var len; - var get; - var ref; - var shx; - var sx; - var ox; - var ix; - var i; - - // Cache the total number of elements over which to iterate: - len = x.length; - - // Cache the input array shape: - shx = x.shape; - - // Cache reference to the input ndarray data buffer: - xbuf = x.data; - - // Cache reference to the stride array: - sx = x.strides; - - // Cache the index of the first indexed element: - ox = x.offset; - - // Cache the array order: - ordx = x.order; - - // Cache the element accessor: - get = x.getter; - - // Cache the reference to the original input array: - ref = x.ref; - - // Check for a zero-dimensional array... - if ( shx.length === 0 ) { - return reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len - } - // Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)... - acc = initial; - for ( i = len-1; i >= 0; i-- ) { - ix = vind2bind( shx, sx, ox, ordx, i, MODE ); - acc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/package.json b/package.json index 35888db..58c2ca2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.1", "description": "Perform a single-pass map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.", "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/array-base-arraylike2object": "^0.0.x", - "@stdlib/assert-is-array-like-object": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-ndarray-like": "^0.0.x", - "@stdlib/ndarray-base-ndarraylike2object": "^0.0.x", - "@stdlib/ndarray-base-vind2bind": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-base-filled": "^0.0.x", - "@stdlib/array-complex64": "^0.0.x", - "@stdlib/array-filled-by": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/complex-float32": "^0.0.x", - "@stdlib/complex-imagf": "^0.0.x", - "@stdlib/complex-realf": "^0.0.x", - "@stdlib/math-base-assert-is-nan": "^0.0.x", - "@stdlib/math-base-ops-add": "^0.0.x", - "@stdlib/math-base-ops-cadd": "^0.0.x", - "@stdlib/math-base-special-abs": "^0.0.x", - "@stdlib/math-base-special-cceil": "^0.0.x", - "@stdlib/math-base-special-pow": "^0.0.x", - "@stdlib/ndarray-array": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/random-base-discrete-uniform": "^0.0.x", - "@stdlib/utils-nary-function": "^0.0.x", - "@stdlib/utils-noop": "^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", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..34d45ea --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2c78efa..0000000 --- a/test/test.js +++ /dev/null @@ -1,637 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var cadd = require( '@stdlib/math-base-ops-cadd' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var cceil = require( '@stdlib/math-base-special-cceil' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var mapReduceRight = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapReduceRight, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a first argument which is either an array-like object or an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( value, 0, noop, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value, {} ); - }; - } -}); - -tape( 'the function performs a map-reduce operation for each element in an array (array-like object)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = [ -1, -2, -3 ]; - expected = 7; - actual = mapReduceRight( arr, 1, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (typed array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - expected = 7.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (complex number array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( cceil, 1 ); - f2 = naryFunction( cadd, 2 ); - - arr = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5 ] ); - expected = new Complex64( 12.0, 15.0 ); - actual = mapReduceRight( arr, new Complex64( 0.0, 0.0 ), f1, f2 ); - - t.strictEqual( realf( actual ), realf( expected ), 'returns expected value' ); - t.strictEqual( imagf( actual ), imagf( expected ), 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = array( [ -1.0, -2.0, -3.0, -4.0 ], { - 'dtype': 'generic' - }); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray; 0-dimensional)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = ndarray( 'generic', [ -10.0 ], [], [ 0 ], 0, 'row-major' ); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (array-like object)', function test( t ) { - var out = mapReduceRight( [], 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (ndarray)', function test( t ) { - var arr; - var out; - - arr = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 0, 2 ], [ 0, 2, 1 ], 0, 'row-major' ); - out = mapReduceRight( arr, 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function supports providing a `this` context (array-like object)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = [ -1.0, -2.0, -3.0 ]; - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function supports providing a `this` context (ndarray)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = array( [ -1.0, -2.0, -3.0 ], { - 'dtype': 'generic' - }); - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = array( [ 1, , , 4 ], { // eslint-disable-line no-sparse-arrays - 'dtype': 'generic' - }); - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); From c1b65d64a8ee36e065ebca7b58e1c05dcc6afdfc Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 03:56:49 +0000 Subject: [PATCH 11/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index d95cde3..c890358 100644 --- a/lib/main.js +++ b/lib/main.js @@ -25,7 +25,7 @@ var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); var isFunction = require( '@stdlib/assert-is-function' ); var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ndarrayFcn = require( './ndarray.js' ); var arrayFcn = require( './array.js' ); @@ -90,10 +90,10 @@ var arrayFcn = require( './array.js' ); */ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( !isFunction( mapper ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) ); + throw new TypeError( format( '0kW3Z', mapper ) ); } if ( !isFunction( reducer ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) ); + throw new TypeError( format( '0kW3E', reducer ) ); } if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len @@ -101,7 +101,7 @@ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( isArrayLikeObject( arr ) ) { return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len } - throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) ); + throw new TypeError( format( '0kWC4', arr ) ); } diff --git a/package.json b/package.json index a522b3d..35888db 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-ndarray-like": "^0.0.x", "@stdlib/ndarray-base-ndarraylike2object": "^0.0.x", "@stdlib/ndarray-base-vind2bind": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From 8d28952dc7d65c51449c0098118184928ceecfbe Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 11:25:05 +0000 Subject: [PATCH 12/91] Remove files --- index.d.ts | 257 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2951 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 41d747e..0000000 --- a/index.d.ts +++ /dev/null @@ -1,257 +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. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Collection } from '@stdlib/types/object'; -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* Callback invoked for each array element. -* -* @returns result -*/ -type Nullary = () => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @returns result -*/ -type Unary = ( value: any ) => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @returns result -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Ternary = ( value: any, index: number, arr: ndarray ) => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayTernary = ( value: any, index: number, arr: Collection ) => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Mapper = Nullary | Unary | Binary | Ternary; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayMapper = Nullary | Unary | Binary | ArrayTernary; - -/** -* Function applied against an accumulator. -* -* @returns accumulator value -*/ -type NullaryReducer = () => void; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @returns accumulator value -*/ -type UnaryReducer = ( accumulator: any ) => any; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @returns accumulator value -*/ -type BinaryReducer = ( accumulator: any, value: any ) => any; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @returns accumulator value -*/ -type TernaryReducer = ( accumulator: any, value: any, index: number ) => any; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type QuaternaryReducer = ( accumulator: any, value: any, index: number, arr: ndarray ) => any; // tslint:disable-line:max-line-length - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayQuaternaryReducer = ( accumulator: any, value: any, index: number, arr: Collection ) => any; // tslint:disable-line:max-line-length - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type Reducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | QuaternaryReducer; // tslint:disable-line:max-line-length - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayReducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | ArrayQuaternaryReducer; // tslint:disable-line:max-line-length - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* var naryFunction = require( `@stdlib/utils/nary-function` ); -* var abs = require( `@stdlib/math/base/special/abs` ); -* var add = require( `@stdlib/math/base/ops/add` ); -* var array = require( `@stdlib/ndarray/array` ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 2 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -declare function mapReduceRight( arr: ndarray, initial: any, mapper: Mapper, reducer: Reducer, thisArg?: any ): any; // tslint:disable-line:max-line-length - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -*/ -declare function mapReduceRight( arr: Collection, initial: any, mapper: ArrayMapper, reducer: ArrayReducer, thisArg?: any ): any; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = mapReduceRight; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 6dac8d7..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@esm/index.mjs";function o(o,a,m,l,j){if(!e(m))throw new TypeError(n("0kW3Z",m));if(!e(l))throw new TypeError(n("0kW3E",l));if(t(o))return function(r,t,e,s,i){var n,o,a,m,l,j,f,h,p,c,b;if(m=r.length,f=r.shape,n=r.data,h=r.strides,p=r.offset,o=r.order,l=r.getter,j=r.ref,0===f.length)return s.call(i,t,e(l(n,p),0,j),0,j);for(a=t,b=m-1;b>=0;b--)c=d(f,h,p,o,b,"throw"),a=s.call(i,a,e(l(n,c),b,j),b,j);return a}(s(o),a,m,l,j);if(r(o))return function(r,t,e,s,i){var n,d,o,a;for(n=r.data,d=r.getter,o=t,a=n.length-1;a>=0;a--)o=s.call(i,o,e(d(n,a),a,n),a,n);return o}(i(o),a,m,l,j);throw new TypeError(n("0kWC4",o))}export{o as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 703007b..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js","../lib/ndarray.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object' ;\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object' ;\nimport arraylike2object from '@stdlib/array-base-arraylike2object' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport ndarrayFcn from './ndarray.js' ;\nimport arrayFcn from './array.js' ;\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function' ;\n* import add from '@stdlib/math-base-ops-add' ;\n* import abs from '@stdlib/math-base-special-abs' ;\n* import array from '@stdlib/ndarray-array' ;\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '0kW3Z', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '0kW3E', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '0kWC4', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind' ;\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Function} x.getter - callback for accessing `x` data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64' ;\n* import Complex64 from '@stdlib/complex-float32' ;\n* import realf from '@stdlib/complex-realf' ;\n* import imagf from '@stdlib/complex-imagf' ;\n* import cceil from '@stdlib/math-base-special-cceil' ;\n* import cadd from '@stdlib/math-base-ops-cadd' ;\n* import naryFunction from '@stdlib/utils-nary-function' ;\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'getter': getter\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.getter;\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Function} x.getter - callback for accessing input array data elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'getter': getter\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.getter;\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","getter","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;qoBA0FA,SAASA,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,GAAKK,EAAeR,GACnB,OCGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,OAGRZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAtH1B,SAuHTR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,EDlDCkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OE1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,OAGRf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,EFyBCqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,QAASP"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 34d45ea..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 1463defea093f97eacf3620c6f887cb5c05a67a2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 11:26:02 +0000 Subject: [PATCH 13/91] 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 | 63 +- benchmark/benchmark.array.js | 98 - benchmark/benchmark.ndarray.js | 109 - branches.md | 53 - docs/repl.txt | 65 - docs/types/test.ts | 184 -- examples/index.js | 52 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/array.js | 83 - lib/index.js | 65 - lib/main.js | 110 - lib/ndarray.js | 155 -- package.json | 76 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 637 ----- 40 files changed, 2725 insertions(+), 4609 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.array.js delete mode 100644 benchmark/benchmark.ndarray.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/array.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/ndarray.js create mode 100644 stats.html delete mode 100644 test/test.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 563942d..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-08-01T01:42:49.873Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3b4c7b4..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/utils/map-reduce-right) 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 bbe0806..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/utils/map-reduce-right) 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 + + ```
@@ -260,7 +253,7 @@ console.log( 'sum: %d', out ); ## 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]. @@ -320,11 +313,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/utils-map-reduce-right/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/stdlib +[@stdlib/array/complex64]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/array/complex128]: https://github.com/stdlib-js/stdlib +[@stdlib/array/complex128]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.array.js b/benchmark/benchmark.array.js deleted file mode 100644 index e87feb5..0000000 --- a/benchmark/benchmark.array.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = filled( -3.0, len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::array:len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.ndarray.js b/benchmark/benchmark.ndarray.js deleted file mode 100644 index e3bfba2..0000000 --- a/benchmark/benchmark.ndarray.js +++ /dev/null @@ -1,109 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var xbuf; - var opts; - var x; - - xbuf = filled( -3.0, len ); - - opts = { - 'dtype': 'generic' - }; - x = array( xbuf, opts ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::ndarray:len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 651bb38..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/utils/map-reduce-right" -click B href "https://github.com/stdlib-js/utils-map-reduce-right/tree/main" -click C href "https://github.com/stdlib-js/utils-map-reduce-right/tree/production" -click D href "https://github.com/stdlib-js/utils-map-reduce-right/tree/esm" -click E href "https://github.com/stdlib-js/utils-map-reduce-right/tree/deno" -click F href "https://github.com/stdlib-js/utils-map-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/map-reduce-right -[production-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b580e87..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, initial, mapper, reducer[, thisArg] ) - Performs a map-reduce operation for each element in an array while iterating - from right to left and returns the accumulated result. - - When invoked, the mapping function is provided three arguments: - - - value: array element. - - index: element index. - - arr: input array. - - When invoked, the reducing function is provided four arguments: - - - accumulator: accumulated value. - - value: result after applying the mapping function to the current array - element. - - index: element index. - - arr: input array. - - If provided an empty array, the function returns the initial value. - - When provided an ndarray, the function performs a single-pass map-reduce - operation over the entire input ndarray (i.e., higher-order ndarray - dimensions are flattened to a single-dimension). - - Parameters - ---------- - arr: ArrayLikeObject|ndarray - Input array. - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - mapper: Function - Mapping function. - - reducer: Function - Reducing function. - - thisArg: any (optional) - Execution context for the reducing function. - - Returns - ------- - out: any - Accumulated result. - - Examples - -------- - // array-like object: - > var f1 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/special/abs}}, 1 ); - > var f2 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/ops/add}}, 2 ); - > var arr = [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0 ]; - > var out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - // ndarray: - > arr = {{alias:@stdlib/ndarray/array}}( arr, { 'shape': [ 2, 3 ] } ); - > out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 76168a1..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,184 +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. -*/ - -import array = require( '@stdlib/ndarray-array' ); -import mapReduceRight = require( './index' ); - -/** -* Mapping function. -* -* @param value - array element -* @returns result -*/ -function mapper( value: number ): number { - return value; -} - -/** -* Reducing function. -* -* @param acc - accumulated value -* @param v - array element -* @returns result -*/ -function reducer( acc: number, value: number ): number { - return acc + value; -} - - -// TESTS // - -// The function returns the accumulated value when provided a collection... -{ - mapReduceRight( [ 0, 1, 1, NaN, 2 ], 0, mapper, reducer ); // $ExpectType any - mapReduceRight( [ -1, 1, 2 ], 100, mapper, reducer ); // $ExpectType any - mapReduceRight( [ -1, 1, 2 ], 0, mapper, reducer, {} ); // $ExpectType any -} - -// The function returns the accumulated value when provided an ndarray... -{ - const arr = array( [ 1, 2, 3, 4, 5, 6 ] ); - - mapReduceRight( arr, 0, mapper, reducer ); // $ExpectType any - mapReduceRight( arr, 100, mapper, reducer ); // $ExpectType any - mapReduceRight( arr, 0, mapper, reducer, {} ); // $ExpectType any -} - -// The compiler throws an error if the function is provided a first argument which is not a collection or ndarray... -{ - mapReduceRight( 2, 0, mapper, reducer ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer ); // $ExpectError - - mapReduceRight( 2, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr1, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr2, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const arr1 = [ 1, 2, 3 ]; - - mapReduceRight(); // $ExpectError - mapReduceRight( arr1 ); // $ExpectError - mapReduceRight( arr1, 0 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ); // $ExpectError - mapReduceRight( arr1, 0, mapper, reducer, {}, 3 ); // $ExpectError - - const arr2 = array( [ 1, 2, 3 ] ); - - mapReduceRight(); // $ExpectError - mapReduceRight( arr2 ); // $ExpectError - mapReduceRight( arr2, 0 ); // $ExpectError - mapReduceRight( arr2, 0, mapper ); // $ExpectError - mapReduceRight( arr2, 0, mapper, reducer, {}, 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 7474059..0000000 --- a/examples/index.js +++ /dev/null @@ -1,52 +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. -*/ - -'use strict'; - -var filledarrayBy = require( '@stdlib/array-filled-by' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ).factory; -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var mapReduceRight = require( './../lib' ); - -function fill( i ) { - var rand = discreteUniform( -10*(i+1), 10*(i+1) ); - return filledarrayBy( 10, 'generic', rand ); -} - -// Create a two-dimensional ndarray (i.e., a matrix): -var x = array( filledarrayBy( 10, 'generic', fill ), { - 'dtype': 'generic', - 'flatten': true -}); - -// Create an explicit unary function: -var f1 = naryFunction( abs, 1 ); - -// Create an explicit binary function: -var f2 = naryFunction( add, 2 ); - -// Compute the sum of absolute values: -var out = mapReduceRight( x, 0, f1, f2 ); - -console.log( 'x:' ); -console.log( x.data ); - -console.log( 'sum: %d', out ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index a2eace0..41d747e 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Collection } from '@stdlib/types/object'; import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5110c6b --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@esm/index.mjs";function o(o,a,m,l,j){if(!e(m))throw new TypeError(n("0kW3Z",m));if(!e(l))throw new TypeError(n("0kW3E",l));if(t(o))return function(r,t,e,s,i){var n,o,a,m,l,j,f,h,p,c,b;if(m=r.length,f=r.shape,n=r.data,h=r.strides,p=r.offset,o=r.order,l=r.getter,j=r.ref,0===f.length)return s.call(i,t,e(l(n,p),0,j),0,j);for(a=t,b=m-1;b>=0;b--)c=d(f,h,p,o,b,"throw"),a=s.call(i,a,e(l(n,c),b,j),b,j);return a}(s(o),a,m,l,j);if(r(o))return function(r,t,e,s,i){var n,d,o,a;for(n=r.data,d=r.getter,o=t,a=n.length-1;a>=0;a--)o=s.call(i,o,e(d(n,a),a,n),a,n);return o}(i(o),a,m,l,j);throw new TypeError(n("0kWC4",o))}export{o as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..e44fe6a --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js","../lib/ndarray.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object' ;\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object' ;\nimport arraylike2object from '@stdlib/array-base-arraylike2object' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport ndarrayFcn from './ndarray.js' ;\nimport arrayFcn from './array.js' ;\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function' ;\n* import add from '@stdlib/math-base-ops-add' ;\n* import abs from '@stdlib/math-base-special-abs' ;\n* import array from '@stdlib/ndarray-array' ;\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '0kW3Z', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '0kW3E', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '0kWC4', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind' ;\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Function} x.getter - callback for accessing `x` data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64' ;\n* import Complex64 from '@stdlib/complex-float32' ;\n* import realf from '@stdlib/complex-realf' ;\n* import imagf from '@stdlib/complex-imagf' ;\n* import cceil from '@stdlib/math-base-special-cceil' ;\n* import cadd from '@stdlib/math-base-ops-cadd' ;\n* import naryFunction from '@stdlib/utils-nary-function' ;\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'getter': getter\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.getter;\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Function} x.getter - callback for accessing input array data elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'getter': getter\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.getter;\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","getter","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;4oBA0FA,SAASA,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,GAAKK,EAAeR,GACnB,OCGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,OAGRZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAtH1B,SAuHTR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,EDlDCkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OE1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,OAGRf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,EFyBCqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,QAASP"} \ No newline at end of file diff --git a/lib/array.js b/lib/array.js deleted file mode 100644 index 9f87c1f..0000000 --- a/lib/array.js +++ /dev/null @@ -1,83 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input array data -* @param {ArrayLikeObject} x.data - input array data -* @param {Function} x.getter - callback for accessing input array data elements -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf[ idx ]; -* } -* -* // Create the input array object: -* var x = { -* 'data': [ 1, 2, 3, 4 ], -* 'getter': getter -* }; -* -* // Compute the sum of squared values: -* var out = mapReduceRight( x, 0, square, sum ); -* // returns 30 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var get; - var acc; - var i; - - // Cache reference to the input data: - xbuf = x.data; - - // Cache the element accessor: - get = x.getter; - - // Iterate over each element... - acc = initial; - for ( i = xbuf.length-1; i >= 0; i-- ) { - acc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 522693e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +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. -*/ - -'use strict'; - -/** -* Perform a map-reduce operation against each element in an array while iterating from right to left and return the accumulated result. -* -* @module @stdlib/utils-map-reduce-right -* -* @example -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ - -// 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 c890358..0000000 --- a/lib/main.js +++ /dev/null @@ -1,110 +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. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ndarrayFcn = require( './ndarray.js' ); -var arrayFcn = require( './array.js' ); - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided the following arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided the following arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result of applying the mapping function against the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* @param {(ArrayLikeObject|ndarray)} arr - input array -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} [thisArg] - reduction function execution context -* @throws {TypeError} first argument must be an array-like object or an ndarray -* @throws {TypeError} third argument must be a function -* @throws {TypeError} fourth argument must be a function -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { - if ( !isFunction( mapper ) ) { - throw new TypeError( format( '0kW3Z', mapper ) ); - } - if ( !isFunction( reducer ) ) { - throw new TypeError( format( '0kW3E', reducer ) ); - } - if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like - return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - if ( isArrayLikeObject( arr ) ) { - return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - throw new TypeError( format( '0kWC4', arr ) ); -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/ndarray.js b/lib/ndarray.js deleted file mode 100644 index 8b2442d..0000000 --- a/lib/ndarray.js +++ /dev/null @@ -1,155 +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. -*/ - -'use strict'; - -// MODULES // - -var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); - - -// VARIABLES // - -var MODE = 'throw'; - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input ndarray meta data -* @param {string} x.ref - reference to original input ndarray-like object -* @param {string} x.dtype - data type -* @param {Collection} x.data - data buffer -* @param {NonNegativeInteger} x.length - number of elements -* @param {NonNegativeIntegerArray} x.shape - dimensions -* @param {IntegerArray} x.strides - stride lengths -* @param {NonNegativeInteger} x.offset - index offset -* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) -* @param {Function} x.getter - callback for accessing `x` data buffer elements -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var Complex64 = require( '@stdlib/complex-float32' ); -* var realf = require( '@stdlib/complex-realf' ); -* var imagf = require( '@stdlib/complex-imagf' ); -* var cceil = require( '@stdlib/math-base-special-cceil' ); -* var cadd = require( '@stdlib/math-base-ops-cadd' ); -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* -* // Create a data buffer: -* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] ); -* -* // Define the shape of the input array: -* var shape = [ 2, 2 ]; -* -* // Define the array strides: -* var sx = [ 2, 1 ]; -* -* // Define the index offset: -* var ox = 0; -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf.get( idx ); -* } -* -* // Create the input ndarray-like object: -* var x = { -* 'ref': null, -* 'dtype': 'complex64', -* 'data': xbuf, -* 'length': 4, -* 'shape': shape, -* 'strides': sx, -* 'offset': ox, -* 'order': 'row-major', -* 'getter': getter -* }; -* x.ref = x; -* -* // Compute the sum: -* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) ); -* -* var re = realf( v ); -* // returns 20.0 -* -* var im = imagf( v ); -* // returns 24.0 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var ordx; - var acc; - var len; - var get; - var ref; - var shx; - var sx; - var ox; - var ix; - var i; - - // Cache the total number of elements over which to iterate: - len = x.length; - - // Cache the input array shape: - shx = x.shape; - - // Cache reference to the input ndarray data buffer: - xbuf = x.data; - - // Cache reference to the stride array: - sx = x.strides; - - // Cache the index of the first indexed element: - ox = x.offset; - - // Cache the array order: - ordx = x.order; - - // Cache the element accessor: - get = x.getter; - - // Cache the reference to the original input array: - ref = x.ref; - - // Check for a zero-dimensional array... - if ( shx.length === 0 ) { - return reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len - } - // Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)... - acc = initial; - for ( i = len-1; i >= 0; i-- ) { - ix = vind2bind( shx, sx, ox, ordx, i, MODE ); - acc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/package.json b/package.json index 35888db..58c2ca2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.1", "description": "Perform a single-pass map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.", "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/array-base-arraylike2object": "^0.0.x", - "@stdlib/assert-is-array-like-object": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-ndarray-like": "^0.0.x", - "@stdlib/ndarray-base-ndarraylike2object": "^0.0.x", - "@stdlib/ndarray-base-vind2bind": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-base-filled": "^0.0.x", - "@stdlib/array-complex64": "^0.0.x", - "@stdlib/array-filled-by": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/complex-float32": "^0.0.x", - "@stdlib/complex-imagf": "^0.0.x", - "@stdlib/complex-realf": "^0.0.x", - "@stdlib/math-base-assert-is-nan": "^0.0.x", - "@stdlib/math-base-ops-add": "^0.0.x", - "@stdlib/math-base-ops-cadd": "^0.0.x", - "@stdlib/math-base-special-abs": "^0.0.x", - "@stdlib/math-base-special-cceil": "^0.0.x", - "@stdlib/math-base-special-pow": "^0.0.x", - "@stdlib/ndarray-array": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/random-base-discrete-uniform": "^0.0.x", - "@stdlib/utils-nary-function": "^0.0.x", - "@stdlib/utils-noop": "^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", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a34f322 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2c78efa..0000000 --- a/test/test.js +++ /dev/null @@ -1,637 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var cadd = require( '@stdlib/math-base-ops-cadd' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var cceil = require( '@stdlib/math-base-special-cceil' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var mapReduceRight = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapReduceRight, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a first argument which is either an array-like object or an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( value, 0, noop, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value, {} ); - }; - } -}); - -tape( 'the function performs a map-reduce operation for each element in an array (array-like object)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = [ -1, -2, -3 ]; - expected = 7; - actual = mapReduceRight( arr, 1, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (typed array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - expected = 7.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (complex number array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( cceil, 1 ); - f2 = naryFunction( cadd, 2 ); - - arr = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5 ] ); - expected = new Complex64( 12.0, 15.0 ); - actual = mapReduceRight( arr, new Complex64( 0.0, 0.0 ), f1, f2 ); - - t.strictEqual( realf( actual ), realf( expected ), 'returns expected value' ); - t.strictEqual( imagf( actual ), imagf( expected ), 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = array( [ -1.0, -2.0, -3.0, -4.0 ], { - 'dtype': 'generic' - }); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray; 0-dimensional)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = ndarray( 'generic', [ -10.0 ], [], [ 0 ], 0, 'row-major' ); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (array-like object)', function test( t ) { - var out = mapReduceRight( [], 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (ndarray)', function test( t ) { - var arr; - var out; - - arr = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 0, 2 ], [ 0, 2, 1 ], 0, 'row-major' ); - out = mapReduceRight( arr, 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function supports providing a `this` context (array-like object)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = [ -1.0, -2.0, -3.0 ]; - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function supports providing a `this` context (ndarray)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = array( [ -1.0, -2.0, -3.0 ], { - 'dtype': 'generic' - }); - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = array( [ 1, , , 4 ], { // eslint-disable-line no-sparse-arrays - 'dtype': 'generic' - }); - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); From a914657c735533b412db39a70156f42a1acebc4f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 03:48:57 +0000 Subject: [PATCH 14/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index d95cde3..c890358 100644 --- a/lib/main.js +++ b/lib/main.js @@ -25,7 +25,7 @@ var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); var isFunction = require( '@stdlib/assert-is-function' ); var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ndarrayFcn = require( './ndarray.js' ); var arrayFcn = require( './array.js' ); @@ -90,10 +90,10 @@ var arrayFcn = require( './array.js' ); */ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( !isFunction( mapper ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) ); + throw new TypeError( format( '0kW3Z', mapper ) ); } if ( !isFunction( reducer ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) ); + throw new TypeError( format( '0kW3E', reducer ) ); } if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len @@ -101,7 +101,7 @@ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( isArrayLikeObject( arr ) ) { return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len } - throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) ); + throw new TypeError( format( '0kWC4', arr ) ); } diff --git a/package.json b/package.json index a522b3d..35888db 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-ndarray-like": "^0.0.x", "@stdlib/ndarray-base-ndarraylike2object": "^0.0.x", "@stdlib/ndarray-base-vind2bind": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From 83d44bdb619f971ad20fd363468e79fe249d5214 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 11:15:15 +0000 Subject: [PATCH 15/91] Remove files --- index.d.ts | 257 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2951 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 41d747e..0000000 --- a/index.d.ts +++ /dev/null @@ -1,257 +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. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Collection } from '@stdlib/types/object'; -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* Callback invoked for each array element. -* -* @returns result -*/ -type Nullary = () => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @returns result -*/ -type Unary = ( value: any ) => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @returns result -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Ternary = ( value: any, index: number, arr: ndarray ) => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayTernary = ( value: any, index: number, arr: Collection ) => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Mapper = Nullary | Unary | Binary | Ternary; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayMapper = Nullary | Unary | Binary | ArrayTernary; - -/** -* Function applied against an accumulator. -* -* @returns accumulator value -*/ -type NullaryReducer = () => void; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @returns accumulator value -*/ -type UnaryReducer = ( accumulator: any ) => any; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @returns accumulator value -*/ -type BinaryReducer = ( accumulator: any, value: any ) => any; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @returns accumulator value -*/ -type TernaryReducer = ( accumulator: any, value: any, index: number ) => any; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type QuaternaryReducer = ( accumulator: any, value: any, index: number, arr: ndarray ) => any; // tslint:disable-line:max-line-length - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayQuaternaryReducer = ( accumulator: any, value: any, index: number, arr: Collection ) => any; // tslint:disable-line:max-line-length - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type Reducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | QuaternaryReducer; // tslint:disable-line:max-line-length - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayReducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | ArrayQuaternaryReducer; // tslint:disable-line:max-line-length - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* var naryFunction = require( `@stdlib/utils/nary-function` ); -* var abs = require( `@stdlib/math/base/special/abs` ); -* var add = require( `@stdlib/math/base/ops/add` ); -* var array = require( `@stdlib/ndarray/array` ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 2 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -declare function mapReduceRight( arr: ndarray, initial: any, mapper: Mapper, reducer: Reducer, thisArg?: any ): any; // tslint:disable-line:max-line-length - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -*/ -declare function mapReduceRight( arr: Collection, initial: any, mapper: ArrayMapper, reducer: ArrayReducer, thisArg?: any ): any; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = mapReduceRight; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5110c6b..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@esm/index.mjs";function o(o,a,m,l,j){if(!e(m))throw new TypeError(n("0kW3Z",m));if(!e(l))throw new TypeError(n("0kW3E",l));if(t(o))return function(r,t,e,s,i){var n,o,a,m,l,j,f,h,p,c,b;if(m=r.length,f=r.shape,n=r.data,h=r.strides,p=r.offset,o=r.order,l=r.getter,j=r.ref,0===f.length)return s.call(i,t,e(l(n,p),0,j),0,j);for(a=t,b=m-1;b>=0;b--)c=d(f,h,p,o,b,"throw"),a=s.call(i,a,e(l(n,c),b,j),b,j);return a}(s(o),a,m,l,j);if(r(o))return function(r,t,e,s,i){var n,d,o,a;for(n=r.data,d=r.getter,o=t,a=n.length-1;a>=0;a--)o=s.call(i,o,e(d(n,a),a,n),a,n);return o}(i(o),a,m,l,j);throw new TypeError(n("0kWC4",o))}export{o as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index e44fe6a..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js","../lib/ndarray.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object' ;\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object' ;\nimport arraylike2object from '@stdlib/array-base-arraylike2object' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport ndarrayFcn from './ndarray.js' ;\nimport arrayFcn from './array.js' ;\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function' ;\n* import add from '@stdlib/math-base-ops-add' ;\n* import abs from '@stdlib/math-base-special-abs' ;\n* import array from '@stdlib/ndarray-array' ;\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '0kW3Z', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '0kW3E', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '0kWC4', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind' ;\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Function} x.getter - callback for accessing `x` data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64' ;\n* import Complex64 from '@stdlib/complex-float32' ;\n* import realf from '@stdlib/complex-realf' ;\n* import imagf from '@stdlib/complex-imagf' ;\n* import cceil from '@stdlib/math-base-special-cceil' ;\n* import cadd from '@stdlib/math-base-ops-cadd' ;\n* import naryFunction from '@stdlib/utils-nary-function' ;\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'getter': getter\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.getter;\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Function} x.getter - callback for accessing input array data elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'getter': getter\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.getter;\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","getter","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;4oBA0FA,SAASA,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,GAAKK,EAAeR,GACnB,OCGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,OAGRZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAtH1B,SAuHTR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,EDlDCkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OE1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,OAGRf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,EFyBCqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,QAASP"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a34f322..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 5f15d8b754ae57d0d0fc49c65a8254522dc5463d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 11:16:23 +0000 Subject: [PATCH 16/91] 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 | 63 +- benchmark/benchmark.array.js | 98 - benchmark/benchmark.ndarray.js | 109 - branches.md | 53 - docs/repl.txt | 65 - docs/types/test.ts | 184 -- examples/index.js | 52 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/array.js | 83 - lib/index.js | 65 - lib/main.js | 110 - lib/ndarray.js | 155 -- package.json | 76 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 637 ----- 40 files changed, 2725 insertions(+), 4625 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.array.js delete mode 100644 benchmark/benchmark.ndarray.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/array.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/ndarray.js create mode 100644 stats.html delete mode 100644 test/test.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 f33bac6..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-09-01T01:42:54.108Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3b4c7b4..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/utils/map-reduce-right) 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 bbe0806..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/utils/map-reduce-right) 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 + + ```
@@ -260,7 +253,7 @@ console.log( 'sum: %d', out ); ## 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]. @@ -320,11 +313,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/utils-map-reduce-right/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/stdlib +[@stdlib/array/complex64]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/array/complex128]: https://github.com/stdlib-js/stdlib +[@stdlib/array/complex128]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.array.js b/benchmark/benchmark.array.js deleted file mode 100644 index e87feb5..0000000 --- a/benchmark/benchmark.array.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = filled( -3.0, len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::array:len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.ndarray.js b/benchmark/benchmark.ndarray.js deleted file mode 100644 index e3bfba2..0000000 --- a/benchmark/benchmark.ndarray.js +++ /dev/null @@ -1,109 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var xbuf; - var opts; - var x; - - xbuf = filled( -3.0, len ); - - opts = { - 'dtype': 'generic' - }; - x = array( xbuf, opts ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::ndarray:len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 651bb38..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/utils/map-reduce-right" -click B href "https://github.com/stdlib-js/utils-map-reduce-right/tree/main" -click C href "https://github.com/stdlib-js/utils-map-reduce-right/tree/production" -click D href "https://github.com/stdlib-js/utils-map-reduce-right/tree/esm" -click E href "https://github.com/stdlib-js/utils-map-reduce-right/tree/deno" -click F href "https://github.com/stdlib-js/utils-map-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/map-reduce-right -[production-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b580e87..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, initial, mapper, reducer[, thisArg] ) - Performs a map-reduce operation for each element in an array while iterating - from right to left and returns the accumulated result. - - When invoked, the mapping function is provided three arguments: - - - value: array element. - - index: element index. - - arr: input array. - - When invoked, the reducing function is provided four arguments: - - - accumulator: accumulated value. - - value: result after applying the mapping function to the current array - element. - - index: element index. - - arr: input array. - - If provided an empty array, the function returns the initial value. - - When provided an ndarray, the function performs a single-pass map-reduce - operation over the entire input ndarray (i.e., higher-order ndarray - dimensions are flattened to a single-dimension). - - Parameters - ---------- - arr: ArrayLikeObject|ndarray - Input array. - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - mapper: Function - Mapping function. - - reducer: Function - Reducing function. - - thisArg: any (optional) - Execution context for the reducing function. - - Returns - ------- - out: any - Accumulated result. - - Examples - -------- - // array-like object: - > var f1 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/special/abs}}, 1 ); - > var f2 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/ops/add}}, 2 ); - > var arr = [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0 ]; - > var out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - // ndarray: - > arr = {{alias:@stdlib/ndarray/array}}( arr, { 'shape': [ 2, 3 ] } ); - > out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 76168a1..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,184 +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. -*/ - -import array = require( '@stdlib/ndarray-array' ); -import mapReduceRight = require( './index' ); - -/** -* Mapping function. -* -* @param value - array element -* @returns result -*/ -function mapper( value: number ): number { - return value; -} - -/** -* Reducing function. -* -* @param acc - accumulated value -* @param v - array element -* @returns result -*/ -function reducer( acc: number, value: number ): number { - return acc + value; -} - - -// TESTS // - -// The function returns the accumulated value when provided a collection... -{ - mapReduceRight( [ 0, 1, 1, NaN, 2 ], 0, mapper, reducer ); // $ExpectType any - mapReduceRight( [ -1, 1, 2 ], 100, mapper, reducer ); // $ExpectType any - mapReduceRight( [ -1, 1, 2 ], 0, mapper, reducer, {} ); // $ExpectType any -} - -// The function returns the accumulated value when provided an ndarray... -{ - const arr = array( [ 1, 2, 3, 4, 5, 6 ] ); - - mapReduceRight( arr, 0, mapper, reducer ); // $ExpectType any - mapReduceRight( arr, 100, mapper, reducer ); // $ExpectType any - mapReduceRight( arr, 0, mapper, reducer, {} ); // $ExpectType any -} - -// The compiler throws an error if the function is provided a first argument which is not a collection or ndarray... -{ - mapReduceRight( 2, 0, mapper, reducer ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer ); // $ExpectError - - mapReduceRight( 2, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr1, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr2, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const arr1 = [ 1, 2, 3 ]; - - mapReduceRight(); // $ExpectError - mapReduceRight( arr1 ); // $ExpectError - mapReduceRight( arr1, 0 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ); // $ExpectError - mapReduceRight( arr1, 0, mapper, reducer, {}, 3 ); // $ExpectError - - const arr2 = array( [ 1, 2, 3 ] ); - - mapReduceRight(); // $ExpectError - mapReduceRight( arr2 ); // $ExpectError - mapReduceRight( arr2, 0 ); // $ExpectError - mapReduceRight( arr2, 0, mapper ); // $ExpectError - mapReduceRight( arr2, 0, mapper, reducer, {}, 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 7474059..0000000 --- a/examples/index.js +++ /dev/null @@ -1,52 +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. -*/ - -'use strict'; - -var filledarrayBy = require( '@stdlib/array-filled-by' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ).factory; -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var mapReduceRight = require( './../lib' ); - -function fill( i ) { - var rand = discreteUniform( -10*(i+1), 10*(i+1) ); - return filledarrayBy( 10, 'generic', rand ); -} - -// Create a two-dimensional ndarray (i.e., a matrix): -var x = array( filledarrayBy( 10, 'generic', fill ), { - 'dtype': 'generic', - 'flatten': true -}); - -// Create an explicit unary function: -var f1 = naryFunction( abs, 1 ); - -// Create an explicit binary function: -var f2 = naryFunction( add, 2 ); - -// Compute the sum of absolute values: -var out = mapReduceRight( x, 0, f1, f2 ); - -console.log( 'x:' ); -console.log( x.data ); - -console.log( 'sum: %d', out ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index a2eace0..41d747e 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Collection } from '@stdlib/types/object'; import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5110c6b --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@esm/index.mjs";function o(o,a,m,l,j){if(!e(m))throw new TypeError(n("0kW3Z",m));if(!e(l))throw new TypeError(n("0kW3E",l));if(t(o))return function(r,t,e,s,i){var n,o,a,m,l,j,f,h,p,c,b;if(m=r.length,f=r.shape,n=r.data,h=r.strides,p=r.offset,o=r.order,l=r.getter,j=r.ref,0===f.length)return s.call(i,t,e(l(n,p),0,j),0,j);for(a=t,b=m-1;b>=0;b--)c=d(f,h,p,o,b,"throw"),a=s.call(i,a,e(l(n,c),b,j),b,j);return a}(s(o),a,m,l,j);if(r(o))return function(r,t,e,s,i){var n,d,o,a;for(n=r.data,d=r.getter,o=t,a=n.length-1;a>=0;a--)o=s.call(i,o,e(d(n,a),a,n),a,n);return o}(i(o),a,m,l,j);throw new TypeError(n("0kWC4",o))}export{o as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..e44fe6a --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js","../lib/ndarray.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object' ;\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object' ;\nimport arraylike2object from '@stdlib/array-base-arraylike2object' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport ndarrayFcn from './ndarray.js' ;\nimport arrayFcn from './array.js' ;\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function' ;\n* import add from '@stdlib/math-base-ops-add' ;\n* import abs from '@stdlib/math-base-special-abs' ;\n* import array from '@stdlib/ndarray-array' ;\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '0kW3Z', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '0kW3E', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '0kWC4', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind' ;\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Function} x.getter - callback for accessing `x` data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64' ;\n* import Complex64 from '@stdlib/complex-float32' ;\n* import realf from '@stdlib/complex-realf' ;\n* import imagf from '@stdlib/complex-imagf' ;\n* import cceil from '@stdlib/math-base-special-cceil' ;\n* import cadd from '@stdlib/math-base-ops-cadd' ;\n* import naryFunction from '@stdlib/utils-nary-function' ;\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'getter': getter\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.getter;\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Function} x.getter - callback for accessing input array data elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'getter': getter\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.getter;\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","getter","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;4oBA0FA,SAASA,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,GAAKK,EAAeR,GACnB,OCGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,OAGRZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAtH1B,SAuHTR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,EDlDCkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OE1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,OAGRf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,EFyBCqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,QAASP"} \ No newline at end of file diff --git a/lib/array.js b/lib/array.js deleted file mode 100644 index 9f87c1f..0000000 --- a/lib/array.js +++ /dev/null @@ -1,83 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input array data -* @param {ArrayLikeObject} x.data - input array data -* @param {Function} x.getter - callback for accessing input array data elements -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf[ idx ]; -* } -* -* // Create the input array object: -* var x = { -* 'data': [ 1, 2, 3, 4 ], -* 'getter': getter -* }; -* -* // Compute the sum of squared values: -* var out = mapReduceRight( x, 0, square, sum ); -* // returns 30 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var get; - var acc; - var i; - - // Cache reference to the input data: - xbuf = x.data; - - // Cache the element accessor: - get = x.getter; - - // Iterate over each element... - acc = initial; - for ( i = xbuf.length-1; i >= 0; i-- ) { - acc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 522693e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +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. -*/ - -'use strict'; - -/** -* Perform a map-reduce operation against each element in an array while iterating from right to left and return the accumulated result. -* -* @module @stdlib/utils-map-reduce-right -* -* @example -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ - -// 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 c890358..0000000 --- a/lib/main.js +++ /dev/null @@ -1,110 +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. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ndarrayFcn = require( './ndarray.js' ); -var arrayFcn = require( './array.js' ); - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided the following arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided the following arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result of applying the mapping function against the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* @param {(ArrayLikeObject|ndarray)} arr - input array -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} [thisArg] - reduction function execution context -* @throws {TypeError} first argument must be an array-like object or an ndarray -* @throws {TypeError} third argument must be a function -* @throws {TypeError} fourth argument must be a function -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { - if ( !isFunction( mapper ) ) { - throw new TypeError( format( '0kW3Z', mapper ) ); - } - if ( !isFunction( reducer ) ) { - throw new TypeError( format( '0kW3E', reducer ) ); - } - if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like - return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - if ( isArrayLikeObject( arr ) ) { - return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - throw new TypeError( format( '0kWC4', arr ) ); -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/ndarray.js b/lib/ndarray.js deleted file mode 100644 index 8b2442d..0000000 --- a/lib/ndarray.js +++ /dev/null @@ -1,155 +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. -*/ - -'use strict'; - -// MODULES // - -var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); - - -// VARIABLES // - -var MODE = 'throw'; - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input ndarray meta data -* @param {string} x.ref - reference to original input ndarray-like object -* @param {string} x.dtype - data type -* @param {Collection} x.data - data buffer -* @param {NonNegativeInteger} x.length - number of elements -* @param {NonNegativeIntegerArray} x.shape - dimensions -* @param {IntegerArray} x.strides - stride lengths -* @param {NonNegativeInteger} x.offset - index offset -* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) -* @param {Function} x.getter - callback for accessing `x` data buffer elements -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var Complex64 = require( '@stdlib/complex-float32' ); -* var realf = require( '@stdlib/complex-realf' ); -* var imagf = require( '@stdlib/complex-imagf' ); -* var cceil = require( '@stdlib/math-base-special-cceil' ); -* var cadd = require( '@stdlib/math-base-ops-cadd' ); -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* -* // Create a data buffer: -* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] ); -* -* // Define the shape of the input array: -* var shape = [ 2, 2 ]; -* -* // Define the array strides: -* var sx = [ 2, 1 ]; -* -* // Define the index offset: -* var ox = 0; -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf.get( idx ); -* } -* -* // Create the input ndarray-like object: -* var x = { -* 'ref': null, -* 'dtype': 'complex64', -* 'data': xbuf, -* 'length': 4, -* 'shape': shape, -* 'strides': sx, -* 'offset': ox, -* 'order': 'row-major', -* 'getter': getter -* }; -* x.ref = x; -* -* // Compute the sum: -* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) ); -* -* var re = realf( v ); -* // returns 20.0 -* -* var im = imagf( v ); -* // returns 24.0 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var ordx; - var acc; - var len; - var get; - var ref; - var shx; - var sx; - var ox; - var ix; - var i; - - // Cache the total number of elements over which to iterate: - len = x.length; - - // Cache the input array shape: - shx = x.shape; - - // Cache reference to the input ndarray data buffer: - xbuf = x.data; - - // Cache reference to the stride array: - sx = x.strides; - - // Cache the index of the first indexed element: - ox = x.offset; - - // Cache the array order: - ordx = x.order; - - // Cache the element accessor: - get = x.getter; - - // Cache the reference to the original input array: - ref = x.ref; - - // Check for a zero-dimensional array... - if ( shx.length === 0 ) { - return reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len - } - // Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)... - acc = initial; - for ( i = len-1; i >= 0; i-- ) { - ix = vind2bind( shx, sx, ox, ordx, i, MODE ); - acc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/package.json b/package.json index 35888db..58c2ca2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.1", "description": "Perform a single-pass map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.", "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/array-base-arraylike2object": "^0.0.x", - "@stdlib/assert-is-array-like-object": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-ndarray-like": "^0.0.x", - "@stdlib/ndarray-base-ndarraylike2object": "^0.0.x", - "@stdlib/ndarray-base-vind2bind": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-base-filled": "^0.0.x", - "@stdlib/array-complex64": "^0.0.x", - "@stdlib/array-filled-by": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/complex-float32": "^0.0.x", - "@stdlib/complex-imagf": "^0.0.x", - "@stdlib/complex-realf": "^0.0.x", - "@stdlib/math-base-assert-is-nan": "^0.0.x", - "@stdlib/math-base-ops-add": "^0.0.x", - "@stdlib/math-base-ops-cadd": "^0.0.x", - "@stdlib/math-base-special-abs": "^0.0.x", - "@stdlib/math-base-special-cceil": "^0.0.x", - "@stdlib/math-base-special-pow": "^0.0.x", - "@stdlib/ndarray-array": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/random-base-discrete-uniform": "^0.0.x", - "@stdlib/utils-nary-function": "^0.0.x", - "@stdlib/utils-noop": "^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", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..aea6eb7 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2c78efa..0000000 --- a/test/test.js +++ /dev/null @@ -1,637 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var cadd = require( '@stdlib/math-base-ops-cadd' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var cceil = require( '@stdlib/math-base-special-cceil' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var mapReduceRight = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapReduceRight, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a first argument which is either an array-like object or an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( value, 0, noop, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value, {} ); - }; - } -}); - -tape( 'the function performs a map-reduce operation for each element in an array (array-like object)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = [ -1, -2, -3 ]; - expected = 7; - actual = mapReduceRight( arr, 1, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (typed array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - expected = 7.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (complex number array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( cceil, 1 ); - f2 = naryFunction( cadd, 2 ); - - arr = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5 ] ); - expected = new Complex64( 12.0, 15.0 ); - actual = mapReduceRight( arr, new Complex64( 0.0, 0.0 ), f1, f2 ); - - t.strictEqual( realf( actual ), realf( expected ), 'returns expected value' ); - t.strictEqual( imagf( actual ), imagf( expected ), 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = array( [ -1.0, -2.0, -3.0, -4.0 ], { - 'dtype': 'generic' - }); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray; 0-dimensional)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = ndarray( 'generic', [ -10.0 ], [], [ 0 ], 0, 'row-major' ); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (array-like object)', function test( t ) { - var out = mapReduceRight( [], 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (ndarray)', function test( t ) { - var arr; - var out; - - arr = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 0, 2 ], [ 0, 2, 1 ], 0, 'row-major' ); - out = mapReduceRight( arr, 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function supports providing a `this` context (array-like object)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = [ -1.0, -2.0, -3.0 ]; - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function supports providing a `this` context (ndarray)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = array( [ -1.0, -2.0, -3.0 ], { - 'dtype': 'generic' - }); - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = array( [ 1, , , 4 ], { // eslint-disable-line no-sparse-arrays - 'dtype': 'generic' - }); - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); From a787695609bf040d9e7703ff13eb899313a574ff Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 04:17:14 +0000 Subject: [PATCH 17/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index d95cde3..c890358 100644 --- a/lib/main.js +++ b/lib/main.js @@ -25,7 +25,7 @@ var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); var isFunction = require( '@stdlib/assert-is-function' ); var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ndarrayFcn = require( './ndarray.js' ); var arrayFcn = require( './array.js' ); @@ -90,10 +90,10 @@ var arrayFcn = require( './array.js' ); */ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( !isFunction( mapper ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) ); + throw new TypeError( format( '0kW3Z', mapper ) ); } if ( !isFunction( reducer ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) ); + throw new TypeError( format( '0kW3E', reducer ) ); } if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len @@ -101,7 +101,7 @@ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( isArrayLikeObject( arr ) ) { return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len } - throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) ); + throw new TypeError( format( '0kWC4', arr ) ); } diff --git a/package.json b/package.json index a522b3d..35888db 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-ndarray-like": "^0.0.x", "@stdlib/ndarray-base-ndarraylike2object": "^0.0.x", "@stdlib/ndarray-base-vind2bind": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From 3e0c01ed3817dce19d4e05cd30e8ec92d96a28ab Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 21:13:00 +0000 Subject: [PATCH 18/91] Remove files --- index.d.ts | 257 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2951 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 41d747e..0000000 --- a/index.d.ts +++ /dev/null @@ -1,257 +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. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Collection } from '@stdlib/types/object'; -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* Callback invoked for each array element. -* -* @returns result -*/ -type Nullary = () => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @returns result -*/ -type Unary = ( value: any ) => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @returns result -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Ternary = ( value: any, index: number, arr: ndarray ) => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayTernary = ( value: any, index: number, arr: Collection ) => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Mapper = Nullary | Unary | Binary | Ternary; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayMapper = Nullary | Unary | Binary | ArrayTernary; - -/** -* Function applied against an accumulator. -* -* @returns accumulator value -*/ -type NullaryReducer = () => void; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @returns accumulator value -*/ -type UnaryReducer = ( accumulator: any ) => any; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @returns accumulator value -*/ -type BinaryReducer = ( accumulator: any, value: any ) => any; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @returns accumulator value -*/ -type TernaryReducer = ( accumulator: any, value: any, index: number ) => any; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type QuaternaryReducer = ( accumulator: any, value: any, index: number, arr: ndarray ) => any; // tslint:disable-line:max-line-length - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayQuaternaryReducer = ( accumulator: any, value: any, index: number, arr: Collection ) => any; // tslint:disable-line:max-line-length - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type Reducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | QuaternaryReducer; // tslint:disable-line:max-line-length - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayReducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | ArrayQuaternaryReducer; // tslint:disable-line:max-line-length - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* var naryFunction = require( `@stdlib/utils/nary-function` ); -* var abs = require( `@stdlib/math/base/special/abs` ); -* var add = require( `@stdlib/math/base/ops/add` ); -* var array = require( `@stdlib/ndarray/array` ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 2 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -declare function mapReduceRight( arr: ndarray, initial: any, mapper: Mapper, reducer: Reducer, thisArg?: any ): any; // tslint:disable-line:max-line-length - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -*/ -declare function mapReduceRight( arr: Collection, initial: any, mapper: ArrayMapper, reducer: ArrayReducer, thisArg?: any ): any; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = mapReduceRight; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5110c6b..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@esm/index.mjs";function o(o,a,m,l,j){if(!e(m))throw new TypeError(n("0kW3Z",m));if(!e(l))throw new TypeError(n("0kW3E",l));if(t(o))return function(r,t,e,s,i){var n,o,a,m,l,j,f,h,p,c,b;if(m=r.length,f=r.shape,n=r.data,h=r.strides,p=r.offset,o=r.order,l=r.getter,j=r.ref,0===f.length)return s.call(i,t,e(l(n,p),0,j),0,j);for(a=t,b=m-1;b>=0;b--)c=d(f,h,p,o,b,"throw"),a=s.call(i,a,e(l(n,c),b,j),b,j);return a}(s(o),a,m,l,j);if(r(o))return function(r,t,e,s,i){var n,d,o,a;for(n=r.data,d=r.getter,o=t,a=n.length-1;a>=0;a--)o=s.call(i,o,e(d(n,a),a,n),a,n);return o}(i(o),a,m,l,j);throw new TypeError(n("0kWC4",o))}export{o as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index e44fe6a..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js","../lib/ndarray.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object' ;\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object' ;\nimport arraylike2object from '@stdlib/array-base-arraylike2object' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport ndarrayFcn from './ndarray.js' ;\nimport arrayFcn from './array.js' ;\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function' ;\n* import add from '@stdlib/math-base-ops-add' ;\n* import abs from '@stdlib/math-base-special-abs' ;\n* import array from '@stdlib/ndarray-array' ;\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '0kW3Z', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '0kW3E', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '0kWC4', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind' ;\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Function} x.getter - callback for accessing `x` data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64' ;\n* import Complex64 from '@stdlib/complex-float32' ;\n* import realf from '@stdlib/complex-realf' ;\n* import imagf from '@stdlib/complex-imagf' ;\n* import cceil from '@stdlib/math-base-special-cceil' ;\n* import cadd from '@stdlib/math-base-ops-cadd' ;\n* import naryFunction from '@stdlib/utils-nary-function' ;\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'getter': getter\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.getter;\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Function} x.getter - callback for accessing input array data elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'getter': getter\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.getter;\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","getter","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;4oBA0FA,SAASA,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,GAAKK,EAAeR,GACnB,OCGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,OAGRZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAtH1B,SAuHTR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,EDlDCkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OE1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,OAGRf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,EFyBCqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,QAASP"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index aea6eb7..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 794a336795a8beb67ed5dbe64675a66c1c3bd702 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 21:13:58 +0000 Subject: [PATCH 19/91] 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 | 63 +- benchmark/benchmark.array.js | 98 - benchmark/benchmark.ndarray.js | 109 - branches.md | 53 - docs/repl.txt | 65 - docs/types/test.ts | 184 -- examples/index.js | 52 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/array.js | 83 - lib/index.js | 65 - lib/main.js | 110 - lib/ndarray.js | 155 -- package.json | 76 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 637 ----- 40 files changed, 2725 insertions(+), 4625 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.array.js delete mode 100644 benchmark/benchmark.ndarray.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/array.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/ndarray.js create mode 100644 stats.html delete mode 100644 test/test.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 422971a..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-10-01T02:10:25.698Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3b4c7b4..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/utils/map-reduce-right) 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 bbe0806..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/utils/map-reduce-right) 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 + + ```
@@ -260,7 +253,7 @@ console.log( 'sum: %d', out ); ## 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]. @@ -320,11 +313,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/utils-map-reduce-right/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/stdlib +[@stdlib/array/complex64]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/array/complex128]: https://github.com/stdlib-js/stdlib +[@stdlib/array/complex128]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.array.js b/benchmark/benchmark.array.js deleted file mode 100644 index e87feb5..0000000 --- a/benchmark/benchmark.array.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = filled( -3.0, len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::array:len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.ndarray.js b/benchmark/benchmark.ndarray.js deleted file mode 100644 index e3bfba2..0000000 --- a/benchmark/benchmark.ndarray.js +++ /dev/null @@ -1,109 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var xbuf; - var opts; - var x; - - xbuf = filled( -3.0, len ); - - opts = { - 'dtype': 'generic' - }; - x = array( xbuf, opts ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::ndarray:len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 651bb38..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/utils/map-reduce-right" -click B href "https://github.com/stdlib-js/utils-map-reduce-right/tree/main" -click C href "https://github.com/stdlib-js/utils-map-reduce-right/tree/production" -click D href "https://github.com/stdlib-js/utils-map-reduce-right/tree/esm" -click E href "https://github.com/stdlib-js/utils-map-reduce-right/tree/deno" -click F href "https://github.com/stdlib-js/utils-map-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/map-reduce-right -[production-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b580e87..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, initial, mapper, reducer[, thisArg] ) - Performs a map-reduce operation for each element in an array while iterating - from right to left and returns the accumulated result. - - When invoked, the mapping function is provided three arguments: - - - value: array element. - - index: element index. - - arr: input array. - - When invoked, the reducing function is provided four arguments: - - - accumulator: accumulated value. - - value: result after applying the mapping function to the current array - element. - - index: element index. - - arr: input array. - - If provided an empty array, the function returns the initial value. - - When provided an ndarray, the function performs a single-pass map-reduce - operation over the entire input ndarray (i.e., higher-order ndarray - dimensions are flattened to a single-dimension). - - Parameters - ---------- - arr: ArrayLikeObject|ndarray - Input array. - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - mapper: Function - Mapping function. - - reducer: Function - Reducing function. - - thisArg: any (optional) - Execution context for the reducing function. - - Returns - ------- - out: any - Accumulated result. - - Examples - -------- - // array-like object: - > var f1 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/special/abs}}, 1 ); - > var f2 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/ops/add}}, 2 ); - > var arr = [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0 ]; - > var out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - // ndarray: - > arr = {{alias:@stdlib/ndarray/array}}( arr, { 'shape': [ 2, 3 ] } ); - > out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 76168a1..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,184 +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. -*/ - -import array = require( '@stdlib/ndarray-array' ); -import mapReduceRight = require( './index' ); - -/** -* Mapping function. -* -* @param value - array element -* @returns result -*/ -function mapper( value: number ): number { - return value; -} - -/** -* Reducing function. -* -* @param acc - accumulated value -* @param v - array element -* @returns result -*/ -function reducer( acc: number, value: number ): number { - return acc + value; -} - - -// TESTS // - -// The function returns the accumulated value when provided a collection... -{ - mapReduceRight( [ 0, 1, 1, NaN, 2 ], 0, mapper, reducer ); // $ExpectType any - mapReduceRight( [ -1, 1, 2 ], 100, mapper, reducer ); // $ExpectType any - mapReduceRight( [ -1, 1, 2 ], 0, mapper, reducer, {} ); // $ExpectType any -} - -// The function returns the accumulated value when provided an ndarray... -{ - const arr = array( [ 1, 2, 3, 4, 5, 6 ] ); - - mapReduceRight( arr, 0, mapper, reducer ); // $ExpectType any - mapReduceRight( arr, 100, mapper, reducer ); // $ExpectType any - mapReduceRight( arr, 0, mapper, reducer, {} ); // $ExpectType any -} - -// The compiler throws an error if the function is provided a first argument which is not a collection or ndarray... -{ - mapReduceRight( 2, 0, mapper, reducer ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer ); // $ExpectError - - mapReduceRight( 2, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr1, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr2, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const arr1 = [ 1, 2, 3 ]; - - mapReduceRight(); // $ExpectError - mapReduceRight( arr1 ); // $ExpectError - mapReduceRight( arr1, 0 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ); // $ExpectError - mapReduceRight( arr1, 0, mapper, reducer, {}, 3 ); // $ExpectError - - const arr2 = array( [ 1, 2, 3 ] ); - - mapReduceRight(); // $ExpectError - mapReduceRight( arr2 ); // $ExpectError - mapReduceRight( arr2, 0 ); // $ExpectError - mapReduceRight( arr2, 0, mapper ); // $ExpectError - mapReduceRight( arr2, 0, mapper, reducer, {}, 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 7474059..0000000 --- a/examples/index.js +++ /dev/null @@ -1,52 +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. -*/ - -'use strict'; - -var filledarrayBy = require( '@stdlib/array-filled-by' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ).factory; -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var mapReduceRight = require( './../lib' ); - -function fill( i ) { - var rand = discreteUniform( -10*(i+1), 10*(i+1) ); - return filledarrayBy( 10, 'generic', rand ); -} - -// Create a two-dimensional ndarray (i.e., a matrix): -var x = array( filledarrayBy( 10, 'generic', fill ), { - 'dtype': 'generic', - 'flatten': true -}); - -// Create an explicit unary function: -var f1 = naryFunction( abs, 1 ); - -// Create an explicit binary function: -var f2 = naryFunction( add, 2 ); - -// Compute the sum of absolute values: -var out = mapReduceRight( x, 0, f1, f2 ); - -console.log( 'x:' ); -console.log( x.data ); - -console.log( 'sum: %d', out ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index a2eace0..41d747e 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Collection } from '@stdlib/types/object'; import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5110c6b --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@esm/index.mjs";function o(o,a,m,l,j){if(!e(m))throw new TypeError(n("0kW3Z",m));if(!e(l))throw new TypeError(n("0kW3E",l));if(t(o))return function(r,t,e,s,i){var n,o,a,m,l,j,f,h,p,c,b;if(m=r.length,f=r.shape,n=r.data,h=r.strides,p=r.offset,o=r.order,l=r.getter,j=r.ref,0===f.length)return s.call(i,t,e(l(n,p),0,j),0,j);for(a=t,b=m-1;b>=0;b--)c=d(f,h,p,o,b,"throw"),a=s.call(i,a,e(l(n,c),b,j),b,j);return a}(s(o),a,m,l,j);if(r(o))return function(r,t,e,s,i){var n,d,o,a;for(n=r.data,d=r.getter,o=t,a=n.length-1;a>=0;a--)o=s.call(i,o,e(d(n,a),a,n),a,n);return o}(i(o),a,m,l,j);throw new TypeError(n("0kWC4",o))}export{o as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..e44fe6a --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js","../lib/ndarray.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object' ;\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object' ;\nimport arraylike2object from '@stdlib/array-base-arraylike2object' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport ndarrayFcn from './ndarray.js' ;\nimport arrayFcn from './array.js' ;\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function' ;\n* import add from '@stdlib/math-base-ops-add' ;\n* import abs from '@stdlib/math-base-special-abs' ;\n* import array from '@stdlib/ndarray-array' ;\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '0kW3Z', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '0kW3E', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '0kWC4', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind' ;\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Function} x.getter - callback for accessing `x` data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64' ;\n* import Complex64 from '@stdlib/complex-float32' ;\n* import realf from '@stdlib/complex-realf' ;\n* import imagf from '@stdlib/complex-imagf' ;\n* import cceil from '@stdlib/math-base-special-cceil' ;\n* import cadd from '@stdlib/math-base-ops-cadd' ;\n* import naryFunction from '@stdlib/utils-nary-function' ;\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'getter': getter\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.getter;\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Function} x.getter - callback for accessing input array data elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'getter': getter\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.getter;\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","getter","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;4oBA0FA,SAASA,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,GAAKK,EAAeR,GACnB,OCGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,OAGRZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAtH1B,SAuHTR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,EDlDCkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OE1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,OAGRf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,EFyBCqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,QAASP"} \ No newline at end of file diff --git a/lib/array.js b/lib/array.js deleted file mode 100644 index 9f87c1f..0000000 --- a/lib/array.js +++ /dev/null @@ -1,83 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input array data -* @param {ArrayLikeObject} x.data - input array data -* @param {Function} x.getter - callback for accessing input array data elements -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf[ idx ]; -* } -* -* // Create the input array object: -* var x = { -* 'data': [ 1, 2, 3, 4 ], -* 'getter': getter -* }; -* -* // Compute the sum of squared values: -* var out = mapReduceRight( x, 0, square, sum ); -* // returns 30 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var get; - var acc; - var i; - - // Cache reference to the input data: - xbuf = x.data; - - // Cache the element accessor: - get = x.getter; - - // Iterate over each element... - acc = initial; - for ( i = xbuf.length-1; i >= 0; i-- ) { - acc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 522693e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +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. -*/ - -'use strict'; - -/** -* Perform a map-reduce operation against each element in an array while iterating from right to left and return the accumulated result. -* -* @module @stdlib/utils-map-reduce-right -* -* @example -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ - -// 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 c890358..0000000 --- a/lib/main.js +++ /dev/null @@ -1,110 +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. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ndarrayFcn = require( './ndarray.js' ); -var arrayFcn = require( './array.js' ); - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided the following arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided the following arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result of applying the mapping function against the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* @param {(ArrayLikeObject|ndarray)} arr - input array -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} [thisArg] - reduction function execution context -* @throws {TypeError} first argument must be an array-like object or an ndarray -* @throws {TypeError} third argument must be a function -* @throws {TypeError} fourth argument must be a function -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { - if ( !isFunction( mapper ) ) { - throw new TypeError( format( '0kW3Z', mapper ) ); - } - if ( !isFunction( reducer ) ) { - throw new TypeError( format( '0kW3E', reducer ) ); - } - if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like - return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - if ( isArrayLikeObject( arr ) ) { - return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - throw new TypeError( format( '0kWC4', arr ) ); -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/ndarray.js b/lib/ndarray.js deleted file mode 100644 index 8b2442d..0000000 --- a/lib/ndarray.js +++ /dev/null @@ -1,155 +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. -*/ - -'use strict'; - -// MODULES // - -var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); - - -// VARIABLES // - -var MODE = 'throw'; - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input ndarray meta data -* @param {string} x.ref - reference to original input ndarray-like object -* @param {string} x.dtype - data type -* @param {Collection} x.data - data buffer -* @param {NonNegativeInteger} x.length - number of elements -* @param {NonNegativeIntegerArray} x.shape - dimensions -* @param {IntegerArray} x.strides - stride lengths -* @param {NonNegativeInteger} x.offset - index offset -* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) -* @param {Function} x.getter - callback for accessing `x` data buffer elements -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var Complex64 = require( '@stdlib/complex-float32' ); -* var realf = require( '@stdlib/complex-realf' ); -* var imagf = require( '@stdlib/complex-imagf' ); -* var cceil = require( '@stdlib/math-base-special-cceil' ); -* var cadd = require( '@stdlib/math-base-ops-cadd' ); -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* -* // Create a data buffer: -* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] ); -* -* // Define the shape of the input array: -* var shape = [ 2, 2 ]; -* -* // Define the array strides: -* var sx = [ 2, 1 ]; -* -* // Define the index offset: -* var ox = 0; -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf.get( idx ); -* } -* -* // Create the input ndarray-like object: -* var x = { -* 'ref': null, -* 'dtype': 'complex64', -* 'data': xbuf, -* 'length': 4, -* 'shape': shape, -* 'strides': sx, -* 'offset': ox, -* 'order': 'row-major', -* 'getter': getter -* }; -* x.ref = x; -* -* // Compute the sum: -* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) ); -* -* var re = realf( v ); -* // returns 20.0 -* -* var im = imagf( v ); -* // returns 24.0 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var ordx; - var acc; - var len; - var get; - var ref; - var shx; - var sx; - var ox; - var ix; - var i; - - // Cache the total number of elements over which to iterate: - len = x.length; - - // Cache the input array shape: - shx = x.shape; - - // Cache reference to the input ndarray data buffer: - xbuf = x.data; - - // Cache reference to the stride array: - sx = x.strides; - - // Cache the index of the first indexed element: - ox = x.offset; - - // Cache the array order: - ordx = x.order; - - // Cache the element accessor: - get = x.getter; - - // Cache the reference to the original input array: - ref = x.ref; - - // Check for a zero-dimensional array... - if ( shx.length === 0 ) { - return reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len - } - // Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)... - acc = initial; - for ( i = len-1; i >= 0; i-- ) { - ix = vind2bind( shx, sx, ox, ordx, i, MODE ); - acc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/package.json b/package.json index 35888db..58c2ca2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.1", "description": "Perform a single-pass map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.", "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/array-base-arraylike2object": "^0.0.x", - "@stdlib/assert-is-array-like-object": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-ndarray-like": "^0.0.x", - "@stdlib/ndarray-base-ndarraylike2object": "^0.0.x", - "@stdlib/ndarray-base-vind2bind": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-base-filled": "^0.0.x", - "@stdlib/array-complex64": "^0.0.x", - "@stdlib/array-filled-by": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/complex-float32": "^0.0.x", - "@stdlib/complex-imagf": "^0.0.x", - "@stdlib/complex-realf": "^0.0.x", - "@stdlib/math-base-assert-is-nan": "^0.0.x", - "@stdlib/math-base-ops-add": "^0.0.x", - "@stdlib/math-base-ops-cadd": "^0.0.x", - "@stdlib/math-base-special-abs": "^0.0.x", - "@stdlib/math-base-special-cceil": "^0.0.x", - "@stdlib/math-base-special-pow": "^0.0.x", - "@stdlib/ndarray-array": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/random-base-discrete-uniform": "^0.0.x", - "@stdlib/utils-nary-function": "^0.0.x", - "@stdlib/utils-noop": "^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", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..23d9607 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2c78efa..0000000 --- a/test/test.js +++ /dev/null @@ -1,637 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var cadd = require( '@stdlib/math-base-ops-cadd' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var cceil = require( '@stdlib/math-base-special-cceil' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var mapReduceRight = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapReduceRight, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a first argument which is either an array-like object or an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( value, 0, noop, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value, {} ); - }; - } -}); - -tape( 'the function performs a map-reduce operation for each element in an array (array-like object)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = [ -1, -2, -3 ]; - expected = 7; - actual = mapReduceRight( arr, 1, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (typed array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - expected = 7.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (complex number array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( cceil, 1 ); - f2 = naryFunction( cadd, 2 ); - - arr = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5 ] ); - expected = new Complex64( 12.0, 15.0 ); - actual = mapReduceRight( arr, new Complex64( 0.0, 0.0 ), f1, f2 ); - - t.strictEqual( realf( actual ), realf( expected ), 'returns expected value' ); - t.strictEqual( imagf( actual ), imagf( expected ), 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = array( [ -1.0, -2.0, -3.0, -4.0 ], { - 'dtype': 'generic' - }); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray; 0-dimensional)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = ndarray( 'generic', [ -10.0 ], [], [ 0 ], 0, 'row-major' ); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (array-like object)', function test( t ) { - var out = mapReduceRight( [], 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (ndarray)', function test( t ) { - var arr; - var out; - - arr = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 0, 2 ], [ 0, 2, 1 ], 0, 'row-major' ); - out = mapReduceRight( arr, 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function supports providing a `this` context (array-like object)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = [ -1.0, -2.0, -3.0 ]; - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function supports providing a `this` context (ndarray)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = array( [ -1.0, -2.0, -3.0 ], { - 'dtype': 'generic' - }); - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = array( [ 1, , , 4 ], { // eslint-disable-line no-sparse-arrays - 'dtype': 'generic' - }); - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); From facb3570ad939e78f9b9955ccf055709152a041e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 04:01:25 +0000 Subject: [PATCH 20/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index d95cde3..c890358 100644 --- a/lib/main.js +++ b/lib/main.js @@ -25,7 +25,7 @@ var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); var isFunction = require( '@stdlib/assert-is-function' ); var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ndarrayFcn = require( './ndarray.js' ); var arrayFcn = require( './array.js' ); @@ -90,10 +90,10 @@ var arrayFcn = require( './array.js' ); */ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( !isFunction( mapper ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) ); + throw new TypeError( format( '0kW3Z', mapper ) ); } if ( !isFunction( reducer ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) ); + throw new TypeError( format( '0kW3E', reducer ) ); } if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len @@ -101,7 +101,7 @@ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( isArrayLikeObject( arr ) ) { return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len } - throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) ); + throw new TypeError( format( '0kWC4', arr ) ); } diff --git a/package.json b/package.json index a522b3d..35888db 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-ndarray-like": "^0.0.x", "@stdlib/ndarray-base-ndarraylike2object": "^0.0.x", "@stdlib/ndarray-base-vind2bind": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From d636f54add702e813657c2528c150d5a9fc9f04d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 12:05:40 +0000 Subject: [PATCH 21/91] Remove files --- index.d.ts | 257 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2951 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 41d747e..0000000 --- a/index.d.ts +++ /dev/null @@ -1,257 +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. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Collection } from '@stdlib/types/object'; -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* Callback invoked for each array element. -* -* @returns result -*/ -type Nullary = () => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @returns result -*/ -type Unary = ( value: any ) => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @returns result -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Ternary = ( value: any, index: number, arr: ndarray ) => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayTernary = ( value: any, index: number, arr: Collection ) => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Mapper = Nullary | Unary | Binary | Ternary; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayMapper = Nullary | Unary | Binary | ArrayTernary; - -/** -* Function applied against an accumulator. -* -* @returns accumulator value -*/ -type NullaryReducer = () => void; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @returns accumulator value -*/ -type UnaryReducer = ( accumulator: any ) => any; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @returns accumulator value -*/ -type BinaryReducer = ( accumulator: any, value: any ) => any; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @returns accumulator value -*/ -type TernaryReducer = ( accumulator: any, value: any, index: number ) => any; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type QuaternaryReducer = ( accumulator: any, value: any, index: number, arr: ndarray ) => any; // tslint:disable-line:max-line-length - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayQuaternaryReducer = ( accumulator: any, value: any, index: number, arr: Collection ) => any; // tslint:disable-line:max-line-length - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type Reducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | QuaternaryReducer; // tslint:disable-line:max-line-length - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayReducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | ArrayQuaternaryReducer; // tslint:disable-line:max-line-length - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* var naryFunction = require( `@stdlib/utils/nary-function` ); -* var abs = require( `@stdlib/math/base/special/abs` ); -* var add = require( `@stdlib/math/base/ops/add` ); -* var array = require( `@stdlib/ndarray/array` ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 2 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -declare function mapReduceRight( arr: ndarray, initial: any, mapper: Mapper, reducer: Reducer, thisArg?: any ): any; // tslint:disable-line:max-line-length - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -*/ -declare function mapReduceRight( arr: Collection, initial: any, mapper: ArrayMapper, reducer: ArrayReducer, thisArg?: any ): any; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = mapReduceRight; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5110c6b..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@esm/index.mjs";function o(o,a,m,l,j){if(!e(m))throw new TypeError(n("0kW3Z",m));if(!e(l))throw new TypeError(n("0kW3E",l));if(t(o))return function(r,t,e,s,i){var n,o,a,m,l,j,f,h,p,c,b;if(m=r.length,f=r.shape,n=r.data,h=r.strides,p=r.offset,o=r.order,l=r.getter,j=r.ref,0===f.length)return s.call(i,t,e(l(n,p),0,j),0,j);for(a=t,b=m-1;b>=0;b--)c=d(f,h,p,o,b,"throw"),a=s.call(i,a,e(l(n,c),b,j),b,j);return a}(s(o),a,m,l,j);if(r(o))return function(r,t,e,s,i){var n,d,o,a;for(n=r.data,d=r.getter,o=t,a=n.length-1;a>=0;a--)o=s.call(i,o,e(d(n,a),a,n),a,n);return o}(i(o),a,m,l,j);throw new TypeError(n("0kWC4",o))}export{o as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index e44fe6a..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js","../lib/ndarray.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object' ;\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object' ;\nimport arraylike2object from '@stdlib/array-base-arraylike2object' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport ndarrayFcn from './ndarray.js' ;\nimport arrayFcn from './array.js' ;\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function' ;\n* import add from '@stdlib/math-base-ops-add' ;\n* import abs from '@stdlib/math-base-special-abs' ;\n* import array from '@stdlib/ndarray-array' ;\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '0kW3Z', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '0kW3E', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '0kWC4', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind' ;\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Function} x.getter - callback for accessing `x` data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64' ;\n* import Complex64 from '@stdlib/complex-float32' ;\n* import realf from '@stdlib/complex-realf' ;\n* import imagf from '@stdlib/complex-imagf' ;\n* import cceil from '@stdlib/math-base-special-cceil' ;\n* import cadd from '@stdlib/math-base-ops-cadd' ;\n* import naryFunction from '@stdlib/utils-nary-function' ;\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'getter': getter\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.getter;\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Function} x.getter - callback for accessing input array data elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'getter': getter\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.getter;\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","getter","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;4oBA0FA,SAASA,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,GAAKK,EAAeR,GACnB,OCGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,OAGRZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAtH1B,SAuHTR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,EDlDCkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OE1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,OAGRf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,EFyBCqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,QAASP"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 23d9607..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 3fe8871b8ae6162a770dd6701ebe70f25b3c351e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 12:06:43 +0000 Subject: [PATCH 22/91] 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 | 63 +- benchmark/benchmark.array.js | 98 - benchmark/benchmark.ndarray.js | 109 - branches.md | 53 - docs/repl.txt | 65 - docs/types/test.ts | 184 - examples/index.js | 52 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/array.js | 83 - lib/index.js | 65 - lib/main.js | 110 - lib/ndarray.js | 155 - package.json | 76 +- stats.html | 4044 +++++++++++++++++++++ test/test.js | 637 ---- 40 files changed, 4080 insertions(+), 4625 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.array.js delete mode 100644 benchmark/benchmark.ndarray.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/array.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/ndarray.js create mode 100644 stats.html delete mode 100644 test/test.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 dabf605..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-11-01T01:55:58.358Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3b4c7b4..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/utils/map-reduce-right) 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 bbe0806..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/utils/map-reduce-right) 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 42fe05c..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: '21 21 * * 4' - - # 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 + + ```
@@ -260,7 +253,7 @@ console.log( 'sum: %d', out ); ## 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]. @@ -320,11 +313,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/utils-map-reduce-right/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/stdlib +[@stdlib/array/complex64]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/array/complex128]: https://github.com/stdlib-js/stdlib +[@stdlib/array/complex128]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.array.js b/benchmark/benchmark.array.js deleted file mode 100644 index e87feb5..0000000 --- a/benchmark/benchmark.array.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = filled( -3.0, len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::array:len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.ndarray.js b/benchmark/benchmark.ndarray.js deleted file mode 100644 index e3bfba2..0000000 --- a/benchmark/benchmark.ndarray.js +++ /dev/null @@ -1,109 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var xbuf; - var opts; - var x; - - xbuf = filled( -3.0, len ); - - opts = { - 'dtype': 'generic' - }; - x = array( xbuf, opts ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::ndarray:len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 651bb38..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/utils/map-reduce-right" -click B href "https://github.com/stdlib-js/utils-map-reduce-right/tree/main" -click C href "https://github.com/stdlib-js/utils-map-reduce-right/tree/production" -click D href "https://github.com/stdlib-js/utils-map-reduce-right/tree/esm" -click E href "https://github.com/stdlib-js/utils-map-reduce-right/tree/deno" -click F href "https://github.com/stdlib-js/utils-map-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/map-reduce-right -[production-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b580e87..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, initial, mapper, reducer[, thisArg] ) - Performs a map-reduce operation for each element in an array while iterating - from right to left and returns the accumulated result. - - When invoked, the mapping function is provided three arguments: - - - value: array element. - - index: element index. - - arr: input array. - - When invoked, the reducing function is provided four arguments: - - - accumulator: accumulated value. - - value: result after applying the mapping function to the current array - element. - - index: element index. - - arr: input array. - - If provided an empty array, the function returns the initial value. - - When provided an ndarray, the function performs a single-pass map-reduce - operation over the entire input ndarray (i.e., higher-order ndarray - dimensions are flattened to a single-dimension). - - Parameters - ---------- - arr: ArrayLikeObject|ndarray - Input array. - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - mapper: Function - Mapping function. - - reducer: Function - Reducing function. - - thisArg: any (optional) - Execution context for the reducing function. - - Returns - ------- - out: any - Accumulated result. - - Examples - -------- - // array-like object: - > var f1 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/special/abs}}, 1 ); - > var f2 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/ops/add}}, 2 ); - > var arr = [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0 ]; - > var out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - // ndarray: - > arr = {{alias:@stdlib/ndarray/array}}( arr, { 'shape': [ 2, 3 ] } ); - > out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 76168a1..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,184 +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. -*/ - -import array = require( '@stdlib/ndarray-array' ); -import mapReduceRight = require( './index' ); - -/** -* Mapping function. -* -* @param value - array element -* @returns result -*/ -function mapper( value: number ): number { - return value; -} - -/** -* Reducing function. -* -* @param acc - accumulated value -* @param v - array element -* @returns result -*/ -function reducer( acc: number, value: number ): number { - return acc + value; -} - - -// TESTS // - -// The function returns the accumulated value when provided a collection... -{ - mapReduceRight( [ 0, 1, 1, NaN, 2 ], 0, mapper, reducer ); // $ExpectType any - mapReduceRight( [ -1, 1, 2 ], 100, mapper, reducer ); // $ExpectType any - mapReduceRight( [ -1, 1, 2 ], 0, mapper, reducer, {} ); // $ExpectType any -} - -// The function returns the accumulated value when provided an ndarray... -{ - const arr = array( [ 1, 2, 3, 4, 5, 6 ] ); - - mapReduceRight( arr, 0, mapper, reducer ); // $ExpectType any - mapReduceRight( arr, 100, mapper, reducer ); // $ExpectType any - mapReduceRight( arr, 0, mapper, reducer, {} ); // $ExpectType any -} - -// The compiler throws an error if the function is provided a first argument which is not a collection or ndarray... -{ - mapReduceRight( 2, 0, mapper, reducer ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer ); // $ExpectError - - mapReduceRight( 2, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr1, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr2, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const arr1 = [ 1, 2, 3 ]; - - mapReduceRight(); // $ExpectError - mapReduceRight( arr1 ); // $ExpectError - mapReduceRight( arr1, 0 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ); // $ExpectError - mapReduceRight( arr1, 0, mapper, reducer, {}, 3 ); // $ExpectError - - const arr2 = array( [ 1, 2, 3 ] ); - - mapReduceRight(); // $ExpectError - mapReduceRight( arr2 ); // $ExpectError - mapReduceRight( arr2, 0 ); // $ExpectError - mapReduceRight( arr2, 0, mapper ); // $ExpectError - mapReduceRight( arr2, 0, mapper, reducer, {}, 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 7474059..0000000 --- a/examples/index.js +++ /dev/null @@ -1,52 +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. -*/ - -'use strict'; - -var filledarrayBy = require( '@stdlib/array-filled-by' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ).factory; -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var mapReduceRight = require( './../lib' ); - -function fill( i ) { - var rand = discreteUniform( -10*(i+1), 10*(i+1) ); - return filledarrayBy( 10, 'generic', rand ); -} - -// Create a two-dimensional ndarray (i.e., a matrix): -var x = array( filledarrayBy( 10, 'generic', fill ), { - 'dtype': 'generic', - 'flatten': true -}); - -// Create an explicit unary function: -var f1 = naryFunction( abs, 1 ); - -// Create an explicit binary function: -var f2 = naryFunction( add, 2 ); - -// Compute the sum of absolute values: -var out = mapReduceRight( x, 0, f1, f2 ); - -console.log( 'x:' ); -console.log( x.data ); - -console.log( 'sum: %d', out ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index a2eace0..41d747e 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Collection } from '@stdlib/types/object'; import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5110c6b --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@esm/index.mjs";function o(o,a,m,l,j){if(!e(m))throw new TypeError(n("0kW3Z",m));if(!e(l))throw new TypeError(n("0kW3E",l));if(t(o))return function(r,t,e,s,i){var n,o,a,m,l,j,f,h,p,c,b;if(m=r.length,f=r.shape,n=r.data,h=r.strides,p=r.offset,o=r.order,l=r.getter,j=r.ref,0===f.length)return s.call(i,t,e(l(n,p),0,j),0,j);for(a=t,b=m-1;b>=0;b--)c=d(f,h,p,o,b,"throw"),a=s.call(i,a,e(l(n,c),b,j),b,j);return a}(s(o),a,m,l,j);if(r(o))return function(r,t,e,s,i){var n,d,o,a;for(n=r.data,d=r.getter,o=t,a=n.length-1;a>=0;a--)o=s.call(i,o,e(d(n,a),a,n),a,n);return o}(i(o),a,m,l,j);throw new TypeError(n("0kWC4",o))}export{o as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..a2dfcd4 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js","../lib/ndarray.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object' ;\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object' ;\nimport arraylike2object from '@stdlib/array-base-arraylike2object' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport ndarrayFcn from './ndarray.js' ;\nimport arrayFcn from './array.js' ;\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function' ;\n* import add from '@stdlib/math-base-ops-add' ;\n* import abs from '@stdlib/math-base-special-abs' ;\n* import array from '@stdlib/ndarray-array' ;\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '0kW3Z', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '0kW3E', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '0kWC4', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind' ;\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Function} x.getter - callback for accessing `x` data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64' ;\n* import Complex64 from '@stdlib/complex-float32' ;\n* import realf from '@stdlib/complex-realf' ;\n* import imagf from '@stdlib/complex-imagf' ;\n* import cceil from '@stdlib/math-base-special-cceil' ;\n* import cadd from '@stdlib/math-base-ops-cadd' ;\n* import naryFunction from '@stdlib/utils-nary-function' ;\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'getter': getter\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.getter;\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Function} x.getter - callback for accessing input array data elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'getter': getter\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.getter;\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","getter","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;4oBA0FA,SAASA,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,GAAKK,EAAeR,GACnB,OCGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,OAGRZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAtH1B,SAuHTR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,CACR,CDnDSkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OE1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,OAGRf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,CACR,CFwBSqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,QAASP,GACvC"} \ No newline at end of file diff --git a/lib/array.js b/lib/array.js deleted file mode 100644 index 9f87c1f..0000000 --- a/lib/array.js +++ /dev/null @@ -1,83 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input array data -* @param {ArrayLikeObject} x.data - input array data -* @param {Function} x.getter - callback for accessing input array data elements -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf[ idx ]; -* } -* -* // Create the input array object: -* var x = { -* 'data': [ 1, 2, 3, 4 ], -* 'getter': getter -* }; -* -* // Compute the sum of squared values: -* var out = mapReduceRight( x, 0, square, sum ); -* // returns 30 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var get; - var acc; - var i; - - // Cache reference to the input data: - xbuf = x.data; - - // Cache the element accessor: - get = x.getter; - - // Iterate over each element... - acc = initial; - for ( i = xbuf.length-1; i >= 0; i-- ) { - acc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 522693e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +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. -*/ - -'use strict'; - -/** -* Perform a map-reduce operation against each element in an array while iterating from right to left and return the accumulated result. -* -* @module @stdlib/utils-map-reduce-right -* -* @example -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ - -// 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 c890358..0000000 --- a/lib/main.js +++ /dev/null @@ -1,110 +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. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ndarrayFcn = require( './ndarray.js' ); -var arrayFcn = require( './array.js' ); - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided the following arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided the following arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result of applying the mapping function against the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* @param {(ArrayLikeObject|ndarray)} arr - input array -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} [thisArg] - reduction function execution context -* @throws {TypeError} first argument must be an array-like object or an ndarray -* @throws {TypeError} third argument must be a function -* @throws {TypeError} fourth argument must be a function -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { - if ( !isFunction( mapper ) ) { - throw new TypeError( format( '0kW3Z', mapper ) ); - } - if ( !isFunction( reducer ) ) { - throw new TypeError( format( '0kW3E', reducer ) ); - } - if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like - return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - if ( isArrayLikeObject( arr ) ) { - return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - throw new TypeError( format( '0kWC4', arr ) ); -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/ndarray.js b/lib/ndarray.js deleted file mode 100644 index 8b2442d..0000000 --- a/lib/ndarray.js +++ /dev/null @@ -1,155 +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. -*/ - -'use strict'; - -// MODULES // - -var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); - - -// VARIABLES // - -var MODE = 'throw'; - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input ndarray meta data -* @param {string} x.ref - reference to original input ndarray-like object -* @param {string} x.dtype - data type -* @param {Collection} x.data - data buffer -* @param {NonNegativeInteger} x.length - number of elements -* @param {NonNegativeIntegerArray} x.shape - dimensions -* @param {IntegerArray} x.strides - stride lengths -* @param {NonNegativeInteger} x.offset - index offset -* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) -* @param {Function} x.getter - callback for accessing `x` data buffer elements -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var Complex64 = require( '@stdlib/complex-float32' ); -* var realf = require( '@stdlib/complex-realf' ); -* var imagf = require( '@stdlib/complex-imagf' ); -* var cceil = require( '@stdlib/math-base-special-cceil' ); -* var cadd = require( '@stdlib/math-base-ops-cadd' ); -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* -* // Create a data buffer: -* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] ); -* -* // Define the shape of the input array: -* var shape = [ 2, 2 ]; -* -* // Define the array strides: -* var sx = [ 2, 1 ]; -* -* // Define the index offset: -* var ox = 0; -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf.get( idx ); -* } -* -* // Create the input ndarray-like object: -* var x = { -* 'ref': null, -* 'dtype': 'complex64', -* 'data': xbuf, -* 'length': 4, -* 'shape': shape, -* 'strides': sx, -* 'offset': ox, -* 'order': 'row-major', -* 'getter': getter -* }; -* x.ref = x; -* -* // Compute the sum: -* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) ); -* -* var re = realf( v ); -* // returns 20.0 -* -* var im = imagf( v ); -* // returns 24.0 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var ordx; - var acc; - var len; - var get; - var ref; - var shx; - var sx; - var ox; - var ix; - var i; - - // Cache the total number of elements over which to iterate: - len = x.length; - - // Cache the input array shape: - shx = x.shape; - - // Cache reference to the input ndarray data buffer: - xbuf = x.data; - - // Cache reference to the stride array: - sx = x.strides; - - // Cache the index of the first indexed element: - ox = x.offset; - - // Cache the array order: - ordx = x.order; - - // Cache the element accessor: - get = x.getter; - - // Cache the reference to the original input array: - ref = x.ref; - - // Check for a zero-dimensional array... - if ( shx.length === 0 ) { - return reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len - } - // Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)... - acc = initial; - for ( i = len-1; i >= 0; i-- ) { - ix = vind2bind( shx, sx, ox, ordx, i, MODE ); - acc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/package.json b/package.json index 35888db..58c2ca2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.1", "description": "Perform a single-pass map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.", "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/array-base-arraylike2object": "^0.0.x", - "@stdlib/assert-is-array-like-object": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-ndarray-like": "^0.0.x", - "@stdlib/ndarray-base-ndarraylike2object": "^0.0.x", - "@stdlib/ndarray-base-vind2bind": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-base-filled": "^0.0.x", - "@stdlib/array-complex64": "^0.0.x", - "@stdlib/array-filled-by": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/complex-float32": "^0.0.x", - "@stdlib/complex-imagf": "^0.0.x", - "@stdlib/complex-realf": "^0.0.x", - "@stdlib/math-base-assert-is-nan": "^0.0.x", - "@stdlib/math-base-ops-add": "^0.0.x", - "@stdlib/math-base-ops-cadd": "^0.0.x", - "@stdlib/math-base-special-abs": "^0.0.x", - "@stdlib/math-base-special-cceil": "^0.0.x", - "@stdlib/math-base-special-pow": "^0.0.x", - "@stdlib/ndarray-array": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/random-base-discrete-uniform": "^0.0.x", - "@stdlib/utils-nary-function": "^0.0.x", - "@stdlib/utils-noop": "^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", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..bd94b70 --- /dev/null +++ b/stats.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2c78efa..0000000 --- a/test/test.js +++ /dev/null @@ -1,637 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var cadd = require( '@stdlib/math-base-ops-cadd' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var cceil = require( '@stdlib/math-base-special-cceil' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var mapReduceRight = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapReduceRight, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a first argument which is either an array-like object or an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( value, 0, noop, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value, {} ); - }; - } -}); - -tape( 'the function performs a map-reduce operation for each element in an array (array-like object)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = [ -1, -2, -3 ]; - expected = 7; - actual = mapReduceRight( arr, 1, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (typed array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - expected = 7.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (complex number array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( cceil, 1 ); - f2 = naryFunction( cadd, 2 ); - - arr = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5 ] ); - expected = new Complex64( 12.0, 15.0 ); - actual = mapReduceRight( arr, new Complex64( 0.0, 0.0 ), f1, f2 ); - - t.strictEqual( realf( actual ), realf( expected ), 'returns expected value' ); - t.strictEqual( imagf( actual ), imagf( expected ), 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = array( [ -1.0, -2.0, -3.0, -4.0 ], { - 'dtype': 'generic' - }); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray; 0-dimensional)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = ndarray( 'generic', [ -10.0 ], [], [ 0 ], 0, 'row-major' ); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (array-like object)', function test( t ) { - var out = mapReduceRight( [], 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (ndarray)', function test( t ) { - var arr; - var out; - - arr = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 0, 2 ], [ 0, 2, 1 ], 0, 'row-major' ); - out = mapReduceRight( arr, 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function supports providing a `this` context (array-like object)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = [ -1.0, -2.0, -3.0 ]; - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function supports providing a `this` context (ndarray)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = array( [ -1.0, -2.0, -3.0 ], { - 'dtype': 'generic' - }); - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = array( [ 1, , , 4 ], { // eslint-disable-line no-sparse-arrays - 'dtype': 'generic' - }); - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); From 6181b4e2517bfd495cb8db6e94a5fe552a05bb5b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 04:27:06 +0000 Subject: [PATCH 23/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index d95cde3..c890358 100644 --- a/lib/main.js +++ b/lib/main.js @@ -25,7 +25,7 @@ var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); var isFunction = require( '@stdlib/assert-is-function' ); var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ndarrayFcn = require( './ndarray.js' ); var arrayFcn = require( './array.js' ); @@ -90,10 +90,10 @@ var arrayFcn = require( './array.js' ); */ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( !isFunction( mapper ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) ); + throw new TypeError( format( '0kW3Z', mapper ) ); } if ( !isFunction( reducer ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) ); + throw new TypeError( format( '0kW3E', reducer ) ); } if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len @@ -101,7 +101,7 @@ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( isArrayLikeObject( arr ) ) { return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len } - throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) ); + throw new TypeError( format( '0kWC4', arr ) ); } diff --git a/package.json b/package.json index a522b3d..35888db 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-ndarray-like": "^0.0.x", "@stdlib/ndarray-base-ndarraylike2object": "^0.0.x", "@stdlib/ndarray-base-vind2bind": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From 61f0f7d0de2cd11b5952e697076c887d568704ba Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 16:12:41 +0000 Subject: [PATCH 24/91] Remove files --- index.d.ts | 257 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4306 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 41d747e..0000000 --- a/index.d.ts +++ /dev/null @@ -1,257 +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. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Collection } from '@stdlib/types/object'; -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* Callback invoked for each array element. -* -* @returns result -*/ -type Nullary = () => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @returns result -*/ -type Unary = ( value: any ) => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @returns result -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Ternary = ( value: any, index: number, arr: ndarray ) => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayTernary = ( value: any, index: number, arr: Collection ) => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Mapper = Nullary | Unary | Binary | Ternary; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayMapper = Nullary | Unary | Binary | ArrayTernary; - -/** -* Function applied against an accumulator. -* -* @returns accumulator value -*/ -type NullaryReducer = () => void; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @returns accumulator value -*/ -type UnaryReducer = ( accumulator: any ) => any; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @returns accumulator value -*/ -type BinaryReducer = ( accumulator: any, value: any ) => any; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @returns accumulator value -*/ -type TernaryReducer = ( accumulator: any, value: any, index: number ) => any; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type QuaternaryReducer = ( accumulator: any, value: any, index: number, arr: ndarray ) => any; // tslint:disable-line:max-line-length - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayQuaternaryReducer = ( accumulator: any, value: any, index: number, arr: Collection ) => any; // tslint:disable-line:max-line-length - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type Reducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | QuaternaryReducer; // tslint:disable-line:max-line-length - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayReducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | ArrayQuaternaryReducer; // tslint:disable-line:max-line-length - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* var naryFunction = require( `@stdlib/utils/nary-function` ); -* var abs = require( `@stdlib/math/base/special/abs` ); -* var add = require( `@stdlib/math/base/ops/add` ); -* var array = require( `@stdlib/ndarray/array` ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 2 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -declare function mapReduceRight( arr: ndarray, initial: any, mapper: Mapper, reducer: Reducer, thisArg?: any ): any; // tslint:disable-line:max-line-length - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -*/ -declare function mapReduceRight( arr: Collection, initial: any, mapper: ArrayMapper, reducer: ArrayReducer, thisArg?: any ): any; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = mapReduceRight; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5110c6b..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@esm/index.mjs";function o(o,a,m,l,j){if(!e(m))throw new TypeError(n("0kW3Z",m));if(!e(l))throw new TypeError(n("0kW3E",l));if(t(o))return function(r,t,e,s,i){var n,o,a,m,l,j,f,h,p,c,b;if(m=r.length,f=r.shape,n=r.data,h=r.strides,p=r.offset,o=r.order,l=r.getter,j=r.ref,0===f.length)return s.call(i,t,e(l(n,p),0,j),0,j);for(a=t,b=m-1;b>=0;b--)c=d(f,h,p,o,b,"throw"),a=s.call(i,a,e(l(n,c),b,j),b,j);return a}(s(o),a,m,l,j);if(r(o))return function(r,t,e,s,i){var n,d,o,a;for(n=r.data,d=r.getter,o=t,a=n.length-1;a>=0;a--)o=s.call(i,o,e(d(n,a),a,n),a,n);return o}(i(o),a,m,l,j);throw new TypeError(n("0kWC4",o))}export{o as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index a2dfcd4..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js","../lib/ndarray.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object' ;\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object' ;\nimport arraylike2object from '@stdlib/array-base-arraylike2object' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport ndarrayFcn from './ndarray.js' ;\nimport arrayFcn from './array.js' ;\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function' ;\n* import add from '@stdlib/math-base-ops-add' ;\n* import abs from '@stdlib/math-base-special-abs' ;\n* import array from '@stdlib/ndarray-array' ;\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '0kW3Z', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '0kW3E', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '0kWC4', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind' ;\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Function} x.getter - callback for accessing `x` data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64' ;\n* import Complex64 from '@stdlib/complex-float32' ;\n* import realf from '@stdlib/complex-realf' ;\n* import imagf from '@stdlib/complex-imagf' ;\n* import cceil from '@stdlib/math-base-special-cceil' ;\n* import cadd from '@stdlib/math-base-ops-cadd' ;\n* import naryFunction from '@stdlib/utils-nary-function' ;\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'getter': getter\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.getter;\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Function} x.getter - callback for accessing input array data elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'getter': getter\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.getter;\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","getter","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;4oBA0FA,SAASA,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,GAAKK,EAAeR,GACnB,OCGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,OAGRZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAtH1B,SAuHTR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,CACR,CDnDSkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OE1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,OAGRf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,CACR,CFwBSqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,QAASP,GACvC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index bd94b70..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 8b835c17cdb38e1fad766352e5634a410fe71932 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 16:13:47 +0000 Subject: [PATCH 25/91] 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 | 63 +- benchmark/benchmark.array.js | 98 - benchmark/benchmark.ndarray.js | 109 - branches.md | 53 - docs/repl.txt | 65 - docs/types/test.ts | 184 - examples/index.js | 52 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/array.js | 83 - lib/index.js | 65 - lib/main.js | 110 - lib/ndarray.js | 155 - package.json | 76 +- stats.html | 4044 +++++++++++++++++++++ test/test.js | 637 ---- 40 files changed, 4080 insertions(+), 4646 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.array.js delete mode 100644 benchmark/benchmark.ndarray.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/array.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/ndarray.js create mode 100644 stats.html delete mode 100644 test/test.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 0b50fc7..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-11-03T22:56:54.177Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3b4c7b4..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/utils/map-reduce-right) 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 bbe0806..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/utils/map-reduce-right) 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 42fe05c..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: '21 21 * * 4' - - # 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 + + ```
@@ -260,7 +253,7 @@ console.log( 'sum: %d', out ); ## 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]. @@ -320,11 +313,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/utils-map-reduce-right/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/stdlib +[@stdlib/array/complex64]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/array/complex128]: https://github.com/stdlib-js/stdlib +[@stdlib/array/complex128]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.array.js b/benchmark/benchmark.array.js deleted file mode 100644 index e87feb5..0000000 --- a/benchmark/benchmark.array.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = filled( -3.0, len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::array:len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.ndarray.js b/benchmark/benchmark.ndarray.js deleted file mode 100644 index e3bfba2..0000000 --- a/benchmark/benchmark.ndarray.js +++ /dev/null @@ -1,109 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var xbuf; - var opts; - var x; - - xbuf = filled( -3.0, len ); - - opts = { - 'dtype': 'generic' - }; - x = array( xbuf, opts ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::ndarray:len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 651bb38..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/utils/map-reduce-right" -click B href "https://github.com/stdlib-js/utils-map-reduce-right/tree/main" -click C href "https://github.com/stdlib-js/utils-map-reduce-right/tree/production" -click D href "https://github.com/stdlib-js/utils-map-reduce-right/tree/esm" -click E href "https://github.com/stdlib-js/utils-map-reduce-right/tree/deno" -click F href "https://github.com/stdlib-js/utils-map-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/map-reduce-right -[production-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b580e87..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, initial, mapper, reducer[, thisArg] ) - Performs a map-reduce operation for each element in an array while iterating - from right to left and returns the accumulated result. - - When invoked, the mapping function is provided three arguments: - - - value: array element. - - index: element index. - - arr: input array. - - When invoked, the reducing function is provided four arguments: - - - accumulator: accumulated value. - - value: result after applying the mapping function to the current array - element. - - index: element index. - - arr: input array. - - If provided an empty array, the function returns the initial value. - - When provided an ndarray, the function performs a single-pass map-reduce - operation over the entire input ndarray (i.e., higher-order ndarray - dimensions are flattened to a single-dimension). - - Parameters - ---------- - arr: ArrayLikeObject|ndarray - Input array. - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - mapper: Function - Mapping function. - - reducer: Function - Reducing function. - - thisArg: any (optional) - Execution context for the reducing function. - - Returns - ------- - out: any - Accumulated result. - - Examples - -------- - // array-like object: - > var f1 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/special/abs}}, 1 ); - > var f2 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/ops/add}}, 2 ); - > var arr = [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0 ]; - > var out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - // ndarray: - > arr = {{alias:@stdlib/ndarray/array}}( arr, { 'shape': [ 2, 3 ] } ); - > out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 76168a1..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,184 +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. -*/ - -import array = require( '@stdlib/ndarray-array' ); -import mapReduceRight = require( './index' ); - -/** -* Mapping function. -* -* @param value - array element -* @returns result -*/ -function mapper( value: number ): number { - return value; -} - -/** -* Reducing function. -* -* @param acc - accumulated value -* @param v - array element -* @returns result -*/ -function reducer( acc: number, value: number ): number { - return acc + value; -} - - -// TESTS // - -// The function returns the accumulated value when provided a collection... -{ - mapReduceRight( [ 0, 1, 1, NaN, 2 ], 0, mapper, reducer ); // $ExpectType any - mapReduceRight( [ -1, 1, 2 ], 100, mapper, reducer ); // $ExpectType any - mapReduceRight( [ -1, 1, 2 ], 0, mapper, reducer, {} ); // $ExpectType any -} - -// The function returns the accumulated value when provided an ndarray... -{ - const arr = array( [ 1, 2, 3, 4, 5, 6 ] ); - - mapReduceRight( arr, 0, mapper, reducer ); // $ExpectType any - mapReduceRight( arr, 100, mapper, reducer ); // $ExpectType any - mapReduceRight( arr, 0, mapper, reducer, {} ); // $ExpectType any -} - -// The compiler throws an error if the function is provided a first argument which is not a collection or ndarray... -{ - mapReduceRight( 2, 0, mapper, reducer ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer ); // $ExpectError - - mapReduceRight( 2, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr1, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr2, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const arr1 = [ 1, 2, 3 ]; - - mapReduceRight(); // $ExpectError - mapReduceRight( arr1 ); // $ExpectError - mapReduceRight( arr1, 0 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ); // $ExpectError - mapReduceRight( arr1, 0, mapper, reducer, {}, 3 ); // $ExpectError - - const arr2 = array( [ 1, 2, 3 ] ); - - mapReduceRight(); // $ExpectError - mapReduceRight( arr2 ); // $ExpectError - mapReduceRight( arr2, 0 ); // $ExpectError - mapReduceRight( arr2, 0, mapper ); // $ExpectError - mapReduceRight( arr2, 0, mapper, reducer, {}, 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 7474059..0000000 --- a/examples/index.js +++ /dev/null @@ -1,52 +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. -*/ - -'use strict'; - -var filledarrayBy = require( '@stdlib/array-filled-by' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ).factory; -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var mapReduceRight = require( './../lib' ); - -function fill( i ) { - var rand = discreteUniform( -10*(i+1), 10*(i+1) ); - return filledarrayBy( 10, 'generic', rand ); -} - -// Create a two-dimensional ndarray (i.e., a matrix): -var x = array( filledarrayBy( 10, 'generic', fill ), { - 'dtype': 'generic', - 'flatten': true -}); - -// Create an explicit unary function: -var f1 = naryFunction( abs, 1 ); - -// Create an explicit binary function: -var f2 = naryFunction( add, 2 ); - -// Compute the sum of absolute values: -var out = mapReduceRight( x, 0, f1, f2 ); - -console.log( 'x:' ); -console.log( x.data ); - -console.log( 'sum: %d', out ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index a2eace0..41d747e 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Collection } from '@stdlib/types/object'; import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5110c6b --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@esm/index.mjs";function o(o,a,m,l,j){if(!e(m))throw new TypeError(n("0kW3Z",m));if(!e(l))throw new TypeError(n("0kW3E",l));if(t(o))return function(r,t,e,s,i){var n,o,a,m,l,j,f,h,p,c,b;if(m=r.length,f=r.shape,n=r.data,h=r.strides,p=r.offset,o=r.order,l=r.getter,j=r.ref,0===f.length)return s.call(i,t,e(l(n,p),0,j),0,j);for(a=t,b=m-1;b>=0;b--)c=d(f,h,p,o,b,"throw"),a=s.call(i,a,e(l(n,c),b,j),b,j);return a}(s(o),a,m,l,j);if(r(o))return function(r,t,e,s,i){var n,d,o,a;for(n=r.data,d=r.getter,o=t,a=n.length-1;a>=0;a--)o=s.call(i,o,e(d(n,a),a,n),a,n);return o}(i(o),a,m,l,j);throw new TypeError(n("0kWC4",o))}export{o as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..a2dfcd4 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js","../lib/ndarray.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object' ;\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object' ;\nimport arraylike2object from '@stdlib/array-base-arraylike2object' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport ndarrayFcn from './ndarray.js' ;\nimport arrayFcn from './array.js' ;\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function' ;\n* import add from '@stdlib/math-base-ops-add' ;\n* import abs from '@stdlib/math-base-special-abs' ;\n* import array from '@stdlib/ndarray-array' ;\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '0kW3Z', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '0kW3E', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '0kWC4', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind' ;\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Function} x.getter - callback for accessing `x` data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64' ;\n* import Complex64 from '@stdlib/complex-float32' ;\n* import realf from '@stdlib/complex-realf' ;\n* import imagf from '@stdlib/complex-imagf' ;\n* import cceil from '@stdlib/math-base-special-cceil' ;\n* import cadd from '@stdlib/math-base-ops-cadd' ;\n* import naryFunction from '@stdlib/utils-nary-function' ;\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'getter': getter\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.getter;\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Function} x.getter - callback for accessing input array data elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'getter': getter\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.getter;\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","getter","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;4oBA0FA,SAASA,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,GAAKK,EAAeR,GACnB,OCGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,OAGRZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAtH1B,SAuHTR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,CACR,CDnDSkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OE1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,OAGRf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,CACR,CFwBSqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,QAASP,GACvC"} \ No newline at end of file diff --git a/lib/array.js b/lib/array.js deleted file mode 100644 index 9f87c1f..0000000 --- a/lib/array.js +++ /dev/null @@ -1,83 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input array data -* @param {ArrayLikeObject} x.data - input array data -* @param {Function} x.getter - callback for accessing input array data elements -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf[ idx ]; -* } -* -* // Create the input array object: -* var x = { -* 'data': [ 1, 2, 3, 4 ], -* 'getter': getter -* }; -* -* // Compute the sum of squared values: -* var out = mapReduceRight( x, 0, square, sum ); -* // returns 30 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var get; - var acc; - var i; - - // Cache reference to the input data: - xbuf = x.data; - - // Cache the element accessor: - get = x.getter; - - // Iterate over each element... - acc = initial; - for ( i = xbuf.length-1; i >= 0; i-- ) { - acc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 522693e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +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. -*/ - -'use strict'; - -/** -* Perform a map-reduce operation against each element in an array while iterating from right to left and return the accumulated result. -* -* @module @stdlib/utils-map-reduce-right -* -* @example -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ - -// 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 c890358..0000000 --- a/lib/main.js +++ /dev/null @@ -1,110 +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. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ndarrayFcn = require( './ndarray.js' ); -var arrayFcn = require( './array.js' ); - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided the following arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided the following arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result of applying the mapping function against the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* @param {(ArrayLikeObject|ndarray)} arr - input array -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} [thisArg] - reduction function execution context -* @throws {TypeError} first argument must be an array-like object or an ndarray -* @throws {TypeError} third argument must be a function -* @throws {TypeError} fourth argument must be a function -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { - if ( !isFunction( mapper ) ) { - throw new TypeError( format( '0kW3Z', mapper ) ); - } - if ( !isFunction( reducer ) ) { - throw new TypeError( format( '0kW3E', reducer ) ); - } - if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like - return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - if ( isArrayLikeObject( arr ) ) { - return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - throw new TypeError( format( '0kWC4', arr ) ); -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/ndarray.js b/lib/ndarray.js deleted file mode 100644 index 8b2442d..0000000 --- a/lib/ndarray.js +++ /dev/null @@ -1,155 +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. -*/ - -'use strict'; - -// MODULES // - -var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); - - -// VARIABLES // - -var MODE = 'throw'; - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input ndarray meta data -* @param {string} x.ref - reference to original input ndarray-like object -* @param {string} x.dtype - data type -* @param {Collection} x.data - data buffer -* @param {NonNegativeInteger} x.length - number of elements -* @param {NonNegativeIntegerArray} x.shape - dimensions -* @param {IntegerArray} x.strides - stride lengths -* @param {NonNegativeInteger} x.offset - index offset -* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) -* @param {Function} x.getter - callback for accessing `x` data buffer elements -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var Complex64 = require( '@stdlib/complex-float32' ); -* var realf = require( '@stdlib/complex-realf' ); -* var imagf = require( '@stdlib/complex-imagf' ); -* var cceil = require( '@stdlib/math-base-special-cceil' ); -* var cadd = require( '@stdlib/math-base-ops-cadd' ); -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* -* // Create a data buffer: -* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] ); -* -* // Define the shape of the input array: -* var shape = [ 2, 2 ]; -* -* // Define the array strides: -* var sx = [ 2, 1 ]; -* -* // Define the index offset: -* var ox = 0; -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf.get( idx ); -* } -* -* // Create the input ndarray-like object: -* var x = { -* 'ref': null, -* 'dtype': 'complex64', -* 'data': xbuf, -* 'length': 4, -* 'shape': shape, -* 'strides': sx, -* 'offset': ox, -* 'order': 'row-major', -* 'getter': getter -* }; -* x.ref = x; -* -* // Compute the sum: -* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) ); -* -* var re = realf( v ); -* // returns 20.0 -* -* var im = imagf( v ); -* // returns 24.0 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var ordx; - var acc; - var len; - var get; - var ref; - var shx; - var sx; - var ox; - var ix; - var i; - - // Cache the total number of elements over which to iterate: - len = x.length; - - // Cache the input array shape: - shx = x.shape; - - // Cache reference to the input ndarray data buffer: - xbuf = x.data; - - // Cache reference to the stride array: - sx = x.strides; - - // Cache the index of the first indexed element: - ox = x.offset; - - // Cache the array order: - ordx = x.order; - - // Cache the element accessor: - get = x.getter; - - // Cache the reference to the original input array: - ref = x.ref; - - // Check for a zero-dimensional array... - if ( shx.length === 0 ) { - return reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len - } - // Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)... - acc = initial; - for ( i = len-1; i >= 0; i-- ) { - ix = vind2bind( shx, sx, ox, ordx, i, MODE ); - acc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/package.json b/package.json index 35888db..58c2ca2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.1", "description": "Perform a single-pass map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.", "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/array-base-arraylike2object": "^0.0.x", - "@stdlib/assert-is-array-like-object": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-ndarray-like": "^0.0.x", - "@stdlib/ndarray-base-ndarraylike2object": "^0.0.x", - "@stdlib/ndarray-base-vind2bind": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-base-filled": "^0.0.x", - "@stdlib/array-complex64": "^0.0.x", - "@stdlib/array-filled-by": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/complex-float32": "^0.0.x", - "@stdlib/complex-imagf": "^0.0.x", - "@stdlib/complex-realf": "^0.0.x", - "@stdlib/math-base-assert-is-nan": "^0.0.x", - "@stdlib/math-base-ops-add": "^0.0.x", - "@stdlib/math-base-ops-cadd": "^0.0.x", - "@stdlib/math-base-special-abs": "^0.0.x", - "@stdlib/math-base-special-cceil": "^0.0.x", - "@stdlib/math-base-special-pow": "^0.0.x", - "@stdlib/ndarray-array": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/random-base-discrete-uniform": "^0.0.x", - "@stdlib/utils-nary-function": "^0.0.x", - "@stdlib/utils-noop": "^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", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..743be83 --- /dev/null +++ b/stats.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2c78efa..0000000 --- a/test/test.js +++ /dev/null @@ -1,637 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var cadd = require( '@stdlib/math-base-ops-cadd' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var cceil = require( '@stdlib/math-base-special-cceil' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var mapReduceRight = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapReduceRight, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a first argument which is either an array-like object or an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( value, 0, noop, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value, {} ); - }; - } -}); - -tape( 'the function performs a map-reduce operation for each element in an array (array-like object)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = [ -1, -2, -3 ]; - expected = 7; - actual = mapReduceRight( arr, 1, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (typed array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - expected = 7.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (complex number array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( cceil, 1 ); - f2 = naryFunction( cadd, 2 ); - - arr = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5 ] ); - expected = new Complex64( 12.0, 15.0 ); - actual = mapReduceRight( arr, new Complex64( 0.0, 0.0 ), f1, f2 ); - - t.strictEqual( realf( actual ), realf( expected ), 'returns expected value' ); - t.strictEqual( imagf( actual ), imagf( expected ), 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = array( [ -1.0, -2.0, -3.0, -4.0 ], { - 'dtype': 'generic' - }); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray; 0-dimensional)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = ndarray( 'generic', [ -10.0 ], [], [ 0 ], 0, 'row-major' ); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (array-like object)', function test( t ) { - var out = mapReduceRight( [], 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (ndarray)', function test( t ) { - var arr; - var out; - - arr = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 0, 2 ], [ 0, 2, 1 ], 0, 'row-major' ); - out = mapReduceRight( arr, 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function supports providing a `this` context (array-like object)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = [ -1.0, -2.0, -3.0 ]; - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function supports providing a `this` context (ndarray)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = array( [ -1.0, -2.0, -3.0 ], { - 'dtype': 'generic' - }); - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = array( [ 1, , , 4 ], { // eslint-disable-line no-sparse-arrays - 'dtype': 'generic' - }); - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); From 19479fe70f654a62b0a5af978ec3fe2d242e52c6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 04:39:16 +0000 Subject: [PATCH 26/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index d95cde3..c890358 100644 --- a/lib/main.js +++ b/lib/main.js @@ -25,7 +25,7 @@ var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); var isFunction = require( '@stdlib/assert-is-function' ); var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ndarrayFcn = require( './ndarray.js' ); var arrayFcn = require( './array.js' ); @@ -90,10 +90,10 @@ var arrayFcn = require( './array.js' ); */ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( !isFunction( mapper ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) ); + throw new TypeError( format( '0kW3Z', mapper ) ); } if ( !isFunction( reducer ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) ); + throw new TypeError( format( '0kW3E', reducer ) ); } if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len @@ -101,7 +101,7 @@ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( isArrayLikeObject( arr ) ) { return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len } - throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) ); + throw new TypeError( format( '0kWC4', arr ) ); } diff --git a/package.json b/package.json index b0040e2..f9e0f6f 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-ndarray-like": "^0.0.x", "@stdlib/ndarray-base-ndarraylike2object": "^0.0.x", "@stdlib/ndarray-base-vind2bind": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From 0dddd11ecfe424a5ec20b8c73e64abe22d317b92 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 15:41:52 +0000 Subject: [PATCH 27/91] Remove files --- index.d.ts | 257 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4306 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 41d747e..0000000 --- a/index.d.ts +++ /dev/null @@ -1,257 +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. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Collection } from '@stdlib/types/object'; -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* Callback invoked for each array element. -* -* @returns result -*/ -type Nullary = () => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @returns result -*/ -type Unary = ( value: any ) => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @returns result -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Ternary = ( value: any, index: number, arr: ndarray ) => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayTernary = ( value: any, index: number, arr: Collection ) => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Mapper = Nullary | Unary | Binary | Ternary; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayMapper = Nullary | Unary | Binary | ArrayTernary; - -/** -* Function applied against an accumulator. -* -* @returns accumulator value -*/ -type NullaryReducer = () => void; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @returns accumulator value -*/ -type UnaryReducer = ( accumulator: any ) => any; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @returns accumulator value -*/ -type BinaryReducer = ( accumulator: any, value: any ) => any; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @returns accumulator value -*/ -type TernaryReducer = ( accumulator: any, value: any, index: number ) => any; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type QuaternaryReducer = ( accumulator: any, value: any, index: number, arr: ndarray ) => any; // tslint:disable-line:max-line-length - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayQuaternaryReducer = ( accumulator: any, value: any, index: number, arr: Collection ) => any; // tslint:disable-line:max-line-length - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type Reducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | QuaternaryReducer; // tslint:disable-line:max-line-length - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayReducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | ArrayQuaternaryReducer; // tslint:disable-line:max-line-length - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* var naryFunction = require( `@stdlib/utils/nary-function` ); -* var abs = require( `@stdlib/math/base/special/abs` ); -* var add = require( `@stdlib/math/base/ops/add` ); -* var array = require( `@stdlib/ndarray/array` ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 2 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -declare function mapReduceRight( arr: ndarray, initial: any, mapper: Mapper, reducer: Reducer, thisArg?: any ): any; // tslint:disable-line:max-line-length - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -*/ -declare function mapReduceRight( arr: Collection, initial: any, mapper: ArrayMapper, reducer: ArrayReducer, thisArg?: any ): any; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = mapReduceRight; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5110c6b..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@esm/index.mjs";function o(o,a,m,l,j){if(!e(m))throw new TypeError(n("0kW3Z",m));if(!e(l))throw new TypeError(n("0kW3E",l));if(t(o))return function(r,t,e,s,i){var n,o,a,m,l,j,f,h,p,c,b;if(m=r.length,f=r.shape,n=r.data,h=r.strides,p=r.offset,o=r.order,l=r.getter,j=r.ref,0===f.length)return s.call(i,t,e(l(n,p),0,j),0,j);for(a=t,b=m-1;b>=0;b--)c=d(f,h,p,o,b,"throw"),a=s.call(i,a,e(l(n,c),b,j),b,j);return a}(s(o),a,m,l,j);if(r(o))return function(r,t,e,s,i){var n,d,o,a;for(n=r.data,d=r.getter,o=t,a=n.length-1;a>=0;a--)o=s.call(i,o,e(d(n,a),a,n),a,n);return o}(i(o),a,m,l,j);throw new TypeError(n("0kWC4",o))}export{o as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index a2dfcd4..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js","../lib/ndarray.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object' ;\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like' ;\nimport isFunction from '@stdlib/assert-is-function' ;\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object' ;\nimport arraylike2object from '@stdlib/array-base-arraylike2object' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport ndarrayFcn from './ndarray.js' ;\nimport arrayFcn from './array.js' ;\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function' ;\n* import add from '@stdlib/math-base-ops-add' ;\n* import abs from '@stdlib/math-base-special-abs' ;\n* import array from '@stdlib/ndarray-array' ;\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '0kW3Z', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '0kW3E', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '0kWC4', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind' ;\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Function} x.getter - callback for accessing `x` data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64' ;\n* import Complex64 from '@stdlib/complex-float32' ;\n* import realf from '@stdlib/complex-realf' ;\n* import imagf from '@stdlib/complex-imagf' ;\n* import cceil from '@stdlib/math-base-special-cceil' ;\n* import cadd from '@stdlib/math-base-ops-cadd' ;\n* import naryFunction from '@stdlib/utils-nary-function' ;\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'getter': getter\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.getter;\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Function} x.getter - callback for accessing input array data elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'getter': getter\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.getter;\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","getter","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;4oBA0FA,SAASA,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,GAAKK,EAAeR,GACnB,OCGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,OAGRZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAtH1B,SAuHTR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,CACR,CDnDSkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OE1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,OAGRf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,CACR,CFwBSqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,QAASP,GACvC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 743be83..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 728d6cac1ca0c604099529702dbb6cf8a6197d4f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 15:43:00 +0000 Subject: [PATCH 28/91] 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 | 63 +- benchmark/benchmark.array.js | 98 - benchmark/benchmark.ndarray.js | 109 - branches.md | 53 - docs/repl.txt | 65 - docs/types/test.ts | 184 - examples/index.js | 52 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/array.js | 83 - lib/index.js | 65 - lib/main.js | 110 - lib/ndarray.js | 155 - package.json | 76 +- stats.html | 4044 +++++++++++++++++++++ test/test.js | 637 ---- 40 files changed, 4080 insertions(+), 4651 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.array.js delete mode 100644 benchmark/benchmark.ndarray.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/array.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/ndarray.js create mode 100644 stats.html delete mode 100644 test/test.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 aba487a..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-12-01T02:45:35.749Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3b4c7b4..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/utils/map-reduce-right) 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 bbe0806..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/utils/map-reduce-right) 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 42fe05c..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: '21 21 * * 4' - - # 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 + + ```
@@ -260,7 +253,7 @@ console.log( 'sum: %d', out ); ## 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]. @@ -320,11 +313,11 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/utils-map-reduce-right/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/stdlib +[@stdlib/array/complex64]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/array/complex128]: https://github.com/stdlib-js/stdlib +[@stdlib/array/complex128]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.array.js b/benchmark/benchmark.array.js deleted file mode 100644 index e87feb5..0000000 --- a/benchmark/benchmark.array.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = filled( -3.0, len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::array:len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.ndarray.js b/benchmark/benchmark.ndarray.js deleted file mode 100644 index e3bfba2..0000000 --- a/benchmark/benchmark.ndarray.js +++ /dev/null @@ -1,109 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var xbuf; - var opts; - var x; - - xbuf = filled( -3.0, len ); - - opts = { - 'dtype': 'generic' - }; - x = array( xbuf, opts ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::ndarray:len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 651bb38..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/utils/map-reduce-right" -click B href "https://github.com/stdlib-js/utils-map-reduce-right/tree/main" -click C href "https://github.com/stdlib-js/utils-map-reduce-right/tree/production" -click D href "https://github.com/stdlib-js/utils-map-reduce-right/tree/esm" -click E href "https://github.com/stdlib-js/utils-map-reduce-right/tree/deno" -click F href "https://github.com/stdlib-js/utils-map-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/map-reduce-right -[production-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b580e87..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, initial, mapper, reducer[, thisArg] ) - Performs a map-reduce operation for each element in an array while iterating - from right to left and returns the accumulated result. - - When invoked, the mapping function is provided three arguments: - - - value: array element. - - index: element index. - - arr: input array. - - When invoked, the reducing function is provided four arguments: - - - accumulator: accumulated value. - - value: result after applying the mapping function to the current array - element. - - index: element index. - - arr: input array. - - If provided an empty array, the function returns the initial value. - - When provided an ndarray, the function performs a single-pass map-reduce - operation over the entire input ndarray (i.e., higher-order ndarray - dimensions are flattened to a single-dimension). - - Parameters - ---------- - arr: ArrayLikeObject|ndarray - Input array. - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - mapper: Function - Mapping function. - - reducer: Function - Reducing function. - - thisArg: any (optional) - Execution context for the reducing function. - - Returns - ------- - out: any - Accumulated result. - - Examples - -------- - // array-like object: - > var f1 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/special/abs}}, 1 ); - > var f2 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/ops/add}}, 2 ); - > var arr = [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0 ]; - > var out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - // ndarray: - > arr = {{alias:@stdlib/ndarray/array}}( arr, { 'shape': [ 2, 3 ] } ); - > out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 76168a1..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,184 +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. -*/ - -import array = require( '@stdlib/ndarray-array' ); -import mapReduceRight = require( './index' ); - -/** -* Mapping function. -* -* @param value - array element -* @returns result -*/ -function mapper( value: number ): number { - return value; -} - -/** -* Reducing function. -* -* @param acc - accumulated value -* @param v - array element -* @returns result -*/ -function reducer( acc: number, value: number ): number { - return acc + value; -} - - -// TESTS // - -// The function returns the accumulated value when provided a collection... -{ - mapReduceRight( [ 0, 1, 1, NaN, 2 ], 0, mapper, reducer ); // $ExpectType any - mapReduceRight( [ -1, 1, 2 ], 100, mapper, reducer ); // $ExpectType any - mapReduceRight( [ -1, 1, 2 ], 0, mapper, reducer, {} ); // $ExpectType any -} - -// The function returns the accumulated value when provided an ndarray... -{ - const arr = array( [ 1, 2, 3, 4, 5, 6 ] ); - - mapReduceRight( arr, 0, mapper, reducer ); // $ExpectType any - mapReduceRight( arr, 100, mapper, reducer ); // $ExpectType any - mapReduceRight( arr, 0, mapper, reducer, {} ); // $ExpectType any -} - -// The compiler throws an error if the function is provided a first argument which is not a collection or ndarray... -{ - mapReduceRight( 2, 0, mapper, reducer ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer ); // $ExpectError - - mapReduceRight( 2, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr1, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr2, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const arr1 = [ 1, 2, 3 ]; - - mapReduceRight(); // $ExpectError - mapReduceRight( arr1 ); // $ExpectError - mapReduceRight( arr1, 0 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ); // $ExpectError - mapReduceRight( arr1, 0, mapper, reducer, {}, 3 ); // $ExpectError - - const arr2 = array( [ 1, 2, 3 ] ); - - mapReduceRight(); // $ExpectError - mapReduceRight( arr2 ); // $ExpectError - mapReduceRight( arr2, 0 ); // $ExpectError - mapReduceRight( arr2, 0, mapper ); // $ExpectError - mapReduceRight( arr2, 0, mapper, reducer, {}, 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 7474059..0000000 --- a/examples/index.js +++ /dev/null @@ -1,52 +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. -*/ - -'use strict'; - -var filledarrayBy = require( '@stdlib/array-filled-by' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ).factory; -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var mapReduceRight = require( './../lib' ); - -function fill( i ) { - var rand = discreteUniform( -10*(i+1), 10*(i+1) ); - return filledarrayBy( 10, 'generic', rand ); -} - -// Create a two-dimensional ndarray (i.e., a matrix): -var x = array( filledarrayBy( 10, 'generic', fill ), { - 'dtype': 'generic', - 'flatten': true -}); - -// Create an explicit unary function: -var f1 = naryFunction( abs, 1 ); - -// Create an explicit binary function: -var f2 = naryFunction( add, 2 ); - -// Compute the sum of absolute values: -var out = mapReduceRight( x, 0, f1, f2 ); - -console.log( 'x:' ); -console.log( x.data ); - -console.log( 'sum: %d', out ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index a2eace0..41d747e 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Collection } from '@stdlib/types/object'; import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..5110c6b --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@esm/index.mjs";function o(o,a,m,l,j){if(!e(m))throw new TypeError(n("0kW3Z",m));if(!e(l))throw new TypeError(n("0kW3E",l));if(t(o))return function(r,t,e,s,i){var n,o,a,m,l,j,f,h,p,c,b;if(m=r.length,f=r.shape,n=r.data,h=r.strides,p=r.offset,o=r.order,l=r.getter,j=r.ref,0===f.length)return s.call(i,t,e(l(n,p),0,j),0,j);for(a=t,b=m-1;b>=0;b--)c=d(f,h,p,o,b,"throw"),a=s.call(i,a,e(l(n,c),b,j),b,j);return a}(s(o),a,m,l,j);if(r(o))return function(r,t,e,s,i){var n,d,o,a;for(n=r.data,d=r.getter,o=t,a=n.length-1;a>=0;a--)o=s.call(i,o,e(d(n,a),a,n),a,n);return o}(i(o),a,m,l,j);throw new TypeError(n("0kWC4",o))}export{o as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..854086d --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js","../lib/ndarray.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isFunction from '@stdlib/assert-is-function';\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object';\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndarrayFcn from './ndarray.js';\nimport arrayFcn from './array.js';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function';\n* import add from '@stdlib/math-base-ops-add';\n* import abs from '@stdlib/math-base-special-abs';\n* import array from '@stdlib/ndarray-array';\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '0kW3Z', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '0kW3E', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '0kWC4', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind';\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Function} x.getter - callback for accessing `x` data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64';\n* import Complex64 from '@stdlib/complex-float32';\n* import realf from '@stdlib/complex-realf';\n* import imagf from '@stdlib/complex-imagf';\n* import cceil from '@stdlib/math-base-special-cceil';\n* import cadd from '@stdlib/math-base-ops-cadd';\n* import naryFunction from '@stdlib/utils-nary-function';\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'getter': getter\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.getter;\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Function} x.getter - callback for accessing input array data elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'getter': getter\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.getter;\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","getter","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;4oBA0FA,SAASA,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,GAAKK,EAAeR,GACnB,OCGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,OAGRZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAtH1B,SAuHTR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,CACR,CDnDSkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OE1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,OAGRf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,CACR,CFwBSqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,QAASP,GACvC"} \ No newline at end of file diff --git a/lib/array.js b/lib/array.js deleted file mode 100644 index 9f87c1f..0000000 --- a/lib/array.js +++ /dev/null @@ -1,83 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input array data -* @param {ArrayLikeObject} x.data - input array data -* @param {Function} x.getter - callback for accessing input array data elements -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf[ idx ]; -* } -* -* // Create the input array object: -* var x = { -* 'data': [ 1, 2, 3, 4 ], -* 'getter': getter -* }; -* -* // Compute the sum of squared values: -* var out = mapReduceRight( x, 0, square, sum ); -* // returns 30 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var get; - var acc; - var i; - - // Cache reference to the input data: - xbuf = x.data; - - // Cache the element accessor: - get = x.getter; - - // Iterate over each element... - acc = initial; - for ( i = xbuf.length-1; i >= 0; i-- ) { - acc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 522693e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +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. -*/ - -'use strict'; - -/** -* Perform a map-reduce operation against each element in an array while iterating from right to left and return the accumulated result. -* -* @module @stdlib/utils-map-reduce-right -* -* @example -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ - -// 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 c890358..0000000 --- a/lib/main.js +++ /dev/null @@ -1,110 +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. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ndarrayFcn = require( './ndarray.js' ); -var arrayFcn = require( './array.js' ); - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided the following arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided the following arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result of applying the mapping function against the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* @param {(ArrayLikeObject|ndarray)} arr - input array -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} [thisArg] - reduction function execution context -* @throws {TypeError} first argument must be an array-like object or an ndarray -* @throws {TypeError} third argument must be a function -* @throws {TypeError} fourth argument must be a function -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { - if ( !isFunction( mapper ) ) { - throw new TypeError( format( '0kW3Z', mapper ) ); - } - if ( !isFunction( reducer ) ) { - throw new TypeError( format( '0kW3E', reducer ) ); - } - if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like - return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - if ( isArrayLikeObject( arr ) ) { - return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - throw new TypeError( format( '0kWC4', arr ) ); -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/ndarray.js b/lib/ndarray.js deleted file mode 100644 index 8b2442d..0000000 --- a/lib/ndarray.js +++ /dev/null @@ -1,155 +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. -*/ - -'use strict'; - -// MODULES // - -var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); - - -// VARIABLES // - -var MODE = 'throw'; - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input ndarray meta data -* @param {string} x.ref - reference to original input ndarray-like object -* @param {string} x.dtype - data type -* @param {Collection} x.data - data buffer -* @param {NonNegativeInteger} x.length - number of elements -* @param {NonNegativeIntegerArray} x.shape - dimensions -* @param {IntegerArray} x.strides - stride lengths -* @param {NonNegativeInteger} x.offset - index offset -* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) -* @param {Function} x.getter - callback for accessing `x` data buffer elements -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var Complex64 = require( '@stdlib/complex-float32' ); -* var realf = require( '@stdlib/complex-realf' ); -* var imagf = require( '@stdlib/complex-imagf' ); -* var cceil = require( '@stdlib/math-base-special-cceil' ); -* var cadd = require( '@stdlib/math-base-ops-cadd' ); -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* -* // Create a data buffer: -* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] ); -* -* // Define the shape of the input array: -* var shape = [ 2, 2 ]; -* -* // Define the array strides: -* var sx = [ 2, 1 ]; -* -* // Define the index offset: -* var ox = 0; -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf.get( idx ); -* } -* -* // Create the input ndarray-like object: -* var x = { -* 'ref': null, -* 'dtype': 'complex64', -* 'data': xbuf, -* 'length': 4, -* 'shape': shape, -* 'strides': sx, -* 'offset': ox, -* 'order': 'row-major', -* 'getter': getter -* }; -* x.ref = x; -* -* // Compute the sum: -* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) ); -* -* var re = realf( v ); -* // returns 20.0 -* -* var im = imagf( v ); -* // returns 24.0 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var ordx; - var acc; - var len; - var get; - var ref; - var shx; - var sx; - var ox; - var ix; - var i; - - // Cache the total number of elements over which to iterate: - len = x.length; - - // Cache the input array shape: - shx = x.shape; - - // Cache reference to the input ndarray data buffer: - xbuf = x.data; - - // Cache reference to the stride array: - sx = x.strides; - - // Cache the index of the first indexed element: - ox = x.offset; - - // Cache the array order: - ordx = x.order; - - // Cache the element accessor: - get = x.getter; - - // Cache the reference to the original input array: - ref = x.ref; - - // Check for a zero-dimensional array... - if ( shx.length === 0 ) { - return reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len - } - // Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)... - acc = initial; - for ( i = len-1; i >= 0; i-- ) { - ix = vind2bind( shx, sx, ox, ordx, i, MODE ); - acc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/package.json b/package.json index f9e0f6f..58c2ca2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.1", "description": "Perform a single-pass map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.", "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/array-base-arraylike2object": "^0.0.x", - "@stdlib/assert-is-array-like-object": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-ndarray-like": "^0.0.x", - "@stdlib/ndarray-base-ndarraylike2object": "^0.0.x", - "@stdlib/ndarray-base-vind2bind": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-base-filled": "^0.0.x", - "@stdlib/array-complex64": "^0.0.x", - "@stdlib/array-filled-by": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/complex-float32": "^0.0.x", - "@stdlib/complex-imagf": "^0.0.x", - "@stdlib/complex-realf": "^0.0.x", - "@stdlib/math-base-assert-is-nan": "^0.0.x", - "@stdlib/math-base-ops-add": "^0.0.x", - "@stdlib/math-base-ops-cadd": "^0.0.x", - "@stdlib/math-base-special-abs": "^0.0.x", - "@stdlib/math-base-special-cceil": "^0.0.x", - "@stdlib/math-base-special-pow": "^0.0.x", - "@stdlib/ndarray-array": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/random-base-discrete-uniform": "^0.0.x", - "@stdlib/utils-nary-function": "^0.0.x", - "@stdlib/utils-noop": "^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", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..4a1d3a7 --- /dev/null +++ b/stats.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2c78efa..0000000 --- a/test/test.js +++ /dev/null @@ -1,637 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var cadd = require( '@stdlib/math-base-ops-cadd' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var cceil = require( '@stdlib/math-base-special-cceil' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var mapReduceRight = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapReduceRight, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a first argument which is either an array-like object or an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( value, 0, noop, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value, {} ); - }; - } -}); - -tape( 'the function performs a map-reduce operation for each element in an array (array-like object)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = [ -1, -2, -3 ]; - expected = 7; - actual = mapReduceRight( arr, 1, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (typed array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - expected = 7.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (complex number array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( cceil, 1 ); - f2 = naryFunction( cadd, 2 ); - - arr = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5 ] ); - expected = new Complex64( 12.0, 15.0 ); - actual = mapReduceRight( arr, new Complex64( 0.0, 0.0 ), f1, f2 ); - - t.strictEqual( realf( actual ), realf( expected ), 'returns expected value' ); - t.strictEqual( imagf( actual ), imagf( expected ), 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = array( [ -1.0, -2.0, -3.0, -4.0 ], { - 'dtype': 'generic' - }); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray; 0-dimensional)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = ndarray( 'generic', [ -10.0 ], [], [ 0 ], 0, 'row-major' ); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (array-like object)', function test( t ) { - var out = mapReduceRight( [], 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (ndarray)', function test( t ) { - var arr; - var out; - - arr = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 0, 2 ], [ 0, 2, 1 ], 0, 'row-major' ); - out = mapReduceRight( arr, 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function supports providing a `this` context (array-like object)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = [ -1.0, -2.0, -3.0 ]; - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function supports providing a `this` context (ndarray)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = array( [ -1.0, -2.0, -3.0 ], { - 'dtype': 'generic' - }); - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = array( [ 1, , , 4 ], { // eslint-disable-line no-sparse-arrays - 'dtype': 'generic' - }); - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); From d361f0a4cdeaa300901717b3f7ec81a36aa2397b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 04:16:44 +0000 Subject: [PATCH 29/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index d95cde3..c890358 100644 --- a/lib/main.js +++ b/lib/main.js @@ -25,7 +25,7 @@ var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); var isFunction = require( '@stdlib/assert-is-function' ); var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ndarrayFcn = require( './ndarray.js' ); var arrayFcn = require( './array.js' ); @@ -90,10 +90,10 @@ var arrayFcn = require( './array.js' ); */ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( !isFunction( mapper ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) ); + throw new TypeError( format( '0kW3Z', mapper ) ); } if ( !isFunction( reducer ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) ); + throw new TypeError( format( '0kW3E', reducer ) ); } if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len @@ -101,7 +101,7 @@ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( isArrayLikeObject( arr ) ) { return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len } - throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) ); + throw new TypeError( format( '0kWC4', arr ) ); } diff --git a/package.json b/package.json index ccb78c8..62211f4 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-ndarray-like": "^0.0.x", "@stdlib/ndarray-base-ndarraylike2object": "^0.0.x", "@stdlib/ndarray-base-vind2bind": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x" }, "devDependencies": { From f7ba22fd3aa0df015cc60269b2be77d8a3b32f9e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 13:08:52 +0000 Subject: [PATCH 30/91] Remove files --- index.d.ts | 257 ---- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4306 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 41d747e..0000000 --- a/index.d.ts +++ /dev/null @@ -1,257 +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. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Collection } from '@stdlib/types/object'; -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* Callback invoked for each array element. -* -* @returns result -*/ -type Nullary = () => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @returns result -*/ -type Unary = ( value: any ) => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @returns result -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Ternary = ( value: any, index: number, arr: ndarray ) => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayTernary = ( value: any, index: number, arr: Collection ) => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Mapper = Nullary | Unary | Binary | Ternary; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayMapper = Nullary | Unary | Binary | ArrayTernary; - -/** -* Function applied against an accumulator. -* -* @returns accumulator value -*/ -type NullaryReducer = () => void; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @returns accumulator value -*/ -type UnaryReducer = ( accumulator: any ) => any; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @returns accumulator value -*/ -type BinaryReducer = ( accumulator: any, value: any ) => any; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @returns accumulator value -*/ -type TernaryReducer = ( accumulator: any, value: any, index: number ) => any; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type QuaternaryReducer = ( accumulator: any, value: any, index: number, arr: ndarray ) => any; // tslint:disable-line:max-line-length - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayQuaternaryReducer = ( accumulator: any, value: any, index: number, arr: Collection ) => any; // tslint:disable-line:max-line-length - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type Reducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | QuaternaryReducer; // tslint:disable-line:max-line-length - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayReducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | ArrayQuaternaryReducer; // tslint:disable-line:max-line-length - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* var naryFunction = require( `@stdlib/utils/nary-function` ); -* var abs = require( `@stdlib/math/base/special/abs` ); -* var add = require( `@stdlib/math/base/ops/add` ); -* var array = require( `@stdlib/ndarray/array` ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 2 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -declare function mapReduceRight( arr: ndarray, initial: any, mapper: Mapper, reducer: Reducer, thisArg?: any ): any; // tslint:disable-line:max-line-length - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -*/ -declare function mapReduceRight( arr: Collection, initial: any, mapper: ArrayMapper, reducer: ArrayReducer, thisArg?: any ): any; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = mapReduceRight; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 5110c6b..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@esm/index.mjs";function o(o,a,m,l,j){if(!e(m))throw new TypeError(n("0kW3Z",m));if(!e(l))throw new TypeError(n("0kW3E",l));if(t(o))return function(r,t,e,s,i){var n,o,a,m,l,j,f,h,p,c,b;if(m=r.length,f=r.shape,n=r.data,h=r.strides,p=r.offset,o=r.order,l=r.getter,j=r.ref,0===f.length)return s.call(i,t,e(l(n,p),0,j),0,j);for(a=t,b=m-1;b>=0;b--)c=d(f,h,p,o,b,"throw"),a=s.call(i,a,e(l(n,c),b,j),b,j);return a}(s(o),a,m,l,j);if(r(o))return function(r,t,e,s,i){var n,d,o,a;for(n=r.data,d=r.getter,o=t,a=n.length-1;a>=0;a--)o=s.call(i,o,e(d(n,a),a,n),a,n);return o}(i(o),a,m,l,j);throw new TypeError(n("0kWC4",o))}export{o as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 854086d..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js","../lib/ndarray.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isFunction from '@stdlib/assert-is-function';\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object';\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndarrayFcn from './ndarray.js';\nimport arrayFcn from './array.js';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function';\n* import add from '@stdlib/math-base-ops-add';\n* import abs from '@stdlib/math-base-special-abs';\n* import array from '@stdlib/ndarray-array';\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '0kW3Z', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '0kW3E', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '0kWC4', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind';\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Function} x.getter - callback for accessing `x` data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64';\n* import Complex64 from '@stdlib/complex-float32';\n* import realf from '@stdlib/complex-realf';\n* import imagf from '@stdlib/complex-imagf';\n* import cceil from '@stdlib/math-base-special-cceil';\n* import cadd from '@stdlib/math-base-ops-cadd';\n* import naryFunction from '@stdlib/utils-nary-function';\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'getter': getter\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.getter;\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Function} x.getter - callback for accessing input array data elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'getter': getter\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.getter;\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","getter","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;4oBA0FA,SAASA,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,GAAKK,EAAeR,GACnB,OCGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,OAGRZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAtH1B,SAuHTR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,CACR,CDnDSkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OE1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,OAGRf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,CACR,CFwBSqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,QAASP,GACvC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 4a1d3a7..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 35886bcda95e2048a65ff36fa79c2977a3287ff1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 13:09:48 +0000 Subject: [PATCH 31/91] 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 | 63 +- benchmark/benchmark.array.js | 98 - benchmark/benchmark.ndarray.js | 109 - branches.md | 53 - docs/repl.txt | 65 - docs/types/test.ts | 184 - examples/index.js | 52 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/array.js | 83 - lib/index.js | 65 - lib/main.js | 110 - lib/ndarray.js | 155 - package.json | 76 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 637 --- 40 files changed, 6213 insertions(+), 4662 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.array.js delete mode 100644 benchmark/benchmark.ndarray.js delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/array.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/ndarray.js create mode 100644 stats.html delete mode 100644 test/test.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 1c55e7f..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-02-01T02:34:52.760Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3b4c7b4..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/utils/map-reduce-right) 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 bbe0806..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/utils/map-reduce-right) 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 42fe05c..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: '21 21 * * 4' - - # 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 + + ```
@@ -260,7 +253,7 @@ console.log( 'sum: %d', out ); ## 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]. @@ -320,11 +313,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/utils-map-reduce-right/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/stdlib +[@stdlib/array/complex64]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/array/complex128]: https://github.com/stdlib-js/stdlib +[@stdlib/array/complex128]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.array.js b/benchmark/benchmark.array.js deleted file mode 100644 index e87feb5..0000000 --- a/benchmark/benchmark.array.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = filled( -3.0, len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::array:len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.ndarray.js b/benchmark/benchmark.ndarray.js deleted file mode 100644 index e3bfba2..0000000 --- a/benchmark/benchmark.ndarray.js +++ /dev/null @@ -1,109 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var xbuf; - var opts; - var x; - - xbuf = filled( -3.0, len ); - - opts = { - 'dtype': 'generic' - }; - x = array( xbuf, opts ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::ndarray:len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 651bb38..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/utils/map-reduce-right" -click B href "https://github.com/stdlib-js/utils-map-reduce-right/tree/main" -click C href "https://github.com/stdlib-js/utils-map-reduce-right/tree/production" -click D href "https://github.com/stdlib-js/utils-map-reduce-right/tree/esm" -click E href "https://github.com/stdlib-js/utils-map-reduce-right/tree/deno" -click F href "https://github.com/stdlib-js/utils-map-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/map-reduce-right -[production-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b580e87..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, initial, mapper, reducer[, thisArg] ) - Performs a map-reduce operation for each element in an array while iterating - from right to left and returns the accumulated result. - - When invoked, the mapping function is provided three arguments: - - - value: array element. - - index: element index. - - arr: input array. - - When invoked, the reducing function is provided four arguments: - - - accumulator: accumulated value. - - value: result after applying the mapping function to the current array - element. - - index: element index. - - arr: input array. - - If provided an empty array, the function returns the initial value. - - When provided an ndarray, the function performs a single-pass map-reduce - operation over the entire input ndarray (i.e., higher-order ndarray - dimensions are flattened to a single-dimension). - - Parameters - ---------- - arr: ArrayLikeObject|ndarray - Input array. - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - mapper: Function - Mapping function. - - reducer: Function - Reducing function. - - thisArg: any (optional) - Execution context for the reducing function. - - Returns - ------- - out: any - Accumulated result. - - Examples - -------- - // array-like object: - > var f1 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/special/abs}}, 1 ); - > var f2 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/ops/add}}, 2 ); - > var arr = [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0 ]; - > var out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - // ndarray: - > arr = {{alias:@stdlib/ndarray/array}}( arr, { 'shape': [ 2, 3 ] } ); - > out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 76168a1..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,184 +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. -*/ - -import array = require( '@stdlib/ndarray-array' ); -import mapReduceRight = require( './index' ); - -/** -* Mapping function. -* -* @param value - array element -* @returns result -*/ -function mapper( value: number ): number { - return value; -} - -/** -* Reducing function. -* -* @param acc - accumulated value -* @param v - array element -* @returns result -*/ -function reducer( acc: number, value: number ): number { - return acc + value; -} - - -// TESTS // - -// The function returns the accumulated value when provided a collection... -{ - mapReduceRight( [ 0, 1, 1, NaN, 2 ], 0, mapper, reducer ); // $ExpectType any - mapReduceRight( [ -1, 1, 2 ], 100, mapper, reducer ); // $ExpectType any - mapReduceRight( [ -1, 1, 2 ], 0, mapper, reducer, {} ); // $ExpectType any -} - -// The function returns the accumulated value when provided an ndarray... -{ - const arr = array( [ 1, 2, 3, 4, 5, 6 ] ); - - mapReduceRight( arr, 0, mapper, reducer ); // $ExpectType any - mapReduceRight( arr, 100, mapper, reducer ); // $ExpectType any - mapReduceRight( arr, 0, mapper, reducer, {} ); // $ExpectType any -} - -// The compiler throws an error if the function is provided a first argument which is not a collection or ndarray... -{ - mapReduceRight( 2, 0, mapper, reducer ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer ); // $ExpectError - - mapReduceRight( 2, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr1, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr2, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const arr1 = [ 1, 2, 3 ]; - - mapReduceRight(); // $ExpectError - mapReduceRight( arr1 ); // $ExpectError - mapReduceRight( arr1, 0 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ); // $ExpectError - mapReduceRight( arr1, 0, mapper, reducer, {}, 3 ); // $ExpectError - - const arr2 = array( [ 1, 2, 3 ] ); - - mapReduceRight(); // $ExpectError - mapReduceRight( arr2 ); // $ExpectError - mapReduceRight( arr2, 0 ); // $ExpectError - mapReduceRight( arr2, 0, mapper ); // $ExpectError - mapReduceRight( arr2, 0, mapper, reducer, {}, 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 7474059..0000000 --- a/examples/index.js +++ /dev/null @@ -1,52 +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. -*/ - -'use strict'; - -var filledarrayBy = require( '@stdlib/array-filled-by' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ).factory; -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var mapReduceRight = require( './../lib' ); - -function fill( i ) { - var rand = discreteUniform( -10*(i+1), 10*(i+1) ); - return filledarrayBy( 10, 'generic', rand ); -} - -// Create a two-dimensional ndarray (i.e., a matrix): -var x = array( filledarrayBy( 10, 'generic', fill ), { - 'dtype': 'generic', - 'flatten': true -}); - -// Create an explicit unary function: -var f1 = naryFunction( abs, 1 ); - -// Create an explicit binary function: -var f2 = naryFunction( add, 2 ); - -// Compute the sum of absolute values: -var out = mapReduceRight( x, 0, f1, f2 ); - -console.log( 'x:' ); -console.log( x.data ); - -console.log( 'sum: %d', out ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index a2eace0..41d747e 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { Collection } from '@stdlib/types/object'; import { ndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..7ec13a9 --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@esm/index.mjs";function o(o,a,m,l,j){if(!e(m))throw new TypeError(n("0kW3Z",m));if(!e(l))throw new TypeError(n("0kW3E",l));if(s(o))return function(r,s,e,t,i){var n,o,a,m,l,j,f,h,c,p,b;if(m=r.length,f=r.shape,n=r.data,h=r.strides,c=r.offset,o=r.order,l=r.accessors[0],j=r.ref,0===f.length)return t.call(i,s,e(l(n,c),0,j),0,j);for(a=s,b=m-1;b>=0;b--)p=d(f,h,c,o,b,"throw"),a=t.call(i,a,e(l(n,p),b,j),b,j);return a}(t(o),a,m,l,j);if(r(o))return function(r,s,e,t,i){var n,d,o,a;for(n=r.data,d=r.accessors[0],o=s,a=n.length-1;a>=0;a--)o=t.call(i,o,e(d(n,a),a,n),a,n);return o}(i(o),a,m,l,j);throw new TypeError(n("0kWC4",o))}export{o as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..da8a460 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js","../lib/ndarray.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isFunction from '@stdlib/assert-is-function';\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object';\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndarrayFcn from './ndarray.js';\nimport arrayFcn from './array.js';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function';\n* import add from '@stdlib/math-base-ops-add';\n* import abs from '@stdlib/math-base-special-abs';\n* import array from '@stdlib/ndarray-array';\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '0kW3Z', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '0kW3E', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '0kWC4', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind';\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64';\n* import Complex64 from '@stdlib/complex-float32';\n* import realf from '@stdlib/complex-realf';\n* import imagf from '@stdlib/complex-imagf';\n* import cceil from '@stdlib/math-base-special-cceil';\n* import cadd from '@stdlib/math-base-ops-cadd';\n* import naryFunction from '@stdlib/utils-nary-function';\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","accessors","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;4oBA0FA,SAASA,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,GAAKK,EAAeR,GACnB,OCGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,UAAW,GAGnBZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAtH1B,SAuHTR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,CACR,CDnDSkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OE1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,UAAW,GAGnBf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,CACR,CFwBSqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,QAASP,GACvC"} \ No newline at end of file diff --git a/lib/array.js b/lib/array.js deleted file mode 100644 index 69c0a8c..0000000 --- a/lib/array.js +++ /dev/null @@ -1,83 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input array data -* @param {ArrayLikeObject} x.data - input array data -* @param {Array} x.accessors - input array accessors -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf[ idx ]; -* } -* -* // Create the input array object: -* var x = { -* 'data': [ 1, 2, 3, 4 ], -* 'accessors': [ getter ] -* }; -* -* // Compute the sum of squared values: -* var out = mapReduceRight( x, 0, square, sum ); -* // returns 30 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var get; - var acc; - var i; - - // Cache reference to the input data: - xbuf = x.data; - - // Cache the element accessor: - get = x.accessors[ 0 ]; - - // Iterate over each element... - acc = initial; - for ( i = xbuf.length-1; i >= 0; i-- ) { - acc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 522693e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +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. -*/ - -'use strict'; - -/** -* Perform a map-reduce operation against each element in an array while iterating from right to left and return the accumulated result. -* -* @module @stdlib/utils-map-reduce-right -* -* @example -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ - -// 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 c890358..0000000 --- a/lib/main.js +++ /dev/null @@ -1,110 +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. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ndarrayFcn = require( './ndarray.js' ); -var arrayFcn = require( './array.js' ); - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided the following arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided the following arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result of applying the mapping function against the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* @param {(ArrayLikeObject|ndarray)} arr - input array -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} [thisArg] - reduction function execution context -* @throws {TypeError} first argument must be an array-like object or an ndarray -* @throws {TypeError} third argument must be a function -* @throws {TypeError} fourth argument must be a function -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { - if ( !isFunction( mapper ) ) { - throw new TypeError( format( '0kW3Z', mapper ) ); - } - if ( !isFunction( reducer ) ) { - throw new TypeError( format( '0kW3E', reducer ) ); - } - if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like - return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - if ( isArrayLikeObject( arr ) ) { - return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - throw new TypeError( format( '0kWC4', arr ) ); -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/ndarray.js b/lib/ndarray.js deleted file mode 100644 index 06e19a5..0000000 --- a/lib/ndarray.js +++ /dev/null @@ -1,155 +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. -*/ - -'use strict'; - -// MODULES // - -var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); - - -// VARIABLES // - -var MODE = 'throw'; - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input ndarray meta data -* @param {string} x.ref - reference to original input ndarray-like object -* @param {string} x.dtype - data type -* @param {Collection} x.data - data buffer -* @param {NonNegativeInteger} x.length - number of elements -* @param {NonNegativeIntegerArray} x.shape - dimensions -* @param {IntegerArray} x.strides - stride lengths -* @param {NonNegativeInteger} x.offset - index offset -* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) -* @param {Array} x.accessors - accessors for accessing data buffer elements -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var Complex64 = require( '@stdlib/complex-float32' ); -* var realf = require( '@stdlib/complex-realf' ); -* var imagf = require( '@stdlib/complex-imagf' ); -* var cceil = require( '@stdlib/math-base-special-cceil' ); -* var cadd = require( '@stdlib/math-base-ops-cadd' ); -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* -* // Create a data buffer: -* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] ); -* -* // Define the shape of the input array: -* var shape = [ 2, 2 ]; -* -* // Define the array strides: -* var sx = [ 2, 1 ]; -* -* // Define the index offset: -* var ox = 0; -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf.get( idx ); -* } -* -* // Create the input ndarray-like object: -* var x = { -* 'ref': null, -* 'dtype': 'complex64', -* 'data': xbuf, -* 'length': 4, -* 'shape': shape, -* 'strides': sx, -* 'offset': ox, -* 'order': 'row-major', -* 'accessors': [ getter ] -* }; -* x.ref = x; -* -* // Compute the sum: -* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) ); -* -* var re = realf( v ); -* // returns 20.0 -* -* var im = imagf( v ); -* // returns 24.0 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var ordx; - var acc; - var len; - var get; - var ref; - var shx; - var sx; - var ox; - var ix; - var i; - - // Cache the total number of elements over which to iterate: - len = x.length; - - // Cache the input array shape: - shx = x.shape; - - // Cache reference to the input ndarray data buffer: - xbuf = x.data; - - // Cache reference to the stride array: - sx = x.strides; - - // Cache the index of the first indexed element: - ox = x.offset; - - // Cache the array order: - ordx = x.order; - - // Cache the element accessor: - get = x.accessors[ 0 ]; - - // Cache the reference to the original input array: - ref = x.ref; - - // Check for a zero-dimensional array... - if ( shx.length === 0 ) { - return reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len - } - // Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)... - acc = initial; - for ( i = len-1; i >= 0; i-- ) { - ix = vind2bind( shx, sx, ox, ordx, i, MODE ); - acc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/package.json b/package.json index 62211f4..58c2ca2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.1", "description": "Perform a single-pass map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.", "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/array-base-arraylike2object": "^0.0.x", - "@stdlib/assert-is-array-like-object": "^0.0.x", - "@stdlib/assert-is-function": "^0.0.x", - "@stdlib/assert-is-ndarray-like": "^0.0.x", - "@stdlib/ndarray-base-ndarraylike2object": "^0.0.x", - "@stdlib/ndarray-base-vind2bind": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-base-filled": "^0.0.x", - "@stdlib/array-complex64": "^0.0.x", - "@stdlib/array-filled-by": "^0.0.x", - "@stdlib/array-float64": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "@stdlib/complex-float32": "^0.0.x", - "@stdlib/complex-imagf": "^0.0.x", - "@stdlib/complex-realf": "^0.0.x", - "@stdlib/math-base-assert-is-nan": "^0.0.x", - "@stdlib/math-base-ops-add": "^0.0.x", - "@stdlib/math-base-ops-cadd": "^0.0.x", - "@stdlib/math-base-special-abs": "^0.0.x", - "@stdlib/math-base-special-cceil": "^0.0.x", - "@stdlib/math-base-special-pow": "^0.0.x", - "@stdlib/ndarray-array": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/random-base-discrete-uniform": "^0.0.x", - "@stdlib/utils-nary-function": "^0.0.x", - "@stdlib/utils-noop": "^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", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..d2ad499 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2c78efa..0000000 --- a/test/test.js +++ /dev/null @@ -1,637 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var cadd = require( '@stdlib/math-base-ops-cadd' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var cceil = require( '@stdlib/math-base-special-cceil' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var mapReduceRight = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapReduceRight, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a first argument which is either an array-like object or an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( value, 0, noop, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value, {} ); - }; - } -}); - -tape( 'the function performs a map-reduce operation for each element in an array (array-like object)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = [ -1, -2, -3 ]; - expected = 7; - actual = mapReduceRight( arr, 1, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (typed array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - expected = 7.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (complex number array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( cceil, 1 ); - f2 = naryFunction( cadd, 2 ); - - arr = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5 ] ); - expected = new Complex64( 12.0, 15.0 ); - actual = mapReduceRight( arr, new Complex64( 0.0, 0.0 ), f1, f2 ); - - t.strictEqual( realf( actual ), realf( expected ), 'returns expected value' ); - t.strictEqual( imagf( actual ), imagf( expected ), 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = array( [ -1.0, -2.0, -3.0, -4.0 ], { - 'dtype': 'generic' - }); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray; 0-dimensional)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = ndarray( 'generic', [ -10.0 ], [], [ 0 ], 0, 'row-major' ); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (array-like object)', function test( t ) { - var out = mapReduceRight( [], 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (ndarray)', function test( t ) { - var arr; - var out; - - arr = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 0, 2 ], [ 0, 2, 1 ], 0, 'row-major' ); - out = mapReduceRight( arr, 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function supports providing a `this` context (array-like object)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = [ -1.0, -2.0, -3.0 ]; - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function supports providing a `this` context (ndarray)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = array( [ -1.0, -2.0, -3.0 ], { - 'dtype': 'generic' - }); - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = array( [ 1, , , 4 ], { // eslint-disable-line no-sparse-arrays - 'dtype': 'generic' - }); - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); From 4507f6c53b2187243ee779bbc1f73d532b62661c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 20 Sep 2023 23:11:31 +0000 Subject: [PATCH 32/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index d95cde3..20efedd 100644 --- a/lib/main.js +++ b/lib/main.js @@ -25,7 +25,7 @@ var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); var isFunction = require( '@stdlib/assert-is-function' ); var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ndarrayFcn = require( './ndarray.js' ); var arrayFcn = require( './array.js' ); @@ -90,10 +90,10 @@ var arrayFcn = require( './array.js' ); */ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( !isFunction( mapper ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) ); + throw new TypeError( format( '1VL3N,G4', mapper ) ); } if ( !isFunction( reducer ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) ); + throw new TypeError( format( '1VL32,MM', reducer ) ); } if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len @@ -101,7 +101,7 @@ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( isArrayLikeObject( arr ) ) { return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len } - throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) ); + throw new TypeError( format( '1VLBH,O9', arr ) ); } diff --git a/package.json b/package.json index 918c39b..26e911e 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-ndarray-like": "^0.0.6", "@stdlib/ndarray-base-ndarraylike2object": "^0.0.1", "@stdlib/ndarray-base-vind2bind": "^0.0.8", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/types": "^0.0.14" }, "devDependencies": { From 69cc5664844ab41e66084f59abf5a100fae053ad Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 20 Sep 2023 23:13:33 +0000 Subject: [PATCH 33/91] Remove files --- index.d.ts | 257 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6439 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 41d747e..0000000 --- a/index.d.ts +++ /dev/null @@ -1,257 +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. -*/ - -// TypeScript Version: 2.0 - -/// - -import { Collection } from '@stdlib/types/object'; -import { ndarray } from '@stdlib/types/ndarray'; - -/** -* Callback invoked for each array element. -* -* @returns result -*/ -type Nullary = () => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @returns result -*/ -type Unary = ( value: any ) => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @returns result -*/ -type Binary = ( value: any, index: number ) => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Ternary = ( value: any, index: number, arr: ndarray ) => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayTernary = ( value: any, index: number, arr: Collection ) => any; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Mapper = Nullary | Unary | Binary | Ternary; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayMapper = Nullary | Unary | Binary | ArrayTernary; - -/** -* Function applied against an accumulator. -* -* @returns accumulator value -*/ -type NullaryReducer = () => void; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @returns accumulator value -*/ -type UnaryReducer = ( accumulator: any ) => any; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @returns accumulator value -*/ -type BinaryReducer = ( accumulator: any, value: any ) => any; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @returns accumulator value -*/ -type TernaryReducer = ( accumulator: any, value: any, index: number ) => any; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type QuaternaryReducer = ( accumulator: any, value: any, index: number, arr: ndarray ) => any; // tslint:disable-line:max-line-length - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayQuaternaryReducer = ( accumulator: any, value: any, index: number, arr: Collection ) => any; // tslint:disable-line:max-line-length - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type Reducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | QuaternaryReducer; // tslint:disable-line:max-line-length - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayReducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | ArrayQuaternaryReducer; // tslint:disable-line:max-line-length - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* var naryFunction = require( `@stdlib/utils/nary-function` ); -* var abs = require( `@stdlib/math/base/special/abs` ); -* var add = require( `@stdlib/math/base/ops/add` ); -* var array = require( `@stdlib/ndarray/array` ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 2 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -declare function mapReduceRight( arr: ndarray, initial: any, mapper: Mapper, reducer: Reducer, thisArg?: any ): any; // tslint:disable-line:max-line-length - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -*/ -declare function mapReduceRight( arr: Collection, initial: any, mapper: ArrayMapper, reducer: ArrayReducer, thisArg?: any ): any; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = mapReduceRight; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 7ec13a9..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@esm/index.mjs";function o(o,a,m,l,j){if(!e(m))throw new TypeError(n("0kW3Z",m));if(!e(l))throw new TypeError(n("0kW3E",l));if(s(o))return function(r,s,e,t,i){var n,o,a,m,l,j,f,h,c,p,b;if(m=r.length,f=r.shape,n=r.data,h=r.strides,c=r.offset,o=r.order,l=r.accessors[0],j=r.ref,0===f.length)return t.call(i,s,e(l(n,c),0,j),0,j);for(a=s,b=m-1;b>=0;b--)p=d(f,h,c,o,b,"throw"),a=t.call(i,a,e(l(n,p),b,j),b,j);return a}(t(o),a,m,l,j);if(r(o))return function(r,s,e,t,i){var n,d,o,a;for(n=r.data,d=r.accessors[0],o=s,a=n.length-1;a>=0;a--)o=t.call(i,o,e(d(n,a),a,n),a,n);return o}(i(o),a,m,l,j);throw new TypeError(n("0kWC4",o))}export{o as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index da8a460..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js","../lib/ndarray.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isFunction from '@stdlib/assert-is-function';\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object';\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndarrayFcn from './ndarray.js';\nimport arrayFcn from './array.js';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function';\n* import add from '@stdlib/math-base-ops-add';\n* import abs from '@stdlib/math-base-special-abs';\n* import array from '@stdlib/ndarray-array';\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '0kW3Z', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '0kW3E', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '0kWC4', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind';\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64';\n* import Complex64 from '@stdlib/complex-float32';\n* import realf from '@stdlib/complex-realf';\n* import imagf from '@stdlib/complex-imagf';\n* import cceil from '@stdlib/math-base-special-cceil';\n* import cadd from '@stdlib/math-base-ops-cadd';\n* import naryFunction from '@stdlib/utils-nary-function';\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","accessors","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;4oBA0FA,SAASA,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,GAAKK,EAAeR,GACnB,OCGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,UAAW,GAGnBZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAtH1B,SAuHTR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,CACR,CDnDSkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OE1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,UAAW,GAGnBf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,CACR,CFwBSqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,QAASP,GACvC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d2ad499..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 7ecc6670f7622613c5b1eb78b755b458f6506e04 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 20 Sep 2023 23:14:44 +0000 Subject: [PATCH 34/91] Auto-generated commit --- .editorconfig | 186 - .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 | 783 --- .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 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 63 +- benchmark/benchmark.array.js | 98 - benchmark/benchmark.ndarray.js | 109 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 9 - dist/index.js.map | 7 - docs/repl.txt | 65 - docs/types/test.ts | 184 - examples/index.js | 52 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/array.js | 83 - lib/index.js | 65 - lib/main.js | 110 - lib/ndarray.js | 155 - package.json | 76 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 637 --- 43 files changed, 6213 insertions(+), 4841 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.array.js delete mode 100644 benchmark/benchmark.ndarray.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/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/array.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/ndarray.js create mode 100644 stats.html delete mode 100644 test/test.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 3b4c7b4..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/utils/map-reduce-right) 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 bbe0806..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/utils/map-reduce-right) 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 42fe05c..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: '21 21 * * 4' - - # 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 91f2b93..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,783 +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 - - # 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@v2 - 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 + + ```
@@ -271,7 +264,7 @@ console.log( 'sum: %d', out ); ## 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]. @@ -331,11 +324,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/utils-map-reduce-right/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/stdlib +[@stdlib/array/complex64]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/array/complex128]: https://github.com/stdlib-js/stdlib +[@stdlib/array/complex128]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.array.js b/benchmark/benchmark.array.js deleted file mode 100644 index e87feb5..0000000 --- a/benchmark/benchmark.array.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = filled( -3.0, len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::array:len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.ndarray.js b/benchmark/benchmark.ndarray.js deleted file mode 100644 index e3bfba2..0000000 --- a/benchmark/benchmark.ndarray.js +++ /dev/null @@ -1,109 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var xbuf; - var opts; - var x; - - xbuf = filled( -3.0, len ); - - opts = { - 'dtype': 'generic' - }; - x = array( xbuf, opts ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::ndarray:len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index cd78ec7..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/utils/map-reduce-right" -%% click B href "https://github.com/stdlib-js/utils-map-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-map-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-map-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-map-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-map-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/map-reduce-right -[production-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-map-reduce-right/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 63ea99a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import mapReduceRight from '../docs/types/index'; -export = mapReduceRight; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 3180c8b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,9 +0,0 @@ -"use strict";var g=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var q=g(function(H,m){ -var E=require('@stdlib/ndarray-base-vind2bind/dist'),T="throw";function p(r,e,a,t,s){var i,v,n,u,f,c,l,y,d,b,o;if(u=r.length,l=r.shape,i=r.data,y=r.strides,d=r.offset,v=r.order,f=r.accessors[0],c=r.ref,l.length===0)return t.call(s,e,a(f(i,d),0,c),0,c);for(n=e,o=u-1;o>=0;o--)b=E(l,y,d,v,o,T),n=t.call(s,n,a(f(i,b),o,c),o,c);return n}m.exports=p -});var R=g(function(I,w){ -function x(r,e,a,t,s){var i,v,n,u;for(i=r.data,v=r.accessors[0],n=e,u=i.length-1;u>=0;u--)n=t.call(s,n,a(v(i,u),u,i),u,i);return n}w.exports=x -});var j=g(function(J,F){ -var V=require('@stdlib/assert-is-array-like-object/dist'),L=require('@stdlib/assert-is-ndarray-like/dist'),k=require('@stdlib/assert-is-function/dist'),O=require('@stdlib/ndarray-base-ndarraylike2object/dist'),D=require('@stdlib/array-base-arraylike2object/dist'),h=require('@stdlib/error-tools-fmtprodmsg/dist'),M=q(),z=R();function B(r,e,a,t,s){if(!k(a))throw new TypeError(h('1VL3N',a));if(!k(t))throw new TypeError(h('1VL32',t));if(L(r))return M(O(r),e,a,t,s);if(V(r))return z(D(r),e,a,t,s);throw new TypeError(h('1VLBH',r))}F.exports=B -});var C=j();module.exports=C; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 641859d..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/ndarray.js", "../lib/array.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* var Complex64Array = require( '@stdlib/array-complex64' );\n* var Complex64 = require( '@stdlib/complex-float32' );\n* var realf = require( '@stdlib/complex-realf' );\n* var imagf = require( '@stdlib/complex-imagf' );\n* var cceil = require( '@stdlib/math-base-special-cceil' );\n* var cadd = require( '@stdlib/math-base-ops-cadd' );\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar format = require( '@stdlib/string-format' );\nvar ndarrayFcn = require( './ndarray.js' );\nvar arrayFcn = require( './array.js' );\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/math-base-ops-add' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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* Perform a map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.\n*\n* @module @stdlib/utils-map-reduce-right\n*\n* @example\n* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' );\n*\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, sum );\n* // returns 30\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/math-base-ops-add' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\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,EAAY,QAAS,gCAAiC,EAKtDC,EAAO,QA0EX,SAASC,EAAgBC,EAAGC,EAASC,EAAQC,EAASC,EAAU,CAC/D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMR,EAAE,OAGRW,EAAMX,EAAE,MAGRK,EAAOL,EAAE,KAGTY,EAAKZ,EAAE,QAGPa,EAAKb,EAAE,OAGPM,EAAON,EAAE,MAGTS,EAAMT,EAAE,UAAW,CAAE,EAGrBU,EAAMV,EAAE,IAGHW,EAAI,SAAW,EACnB,OAAOR,EAAQ,KAAMC,EAASH,EAASC,EAAQO,EAAKJ,EAAMQ,CAAG,EAAG,EAAGH,CAAI,EAAG,EAAGA,CAAI,EAIlF,IADAH,EAAMN,EACAc,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKjB,EAAWc,EAAKC,EAAIC,EAAIP,EAAMS,EAAGjB,CAAK,EAC3CS,EAAMJ,EAAQ,KAAMC,EAASG,EAAKL,EAAQO,EAAKJ,EAAMS,CAAG,EAAGC,EAAGL,CAAI,EAAGK,EAAGL,CAAI,EAE7E,OAAOH,CACR,CAKAX,EAAO,QAAUG,IC1JjB,IAAAiB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA2DA,SAASC,EAAgBC,EAAGC,EAASC,EAAQC,EAASC,EAAU,CAC/D,IAAIC,EACAC,EACAC,EACAC,EAUJ,IAPAH,EAAOL,EAAE,KAGTM,EAAMN,EAAE,UAAW,CAAE,EAGrBO,EAAMN,EACAO,EAAIH,EAAK,OAAO,EAAGG,GAAK,EAAGA,IAChCD,EAAMJ,EAAQ,KAAMC,EAASG,EAAKL,EAAQI,EAAKD,EAAMG,CAAE,EAAGA,EAAGH,CAAK,EAAGG,EAAGH,CAAK,EAE9E,OAAOE,CACR,CAKAT,EAAO,QAAUC,IClFjB,IAAAU,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAoB,QAAS,qCAAsC,EACnEC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,4BAA6B,EACnDC,EAAqB,QAAS,yCAA0C,EACxEC,EAAmB,QAAS,qCAAsC,EAClEC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAW,IA6Df,SAASC,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,EAAU,CACjE,GAAK,CAACX,EAAYS,CAAO,EACxB,MAAM,IAAI,UAAWN,EAAQ,oEAAqEM,CAAO,CAAE,EAE5G,GAAK,CAACT,EAAYU,CAAQ,EACzB,MAAM,IAAI,UAAWP,EAAQ,qEAAsEO,CAAQ,CAAE,EAE9G,GAAKX,EAAeQ,CAAI,EACvB,OAAOH,EAAYH,EAAoBM,CAAI,EAAGC,EAASC,EAAQC,EAASC,CAAQ,EAEjF,GAAKb,EAAmBS,CAAI,EAC3B,OAAOF,EAAUH,EAAkBK,CAAI,EAAGC,EAASC,EAAQC,EAASC,CAAQ,EAE7E,MAAM,IAAI,UAAWR,EAAQ,4FAA6FI,CAAI,CAAE,CACjI,CAKAV,EAAO,QAAUS,IClDjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_ndarray", "__commonJSMin", "exports", "module", "vind2bind", "MODE", "mapReduceRight", "x", "initial", "mapper", "reducer", "thisArg", "xbuf", "ordx", "acc", "len", "get", "ref", "shx", "sx", "ox", "ix", "i", "require_array", "__commonJSMin", "exports", "module", "mapReduceRight", "x", "initial", "mapper", "reducer", "thisArg", "xbuf", "get", "acc", "i", "require_main", "__commonJSMin", "exports", "module", "isArrayLikeObject", "isndarrayLike", "isFunction", "ndarraylike2object", "arraylike2object", "format", "ndarrayFcn", "arrayFcn", "mapReduceRight", "arr", "initial", "mapper", "reducer", "thisArg", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b580e87..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, initial, mapper, reducer[, thisArg] ) - Performs a map-reduce operation for each element in an array while iterating - from right to left and returns the accumulated result. - - When invoked, the mapping function is provided three arguments: - - - value: array element. - - index: element index. - - arr: input array. - - When invoked, the reducing function is provided four arguments: - - - accumulator: accumulated value. - - value: result after applying the mapping function to the current array - element. - - index: element index. - - arr: input array. - - If provided an empty array, the function returns the initial value. - - When provided an ndarray, the function performs a single-pass map-reduce - operation over the entire input ndarray (i.e., higher-order ndarray - dimensions are flattened to a single-dimension). - - Parameters - ---------- - arr: ArrayLikeObject|ndarray - Input array. - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - mapper: Function - Mapping function. - - reducer: Function - Reducing function. - - thisArg: any (optional) - Execution context for the reducing function. - - Returns - ------- - out: any - Accumulated result. - - Examples - -------- - // array-like object: - > var f1 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/special/abs}}, 1 ); - > var f2 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/ops/add}}, 2 ); - > var arr = [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0 ]; - > var out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - // ndarray: - > arr = {{alias:@stdlib/ndarray/array}}( arr, { 'shape': [ 2, 3 ] } ); - > out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 3fcccbb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,184 +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. -*/ - -import array = require( '@stdlib/ndarray-array' ); -import mapReduceRight = require( './index' ); - -/** -* Mapping function. -* -* @param value - array element -* @returns result -*/ -function mapper( value: number ): number { - return value; -} - -/** -* Reducing function. -* -* @param acc - accumulated value -* @param v - array element -* @returns result -*/ -function reducer( acc: number, value: number ): number { - return acc + value; -} - - -// TESTS // - -// The function returns the accumulated value when provided a collection... -{ - mapReduceRight( [ 0, 1, 1, NaN, 2 ], 0, mapper, reducer ); // $ExpectType number - mapReduceRight( [ -1, 1, 2 ], 100, mapper, reducer ); // $ExpectType number - mapReduceRight( [ -1, 1, 2 ], 0, mapper, reducer, {} ); // $ExpectType number -} - -// The function returns the accumulated value when provided an ndarray... -{ - const arr = array( [ 1, 2, 3, 4, 5, 6 ] ); - - mapReduceRight( arr, 0, mapper, reducer ); // $ExpectType number - mapReduceRight( arr, 100, mapper, reducer ); // $ExpectType number - mapReduceRight( arr, 0, mapper, reducer, {} ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not a collection or ndarray... -{ - mapReduceRight( 2, 0, mapper, reducer ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer ); // $ExpectError - - mapReduceRight( 2, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr1, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr2, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const arr1 = [ 1, 2, 3 ]; - - mapReduceRight(); // $ExpectError - mapReduceRight( arr1 ); // $ExpectError - mapReduceRight( arr1, 0 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ); // $ExpectError - mapReduceRight( arr1, 0, mapper, reducer, {}, 3 ); // $ExpectError - - const arr2 = array( [ 1, 2, 3 ] ); - - mapReduceRight(); // $ExpectError - mapReduceRight( arr2 ); // $ExpectError - mapReduceRight( arr2, 0 ); // $ExpectError - mapReduceRight( arr2, 0, mapper ); // $ExpectError - mapReduceRight( arr2, 0, mapper, reducer, {}, 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 7474059..0000000 --- a/examples/index.js +++ /dev/null @@ -1,52 +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. -*/ - -'use strict'; - -var filledarrayBy = require( '@stdlib/array-filled-by' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ).factory; -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var mapReduceRight = require( './../lib' ); - -function fill( i ) { - var rand = discreteUniform( -10*(i+1), 10*(i+1) ); - return filledarrayBy( 10, 'generic', rand ); -} - -// Create a two-dimensional ndarray (i.e., a matrix): -var x = array( filledarrayBy( 10, 'generic', fill ), { - 'dtype': 'generic', - 'flatten': true -}); - -// Create an explicit unary function: -var f1 = naryFunction( abs, 1 ); - -// Create an explicit binary function: -var f2 = naryFunction( add, 2 ); - -// Compute the sum of absolute values: -var out = mapReduceRight( x, 0, f1, f2 ); - -console.log( 'x:' ); -console.log( x.data ); - -console.log( 'sum: %d', out ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 2d0e5da..ed593f9 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; import { typedndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..353b9e4 --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@esm/index.mjs";function o(o,a,m,l,j){if(!e(m))throw new TypeError(n("1VL3N,G4",m));if(!e(l))throw new TypeError(n("1VL32,MM",l));if(s(o))return function(r,s,e,t,i){var n,o,a,m,l,j,f,h,c,p,b;if(m=r.length,f=r.shape,n=r.data,h=r.strides,c=r.offset,o=r.order,l=r.accessors[0],j=r.ref,0===f.length)return t.call(i,s,e(l(n,c),0,j),0,j);for(a=s,b=m-1;b>=0;b--)p=d(f,h,c,o,b,"throw"),a=t.call(i,a,e(l(n,p),b,j),b,j);return a}(t(o),a,m,l,j);if(r(o))return function(r,s,e,t,i){var n,d,o,a;for(n=r.data,d=r.accessors[0],o=s,a=n.length-1;a>=0;a--)o=t.call(i,o,e(d(n,a),a,n),a,n);return o}(i(o),a,m,l,j);throw new TypeError(n("1VLBH,O9",o))}export{o as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..8315462 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js","../lib/ndarray.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isFunction from '@stdlib/assert-is-function';\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object';\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndarrayFcn from './ndarray.js';\nimport arrayFcn from './array.js';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function';\n* import add from '@stdlib/math-base-ops-add';\n* import abs from '@stdlib/math-base-special-abs';\n* import array from '@stdlib/ndarray-array';\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '1VL3N,G4', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '1VL32,MM', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '1VLBH,O9', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind';\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64';\n* import Complex64 from '@stdlib/complex-float32';\n* import realf from '@stdlib/complex-realf';\n* import imagf from '@stdlib/complex-imagf';\n* import cceil from '@stdlib/math-base-special-cceil';\n* import cadd from '@stdlib/math-base-ops-cadd';\n* import naryFunction from '@stdlib/utils-nary-function';\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","accessors","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;4oBA0FA,SAASA,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,WAAYL,IAE1C,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,WAAYJ,IAE1C,GAAKK,EAAeR,GACnB,OCGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,UAAW,GAGnBZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAtH1B,SAuHTR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,CACR,CDnDSkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OE1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,UAAW,GAGnBf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,CACR,CFwBSqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,WAAYP,GAC1C"} \ No newline at end of file diff --git a/lib/array.js b/lib/array.js deleted file mode 100644 index 69c0a8c..0000000 --- a/lib/array.js +++ /dev/null @@ -1,83 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input array data -* @param {ArrayLikeObject} x.data - input array data -* @param {Array} x.accessors - input array accessors -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf[ idx ]; -* } -* -* // Create the input array object: -* var x = { -* 'data': [ 1, 2, 3, 4 ], -* 'accessors': [ getter ] -* }; -* -* // Compute the sum of squared values: -* var out = mapReduceRight( x, 0, square, sum ); -* // returns 30 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var get; - var acc; - var i; - - // Cache reference to the input data: - xbuf = x.data; - - // Cache the element accessor: - get = x.accessors[ 0 ]; - - // Iterate over each element... - acc = initial; - for ( i = xbuf.length-1; i >= 0; i-- ) { - acc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 522693e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +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. -*/ - -'use strict'; - -/** -* Perform a map-reduce operation against each element in an array while iterating from right to left and return the accumulated result. -* -* @module @stdlib/utils-map-reduce-right -* -* @example -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ - -// 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 20efedd..0000000 --- a/lib/main.js +++ /dev/null @@ -1,110 +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. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ndarrayFcn = require( './ndarray.js' ); -var arrayFcn = require( './array.js' ); - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided the following arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided the following arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result of applying the mapping function against the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* @param {(ArrayLikeObject|ndarray)} arr - input array -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} [thisArg] - reduction function execution context -* @throws {TypeError} first argument must be an array-like object or an ndarray -* @throws {TypeError} third argument must be a function -* @throws {TypeError} fourth argument must be a function -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { - if ( !isFunction( mapper ) ) { - throw new TypeError( format( '1VL3N,G4', mapper ) ); - } - if ( !isFunction( reducer ) ) { - throw new TypeError( format( '1VL32,MM', reducer ) ); - } - if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like - return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - if ( isArrayLikeObject( arr ) ) { - return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - throw new TypeError( format( '1VLBH,O9', arr ) ); -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/ndarray.js b/lib/ndarray.js deleted file mode 100644 index 06e19a5..0000000 --- a/lib/ndarray.js +++ /dev/null @@ -1,155 +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. -*/ - -'use strict'; - -// MODULES // - -var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); - - -// VARIABLES // - -var MODE = 'throw'; - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input ndarray meta data -* @param {string} x.ref - reference to original input ndarray-like object -* @param {string} x.dtype - data type -* @param {Collection} x.data - data buffer -* @param {NonNegativeInteger} x.length - number of elements -* @param {NonNegativeIntegerArray} x.shape - dimensions -* @param {IntegerArray} x.strides - stride lengths -* @param {NonNegativeInteger} x.offset - index offset -* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) -* @param {Array} x.accessors - accessors for accessing data buffer elements -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var Complex64 = require( '@stdlib/complex-float32' ); -* var realf = require( '@stdlib/complex-realf' ); -* var imagf = require( '@stdlib/complex-imagf' ); -* var cceil = require( '@stdlib/math-base-special-cceil' ); -* var cadd = require( '@stdlib/math-base-ops-cadd' ); -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* -* // Create a data buffer: -* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] ); -* -* // Define the shape of the input array: -* var shape = [ 2, 2 ]; -* -* // Define the array strides: -* var sx = [ 2, 1 ]; -* -* // Define the index offset: -* var ox = 0; -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf.get( idx ); -* } -* -* // Create the input ndarray-like object: -* var x = { -* 'ref': null, -* 'dtype': 'complex64', -* 'data': xbuf, -* 'length': 4, -* 'shape': shape, -* 'strides': sx, -* 'offset': ox, -* 'order': 'row-major', -* 'accessors': [ getter ] -* }; -* x.ref = x; -* -* // Compute the sum: -* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) ); -* -* var re = realf( v ); -* // returns 20.0 -* -* var im = imagf( v ); -* // returns 24.0 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var ordx; - var acc; - var len; - var get; - var ref; - var shx; - var sx; - var ox; - var ix; - var i; - - // Cache the total number of elements over which to iterate: - len = x.length; - - // Cache the input array shape: - shx = x.shape; - - // Cache reference to the input ndarray data buffer: - xbuf = x.data; - - // Cache reference to the stride array: - sx = x.strides; - - // Cache the index of the first indexed element: - ox = x.offset; - - // Cache the array order: - ordx = x.order; - - // Cache the element accessor: - get = x.accessors[ 0 ]; - - // Cache the reference to the original input array: - ref = x.ref; - - // Check for a zero-dimensional array... - if ( shx.length === 0 ) { - return reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len - } - // Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)... - acc = initial; - for ( i = len-1; i >= 0; i-- ) { - ix = vind2bind( shx, sx, ox, ordx, i, MODE ); - acc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/package.json b/package.json index 26e911e..6c60a5a 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.1", "description": "Perform a single-pass map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.", "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/array-base-arraylike2object": "^0.0.2", - "@stdlib/assert-is-array-like-object": "^0.0.8", - "@stdlib/assert-is-function": "^0.0.8", - "@stdlib/assert-is-ndarray-like": "^0.0.6", - "@stdlib/ndarray-base-ndarraylike2object": "^0.0.1", - "@stdlib/ndarray-base-vind2bind": "^0.0.8", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/types": "^0.0.14" - }, - "devDependencies": { - "@stdlib/array-base-filled": "^0.0.2", - "@stdlib/array-complex64": "^0.0.6", - "@stdlib/array-filled-by": "^0.0.2", - "@stdlib/array-float64": "^0.0.6", - "@stdlib/bench": "^0.0.12", - "@stdlib/complex-float32": "^0.0.7", - "@stdlib/complex-imagf": "^0.0.1", - "@stdlib/complex-realf": "^0.0.1", - "@stdlib/math-base-assert-is-nan": "^0.0.8", - "@stdlib/math-base-ops-add": "^0.0.1", - "@stdlib/math-base-ops-cadd": "^0.0.7", - "@stdlib/math-base-special-abs": "^0.0.6", - "@stdlib/math-base-special-cceil": "^0.0.7", - "@stdlib/math-base-special-pow": "^0.0.7", - "@stdlib/ndarray-array": "^0.0.9", - "@stdlib/ndarray-ctor": "^0.0.10", - "@stdlib/random-base-discrete-uniform": "^0.0.6", - "@stdlib/utils-nary-function": "^0.0.1", - "@stdlib/utils-noop": "^0.0.14", - "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", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..7fc8b74 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2c78efa..0000000 --- a/test/test.js +++ /dev/null @@ -1,637 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var cadd = require( '@stdlib/math-base-ops-cadd' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var cceil = require( '@stdlib/math-base-special-cceil' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var mapReduceRight = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapReduceRight, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a first argument which is either an array-like object or an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( value, 0, noop, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value, {} ); - }; - } -}); - -tape( 'the function performs a map-reduce operation for each element in an array (array-like object)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = [ -1, -2, -3 ]; - expected = 7; - actual = mapReduceRight( arr, 1, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (typed array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - expected = 7.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (complex number array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( cceil, 1 ); - f2 = naryFunction( cadd, 2 ); - - arr = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5 ] ); - expected = new Complex64( 12.0, 15.0 ); - actual = mapReduceRight( arr, new Complex64( 0.0, 0.0 ), f1, f2 ); - - t.strictEqual( realf( actual ), realf( expected ), 'returns expected value' ); - t.strictEqual( imagf( actual ), imagf( expected ), 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = array( [ -1.0, -2.0, -3.0, -4.0 ], { - 'dtype': 'generic' - }); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray; 0-dimensional)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = ndarray( 'generic', [ -10.0 ], [], [ 0 ], 0, 'row-major' ); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (array-like object)', function test( t ) { - var out = mapReduceRight( [], 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (ndarray)', function test( t ) { - var arr; - var out; - - arr = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 0, 2 ], [ 0, 2, 1 ], 0, 'row-major' ); - out = mapReduceRight( arr, 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function supports providing a `this` context (array-like object)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = [ -1.0, -2.0, -3.0 ]; - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function supports providing a `this` context (ndarray)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = array( [ -1.0, -2.0, -3.0 ], { - 'dtype': 'generic' - }); - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = array( [ 1, , , 4 ], { // eslint-disable-line no-sparse-arrays - 'dtype': 'generic' - }); - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); From 5e1db1459eaab9c7bde4fd22470fff9cc58c3d44 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 24 Sep 2023 17:42:15 +0000 Subject: [PATCH 35/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index d95cde3..20efedd 100644 --- a/lib/main.js +++ b/lib/main.js @@ -25,7 +25,7 @@ var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); var isFunction = require( '@stdlib/assert-is-function' ); var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ndarrayFcn = require( './ndarray.js' ); var arrayFcn = require( './array.js' ); @@ -90,10 +90,10 @@ var arrayFcn = require( './array.js' ); */ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( !isFunction( mapper ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) ); + throw new TypeError( format( '1VL3N,G4', mapper ) ); } if ( !isFunction( reducer ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) ); + throw new TypeError( format( '1VL32,MM', reducer ) ); } if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len @@ -101,7 +101,7 @@ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( isArrayLikeObject( arr ) ) { return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len } - throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) ); + throw new TypeError( format( '1VLBH,O9', arr ) ); } diff --git a/package.json b/package.json index 87cc32a..55643c8 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-ndarray-like": "^0.1.0", "@stdlib/ndarray-base-ndarraylike2object": "^0.1.0", "@stdlib/ndarray-base-vind2bind": "^0.1.0", - "@stdlib/string-format": "^0.1.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.0", "@stdlib/types": "^0.1.0" }, "devDependencies": { From 89df4015a9395578daecf3ad56c00ac4bab1bf61 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 24 Sep 2023 18:06:12 +0000 Subject: [PATCH 36/91] Remove files --- index.d.ts | 257 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6439 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 ed593f9..0000000 --- a/index.d.ts +++ /dev/null @@ -1,257 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; -import { typedndarray } from '@stdlib/types/ndarray'; - -/** -* Callback invoked for each array element. -* -* @returns result -*/ -type Nullary = () => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @returns result -*/ -type Unary = ( value: T ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @returns result -*/ -type Binary = ( value: T, index: number ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Ternary = ( value: T, index: number, arr: typedndarray ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayTernary = ( value: T, index: number, arr: Collection ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Mapper = Nullary | Unary | Binary | Ternary; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayMapper = Nullary | Unary | Binary | ArrayTernary; - -/** -* Function applied against an accumulator. -* -* @returns accumulator value -*/ -type NullaryReducer = ( this: W ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @returns accumulator value -*/ -type UnaryReducer = ( this: W, accumulator: V ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @returns accumulator value -*/ -type BinaryReducer = ( this: W, accumulator: V, value: U ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @returns accumulator value -*/ -type TernaryReducer = ( this: W, accumulator: V, value: U, index: number ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type QuaternaryReducer = ( this: W, accumulator: V, value: U, index: number, arr: typedndarray ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayQuaternaryReducer = ( this: W, accumulator: V, value: U, index: number, arr: Collection ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type Reducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | QuaternaryReducer; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayReducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | ArrayQuaternaryReducer; - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* var naryFunction = require( `@stdlib/utils/nary-function` ); -* var abs = require( `@stdlib/math/base/special/abs` ); -* var add = require( `@stdlib/math/base/ops/add` ); -* var array = require( `@stdlib/ndarray/array` ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 2 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -declare function mapReduceRight( arr: typedndarray, initial: V, mapper: Mapper, reducer: Reducer, thisArg?: ThisParameterType> ): V; - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -*/ -declare function mapReduceRight( arr: Collection, initial: V, mapper: ArrayMapper, reducer: ArrayReducer, thisArg?: ThisParameterType> ): V; - - -// EXPORTS // - -export = mapReduceRight; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 353b9e4..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@esm/index.mjs";function o(o,a,m,l,j){if(!e(m))throw new TypeError(n("1VL3N,G4",m));if(!e(l))throw new TypeError(n("1VL32,MM",l));if(s(o))return function(r,s,e,t,i){var n,o,a,m,l,j,f,h,c,p,b;if(m=r.length,f=r.shape,n=r.data,h=r.strides,c=r.offset,o=r.order,l=r.accessors[0],j=r.ref,0===f.length)return t.call(i,s,e(l(n,c),0,j),0,j);for(a=s,b=m-1;b>=0;b--)p=d(f,h,c,o,b,"throw"),a=t.call(i,a,e(l(n,p),b,j),b,j);return a}(t(o),a,m,l,j);if(r(o))return function(r,s,e,t,i){var n,d,o,a;for(n=r.data,d=r.accessors[0],o=s,a=n.length-1;a>=0;a--)o=t.call(i,o,e(d(n,a),a,n),a,n);return o}(i(o),a,m,l,j);throw new TypeError(n("1VLBH,O9",o))}export{o as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 8315462..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js","../lib/ndarray.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isFunction from '@stdlib/assert-is-function';\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object';\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndarrayFcn from './ndarray.js';\nimport arrayFcn from './array.js';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function';\n* import add from '@stdlib/math-base-ops-add';\n* import abs from '@stdlib/math-base-special-abs';\n* import array from '@stdlib/ndarray-array';\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '1VL3N,G4', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '1VL32,MM', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '1VLBH,O9', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind';\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64';\n* import Complex64 from '@stdlib/complex-float32';\n* import realf from '@stdlib/complex-realf';\n* import imagf from '@stdlib/complex-imagf';\n* import cceil from '@stdlib/math-base-special-cceil';\n* import cadd from '@stdlib/math-base-ops-cadd';\n* import naryFunction from '@stdlib/utils-nary-function';\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","accessors","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;4oBA0FA,SAASA,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,WAAYL,IAE1C,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,WAAYJ,IAE1C,GAAKK,EAAeR,GACnB,OCGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,UAAW,GAGnBZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAtH1B,SAuHTR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,CACR,CDnDSkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OE1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,UAAW,GAGnBf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,CACR,CFwBSqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,WAAYP,GAC1C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 7fc8b74..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 27a35beff5d030c7325689654cad8ded3d4bd8a7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 24 Sep 2023 18:08:52 +0000 Subject: [PATCH 37/91] Auto-generated commit --- .editorconfig | 186 - .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 | 783 --- .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 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 63 +- benchmark/benchmark.array.js | 98 - benchmark/benchmark.ndarray.js | 109 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 9 - dist/index.js.map | 7 - docs/repl.txt | 65 - docs/types/test.ts | 184 - examples/index.js | 52 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/array.js | 83 - lib/index.js | 65 - lib/main.js | 110 - lib/ndarray.js | 155 - package.json | 76 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 637 --- 43 files changed, 6213 insertions(+), 4841 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.array.js delete mode 100644 benchmark/benchmark.ndarray.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/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/array.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/ndarray.js create mode 100644 stats.html delete mode 100644 test/test.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 3b4c7b4..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/utils/map-reduce-right) 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 bbe0806..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/utils/map-reduce-right) 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 42fe05c..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: '21 21 * * 4' - - # 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 91f2b93..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,783 +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 - - # 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@v2 - 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 + + ```
@@ -271,7 +264,7 @@ console.log( 'sum: %d', out ); ## 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]. @@ -331,11 +324,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/utils-map-reduce-right/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/stdlib +[@stdlib/array/complex64]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/array/complex128]: https://github.com/stdlib-js/stdlib +[@stdlib/array/complex128]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.array.js b/benchmark/benchmark.array.js deleted file mode 100644 index e87feb5..0000000 --- a/benchmark/benchmark.array.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = filled( -3.0, len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::array:len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.ndarray.js b/benchmark/benchmark.ndarray.js deleted file mode 100644 index e3bfba2..0000000 --- a/benchmark/benchmark.ndarray.js +++ /dev/null @@ -1,109 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var xbuf; - var opts; - var x; - - xbuf = filled( -3.0, len ); - - opts = { - 'dtype': 'generic' - }; - x = array( xbuf, opts ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::ndarray:len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index cd78ec7..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/utils/map-reduce-right" -%% click B href "https://github.com/stdlib-js/utils-map-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-map-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-map-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-map-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-map-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/map-reduce-right -[production-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-map-reduce-right/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 63ea99a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import mapReduceRight from '../docs/types/index'; -export = mapReduceRight; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 3180c8b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,9 +0,0 @@ -"use strict";var g=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var q=g(function(H,m){ -var E=require('@stdlib/ndarray-base-vind2bind/dist'),T="throw";function p(r,e,a,t,s){var i,v,n,u,f,c,l,y,d,b,o;if(u=r.length,l=r.shape,i=r.data,y=r.strides,d=r.offset,v=r.order,f=r.accessors[0],c=r.ref,l.length===0)return t.call(s,e,a(f(i,d),0,c),0,c);for(n=e,o=u-1;o>=0;o--)b=E(l,y,d,v,o,T),n=t.call(s,n,a(f(i,b),o,c),o,c);return n}m.exports=p -});var R=g(function(I,w){ -function x(r,e,a,t,s){var i,v,n,u;for(i=r.data,v=r.accessors[0],n=e,u=i.length-1;u>=0;u--)n=t.call(s,n,a(v(i,u),u,i),u,i);return n}w.exports=x -});var j=g(function(J,F){ -var V=require('@stdlib/assert-is-array-like-object/dist'),L=require('@stdlib/assert-is-ndarray-like/dist'),k=require('@stdlib/assert-is-function/dist'),O=require('@stdlib/ndarray-base-ndarraylike2object/dist'),D=require('@stdlib/array-base-arraylike2object/dist'),h=require('@stdlib/error-tools-fmtprodmsg/dist'),M=q(),z=R();function B(r,e,a,t,s){if(!k(a))throw new TypeError(h('1VL3N',a));if(!k(t))throw new TypeError(h('1VL32',t));if(L(r))return M(O(r),e,a,t,s);if(V(r))return z(D(r),e,a,t,s);throw new TypeError(h('1VLBH',r))}F.exports=B -});var C=j();module.exports=C; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 641859d..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/ndarray.js", "../lib/array.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* var Complex64Array = require( '@stdlib/array-complex64' );\n* var Complex64 = require( '@stdlib/complex-float32' );\n* var realf = require( '@stdlib/complex-realf' );\n* var imagf = require( '@stdlib/complex-imagf' );\n* var cceil = require( '@stdlib/math-base-special-cceil' );\n* var cadd = require( '@stdlib/math-base-ops-cadd' );\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar format = require( '@stdlib/string-format' );\nvar ndarrayFcn = require( './ndarray.js' );\nvar arrayFcn = require( './array.js' );\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/math-base-ops-add' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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* Perform a map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.\n*\n* @module @stdlib/utils-map-reduce-right\n*\n* @example\n* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' );\n*\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, sum );\n* // returns 30\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/math-base-ops-add' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\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,EAAY,QAAS,gCAAiC,EAKtDC,EAAO,QA0EX,SAASC,EAAgBC,EAAGC,EAASC,EAAQC,EAASC,EAAU,CAC/D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMR,EAAE,OAGRW,EAAMX,EAAE,MAGRK,EAAOL,EAAE,KAGTY,EAAKZ,EAAE,QAGPa,EAAKb,EAAE,OAGPM,EAAON,EAAE,MAGTS,EAAMT,EAAE,UAAW,CAAE,EAGrBU,EAAMV,EAAE,IAGHW,EAAI,SAAW,EACnB,OAAOR,EAAQ,KAAMC,EAASH,EAASC,EAAQO,EAAKJ,EAAMQ,CAAG,EAAG,EAAGH,CAAI,EAAG,EAAGA,CAAI,EAIlF,IADAH,EAAMN,EACAc,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKjB,EAAWc,EAAKC,EAAIC,EAAIP,EAAMS,EAAGjB,CAAK,EAC3CS,EAAMJ,EAAQ,KAAMC,EAASG,EAAKL,EAAQO,EAAKJ,EAAMS,CAAG,EAAGC,EAAGL,CAAI,EAAGK,EAAGL,CAAI,EAE7E,OAAOH,CACR,CAKAX,EAAO,QAAUG,IC1JjB,IAAAiB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA2DA,SAASC,EAAgBC,EAAGC,EAASC,EAAQC,EAASC,EAAU,CAC/D,IAAIC,EACAC,EACAC,EACAC,EAUJ,IAPAH,EAAOL,EAAE,KAGTM,EAAMN,EAAE,UAAW,CAAE,EAGrBO,EAAMN,EACAO,EAAIH,EAAK,OAAO,EAAGG,GAAK,EAAGA,IAChCD,EAAMJ,EAAQ,KAAMC,EAASG,EAAKL,EAAQI,EAAKD,EAAMG,CAAE,EAAGA,EAAGH,CAAK,EAAGG,EAAGH,CAAK,EAE9E,OAAOE,CACR,CAKAT,EAAO,QAAUC,IClFjB,IAAAU,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAoB,QAAS,qCAAsC,EACnEC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,4BAA6B,EACnDC,EAAqB,QAAS,yCAA0C,EACxEC,EAAmB,QAAS,qCAAsC,EAClEC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAW,IA6Df,SAASC,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,EAAU,CACjE,GAAK,CAACX,EAAYS,CAAO,EACxB,MAAM,IAAI,UAAWN,EAAQ,oEAAqEM,CAAO,CAAE,EAE5G,GAAK,CAACT,EAAYU,CAAQ,EACzB,MAAM,IAAI,UAAWP,EAAQ,qEAAsEO,CAAQ,CAAE,EAE9G,GAAKX,EAAeQ,CAAI,EACvB,OAAOH,EAAYH,EAAoBM,CAAI,EAAGC,EAASC,EAAQC,EAASC,CAAQ,EAEjF,GAAKb,EAAmBS,CAAI,EAC3B,OAAOF,EAAUH,EAAkBK,CAAI,EAAGC,EAASC,EAAQC,EAASC,CAAQ,EAE7E,MAAM,IAAI,UAAWR,EAAQ,4FAA6FI,CAAI,CAAE,CACjI,CAKAV,EAAO,QAAUS,IClDjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_ndarray", "__commonJSMin", "exports", "module", "vind2bind", "MODE", "mapReduceRight", "x", "initial", "mapper", "reducer", "thisArg", "xbuf", "ordx", "acc", "len", "get", "ref", "shx", "sx", "ox", "ix", "i", "require_array", "__commonJSMin", "exports", "module", "mapReduceRight", "x", "initial", "mapper", "reducer", "thisArg", "xbuf", "get", "acc", "i", "require_main", "__commonJSMin", "exports", "module", "isArrayLikeObject", "isndarrayLike", "isFunction", "ndarraylike2object", "arraylike2object", "format", "ndarrayFcn", "arrayFcn", "mapReduceRight", "arr", "initial", "mapper", "reducer", "thisArg", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b580e87..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, initial, mapper, reducer[, thisArg] ) - Performs a map-reduce operation for each element in an array while iterating - from right to left and returns the accumulated result. - - When invoked, the mapping function is provided three arguments: - - - value: array element. - - index: element index. - - arr: input array. - - When invoked, the reducing function is provided four arguments: - - - accumulator: accumulated value. - - value: result after applying the mapping function to the current array - element. - - index: element index. - - arr: input array. - - If provided an empty array, the function returns the initial value. - - When provided an ndarray, the function performs a single-pass map-reduce - operation over the entire input ndarray (i.e., higher-order ndarray - dimensions are flattened to a single-dimension). - - Parameters - ---------- - arr: ArrayLikeObject|ndarray - Input array. - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - mapper: Function - Mapping function. - - reducer: Function - Reducing function. - - thisArg: any (optional) - Execution context for the reducing function. - - Returns - ------- - out: any - Accumulated result. - - Examples - -------- - // array-like object: - > var f1 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/special/abs}}, 1 ); - > var f2 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/ops/add}}, 2 ); - > var arr = [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0 ]; - > var out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - // ndarray: - > arr = {{alias:@stdlib/ndarray/array}}( arr, { 'shape': [ 2, 3 ] } ); - > out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 3fcccbb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,184 +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. -*/ - -import array = require( '@stdlib/ndarray-array' ); -import mapReduceRight = require( './index' ); - -/** -* Mapping function. -* -* @param value - array element -* @returns result -*/ -function mapper( value: number ): number { - return value; -} - -/** -* Reducing function. -* -* @param acc - accumulated value -* @param v - array element -* @returns result -*/ -function reducer( acc: number, value: number ): number { - return acc + value; -} - - -// TESTS // - -// The function returns the accumulated value when provided a collection... -{ - mapReduceRight( [ 0, 1, 1, NaN, 2 ], 0, mapper, reducer ); // $ExpectType number - mapReduceRight( [ -1, 1, 2 ], 100, mapper, reducer ); // $ExpectType number - mapReduceRight( [ -1, 1, 2 ], 0, mapper, reducer, {} ); // $ExpectType number -} - -// The function returns the accumulated value when provided an ndarray... -{ - const arr = array( [ 1, 2, 3, 4, 5, 6 ] ); - - mapReduceRight( arr, 0, mapper, reducer ); // $ExpectType number - mapReduceRight( arr, 100, mapper, reducer ); // $ExpectType number - mapReduceRight( arr, 0, mapper, reducer, {} ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not a collection or ndarray... -{ - mapReduceRight( 2, 0, mapper, reducer ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer ); // $ExpectError - - mapReduceRight( 2, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr1, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr2, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const arr1 = [ 1, 2, 3 ]; - - mapReduceRight(); // $ExpectError - mapReduceRight( arr1 ); // $ExpectError - mapReduceRight( arr1, 0 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ); // $ExpectError - mapReduceRight( arr1, 0, mapper, reducer, {}, 3 ); // $ExpectError - - const arr2 = array( [ 1, 2, 3 ] ); - - mapReduceRight(); // $ExpectError - mapReduceRight( arr2 ); // $ExpectError - mapReduceRight( arr2, 0 ); // $ExpectError - mapReduceRight( arr2, 0, mapper ); // $ExpectError - mapReduceRight( arr2, 0, mapper, reducer, {}, 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 7474059..0000000 --- a/examples/index.js +++ /dev/null @@ -1,52 +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. -*/ - -'use strict'; - -var filledarrayBy = require( '@stdlib/array-filled-by' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ).factory; -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var mapReduceRight = require( './../lib' ); - -function fill( i ) { - var rand = discreteUniform( -10*(i+1), 10*(i+1) ); - return filledarrayBy( 10, 'generic', rand ); -} - -// Create a two-dimensional ndarray (i.e., a matrix): -var x = array( filledarrayBy( 10, 'generic', fill ), { - 'dtype': 'generic', - 'flatten': true -}); - -// Create an explicit unary function: -var f1 = naryFunction( abs, 1 ); - -// Create an explicit binary function: -var f2 = naryFunction( add, 2 ); - -// Compute the sum of absolute values: -var out = mapReduceRight( x, 0, f1, f2 ); - -console.log( 'x:' ); -console.log( x.data ); - -console.log( 'sum: %d', out ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 2d0e5da..ed593f9 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; import { typedndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..80fc989 --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.1.0-esm/index.mjs";function o(o,a,m,l,j){if(!e(m))throw new TypeError(n("1VL3N,G4",m));if(!e(l))throw new TypeError(n("1VL32,MM",l));if(s(o))return function(r,s,e,t,i){var n,o,a,m,l,j,f,h,c,p,v;if(m=r.length,f=r.shape,n=r.data,h=r.strides,c=r.offset,o=r.order,l=r.accessors[0],j=r.ref,0===f.length)return t.call(i,s,e(l(n,c),0,j),0,j);for(a=s,v=m-1;v>=0;v--)p=d(f,h,c,o,v,"throw"),a=t.call(i,a,e(l(n,p),v,j),v,j);return a}(t(o),a,m,l,j);if(r(o))return function(r,s,e,t,i){var n,d,o,a;for(n=r.data,d=r.accessors[0],o=s,a=n.length-1;a>=0;a--)o=t.call(i,o,e(d(n,a),a,n),a,n);return o}(i(o),a,m,l,j);throw new TypeError(n("1VLBH,O9",o))}export{o as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..2978771 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js","../lib/ndarray.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isFunction from '@stdlib/assert-is-function';\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object';\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndarrayFcn from './ndarray.js';\nimport arrayFcn from './array.js';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function';\n* import add from '@stdlib/math-base-ops-add';\n* import abs from '@stdlib/math-base-special-abs';\n* import array from '@stdlib/ndarray-array';\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '1VL3N,G4', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '1VL32,MM', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '1VLBH,O9', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind';\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64';\n* import Complex64 from '@stdlib/complex-float32';\n* import realf from '@stdlib/complex-realf';\n* import imagf from '@stdlib/complex-imagf';\n* import cceil from '@stdlib/math-base-special-cceil';\n* import cadd from '@stdlib/math-base-ops-cadd';\n* import naryFunction from '@stdlib/utils-nary-function';\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","accessors","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;+qBA0FA,SAASA,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,WAAYL,IAE1C,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,WAAYJ,IAE1C,GAAKK,EAAeR,GACnB,OCGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,UAAW,GAGnBZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAtH1B,SAuHTR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,CACR,CDnDSkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OE1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,UAAW,GAGnBf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,CACR,CFwBSqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,WAAYP,GAC1C"} \ No newline at end of file diff --git a/lib/array.js b/lib/array.js deleted file mode 100644 index 69c0a8c..0000000 --- a/lib/array.js +++ /dev/null @@ -1,83 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input array data -* @param {ArrayLikeObject} x.data - input array data -* @param {Array} x.accessors - input array accessors -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf[ idx ]; -* } -* -* // Create the input array object: -* var x = { -* 'data': [ 1, 2, 3, 4 ], -* 'accessors': [ getter ] -* }; -* -* // Compute the sum of squared values: -* var out = mapReduceRight( x, 0, square, sum ); -* // returns 30 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var get; - var acc; - var i; - - // Cache reference to the input data: - xbuf = x.data; - - // Cache the element accessor: - get = x.accessors[ 0 ]; - - // Iterate over each element... - acc = initial; - for ( i = xbuf.length-1; i >= 0; i-- ) { - acc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 522693e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +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. -*/ - -'use strict'; - -/** -* Perform a map-reduce operation against each element in an array while iterating from right to left and return the accumulated result. -* -* @module @stdlib/utils-map-reduce-right -* -* @example -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ - -// 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 20efedd..0000000 --- a/lib/main.js +++ /dev/null @@ -1,110 +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. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ndarrayFcn = require( './ndarray.js' ); -var arrayFcn = require( './array.js' ); - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided the following arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided the following arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result of applying the mapping function against the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* @param {(ArrayLikeObject|ndarray)} arr - input array -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} [thisArg] - reduction function execution context -* @throws {TypeError} first argument must be an array-like object or an ndarray -* @throws {TypeError} third argument must be a function -* @throws {TypeError} fourth argument must be a function -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { - if ( !isFunction( mapper ) ) { - throw new TypeError( format( '1VL3N,G4', mapper ) ); - } - if ( !isFunction( reducer ) ) { - throw new TypeError( format( '1VL32,MM', reducer ) ); - } - if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like - return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - if ( isArrayLikeObject( arr ) ) { - return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - throw new TypeError( format( '1VLBH,O9', arr ) ); -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/ndarray.js b/lib/ndarray.js deleted file mode 100644 index 06e19a5..0000000 --- a/lib/ndarray.js +++ /dev/null @@ -1,155 +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. -*/ - -'use strict'; - -// MODULES // - -var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); - - -// VARIABLES // - -var MODE = 'throw'; - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input ndarray meta data -* @param {string} x.ref - reference to original input ndarray-like object -* @param {string} x.dtype - data type -* @param {Collection} x.data - data buffer -* @param {NonNegativeInteger} x.length - number of elements -* @param {NonNegativeIntegerArray} x.shape - dimensions -* @param {IntegerArray} x.strides - stride lengths -* @param {NonNegativeInteger} x.offset - index offset -* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) -* @param {Array} x.accessors - accessors for accessing data buffer elements -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var Complex64 = require( '@stdlib/complex-float32' ); -* var realf = require( '@stdlib/complex-realf' ); -* var imagf = require( '@stdlib/complex-imagf' ); -* var cceil = require( '@stdlib/math-base-special-cceil' ); -* var cadd = require( '@stdlib/math-base-ops-cadd' ); -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* -* // Create a data buffer: -* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] ); -* -* // Define the shape of the input array: -* var shape = [ 2, 2 ]; -* -* // Define the array strides: -* var sx = [ 2, 1 ]; -* -* // Define the index offset: -* var ox = 0; -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf.get( idx ); -* } -* -* // Create the input ndarray-like object: -* var x = { -* 'ref': null, -* 'dtype': 'complex64', -* 'data': xbuf, -* 'length': 4, -* 'shape': shape, -* 'strides': sx, -* 'offset': ox, -* 'order': 'row-major', -* 'accessors': [ getter ] -* }; -* x.ref = x; -* -* // Compute the sum: -* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) ); -* -* var re = realf( v ); -* // returns 20.0 -* -* var im = imagf( v ); -* // returns 24.0 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var ordx; - var acc; - var len; - var get; - var ref; - var shx; - var sx; - var ox; - var ix; - var i; - - // Cache the total number of elements over which to iterate: - len = x.length; - - // Cache the input array shape: - shx = x.shape; - - // Cache reference to the input ndarray data buffer: - xbuf = x.data; - - // Cache reference to the stride array: - sx = x.strides; - - // Cache the index of the first indexed element: - ox = x.offset; - - // Cache the array order: - ordx = x.order; - - // Cache the element accessor: - get = x.accessors[ 0 ]; - - // Cache the reference to the original input array: - ref = x.ref; - - // Check for a zero-dimensional array... - if ( shx.length === 0 ) { - return reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len - } - // Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)... - acc = initial; - for ( i = len-1; i >= 0; i-- ) { - ix = vind2bind( shx, sx, ox, ordx, i, MODE ); - acc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/package.json b/package.json index 55643c8..75d88cc 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Perform a single-pass map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.", "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/array-base-arraylike2object": "^0.1.0", - "@stdlib/assert-is-array-like-object": "^0.1.0", - "@stdlib/assert-is-function": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/ndarray-base-ndarraylike2object": "^0.1.0", - "@stdlib/ndarray-base-vind2bind": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.0", - "@stdlib/types": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-base-filled": "^0.1.0", - "@stdlib/array-complex64": "^0.1.0", - "@stdlib/array-filled-by": "^0.0.2", - "@stdlib/array-float64": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/complex-float32": "^0.1.0", - "@stdlib/complex-imagf": "^0.1.0", - "@stdlib/complex-realf": "^0.1.0", - "@stdlib/math-base-assert-is-nan": "^0.1.0", - "@stdlib/math-base-ops-add": "^0.1.0", - "@stdlib/math-base-ops-cadd": "^0.1.0", - "@stdlib/math-base-special-abs": "^0.1.0", - "@stdlib/math-base-special-cceil": "^0.1.0", - "@stdlib/math-base-special-pow": "^0.1.0", - "@stdlib/ndarray-array": "^0.0.9", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/random-base-discrete-uniform": "^0.0.6", - "@stdlib/utils-nary-function": "^0.1.0", - "@stdlib/utils-noop": "^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", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..684b5f0 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2c78efa..0000000 --- a/test/test.js +++ /dev/null @@ -1,637 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var cadd = require( '@stdlib/math-base-ops-cadd' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var cceil = require( '@stdlib/math-base-special-cceil' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var mapReduceRight = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapReduceRight, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a first argument which is either an array-like object or an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( value, 0, noop, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value, {} ); - }; - } -}); - -tape( 'the function performs a map-reduce operation for each element in an array (array-like object)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = [ -1, -2, -3 ]; - expected = 7; - actual = mapReduceRight( arr, 1, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (typed array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - expected = 7.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (complex number array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( cceil, 1 ); - f2 = naryFunction( cadd, 2 ); - - arr = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5 ] ); - expected = new Complex64( 12.0, 15.0 ); - actual = mapReduceRight( arr, new Complex64( 0.0, 0.0 ), f1, f2 ); - - t.strictEqual( realf( actual ), realf( expected ), 'returns expected value' ); - t.strictEqual( imagf( actual ), imagf( expected ), 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = array( [ -1.0, -2.0, -3.0, -4.0 ], { - 'dtype': 'generic' - }); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray; 0-dimensional)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = ndarray( 'generic', [ -10.0 ], [], [ 0 ], 0, 'row-major' ); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (array-like object)', function test( t ) { - var out = mapReduceRight( [], 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (ndarray)', function test( t ) { - var arr; - var out; - - arr = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 0, 2 ], [ 0, 2, 1 ], 0, 'row-major' ); - out = mapReduceRight( arr, 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function supports providing a `this` context (array-like object)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = [ -1.0, -2.0, -3.0 ]; - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function supports providing a `this` context (ndarray)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = array( [ -1.0, -2.0, -3.0 ], { - 'dtype': 'generic' - }); - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = array( [ 1, , , 4 ], { // eslint-disable-line no-sparse-arrays - 'dtype': 'generic' - }); - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); From 46a11d652ec3c49c6e03b52b700fb1b91800a053 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 24 Sep 2023 18:21:11 +0000 Subject: [PATCH 38/91] Update README.md for ESM bundle v0.1.0 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 772bfc1..538390d 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import mapReduceRight from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-map-reduce-right@esm/index.mjs'; +import mapReduceRight from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-map-reduce-right@v0.1.0-esm/index.mjs'; ``` #### mapReduceRight( arr, initial, mapper, reducer\[, thisArg ] ) @@ -203,7 +203,7 @@ import naryFunction from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-nary-funct import add from 'https://cdn.jsdelivr.net/gh/stdlib-js/math-base-ops-add@esm/index.mjs'; import abs from 'https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs'; import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; -import mapReduceRight from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-map-reduce-right@esm/index.mjs'; +import mapReduceRight from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-map-reduce-right@v0.1.0-esm/index.mjs'; function fill( i ) { var rand = discreteUniform( -10*(i+1), 10*(i+1) ); From 4d98f9a746bdc3b794ba4cc07451a42eb391e606 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 24 Sep 2023 18:21:12 +0000 Subject: [PATCH 39/91] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 538390d..cd541f5 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import mapReduceRight from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-map-reduce-right@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/utils-map-reduce-right/tags). For example, + ```javascript import mapReduceRight from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-map-reduce-right@v0.1.0-esm/index.mjs'; ``` @@ -203,7 +208,7 @@ import naryFunction from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-nary-funct import add from 'https://cdn.jsdelivr.net/gh/stdlib-js/math-base-ops-add@esm/index.mjs'; import abs from 'https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs'; import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; -import mapReduceRight from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-map-reduce-right@v0.1.0-esm/index.mjs'; +import mapReduceRight from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-map-reduce-right@esm/index.mjs'; function fill( i ) { var rand = discreteUniform( -10*(i+1), 10*(i+1) ); From 65d32765dbb1a9f9fd79d75ed89c6ee685eece17 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 1 Oct 2023 17:20:02 +0000 Subject: [PATCH 40/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index d95cde3..20efedd 100644 --- a/lib/main.js +++ b/lib/main.js @@ -25,7 +25,7 @@ var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); var isFunction = require( '@stdlib/assert-is-function' ); var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ndarrayFcn = require( './ndarray.js' ); var arrayFcn = require( './array.js' ); @@ -90,10 +90,10 @@ var arrayFcn = require( './array.js' ); */ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( !isFunction( mapper ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) ); + throw new TypeError( format( '1VL3N,G4', mapper ) ); } if ( !isFunction( reducer ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) ); + throw new TypeError( format( '1VL32,MM', reducer ) ); } if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len @@ -101,7 +101,7 @@ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( isArrayLikeObject( arr ) ) { return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len } - throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) ); + throw new TypeError( format( '1VLBH,O9', arr ) ); } diff --git a/package.json b/package.json index ac469ec..f5f8d3a 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-ndarray-like": "^0.1.0", "@stdlib/ndarray-base-ndarraylike2object": "^0.1.0", "@stdlib/ndarray-base-vind2bind": "^0.1.0", - "@stdlib/string-format": "^0.1.0", + "@stdlib/error-tools-fmtprodmsg": "^0.1.0", "@stdlib/types": "^0.1.0" }, "devDependencies": { From 930aea1d01738a36a773b742351c3311394642d0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 3 Oct 2023 03:00:12 +0000 Subject: [PATCH 41/91] Remove files --- index.d.ts | 257 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6439 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 ed593f9..0000000 --- a/index.d.ts +++ /dev/null @@ -1,257 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; -import { typedndarray } from '@stdlib/types/ndarray'; - -/** -* Callback invoked for each array element. -* -* @returns result -*/ -type Nullary = () => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @returns result -*/ -type Unary = ( value: T ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @returns result -*/ -type Binary = ( value: T, index: number ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Ternary = ( value: T, index: number, arr: typedndarray ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayTernary = ( value: T, index: number, arr: Collection ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Mapper = Nullary | Unary | Binary | Ternary; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayMapper = Nullary | Unary | Binary | ArrayTernary; - -/** -* Function applied against an accumulator. -* -* @returns accumulator value -*/ -type NullaryReducer = ( this: W ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @returns accumulator value -*/ -type UnaryReducer = ( this: W, accumulator: V ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @returns accumulator value -*/ -type BinaryReducer = ( this: W, accumulator: V, value: U ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @returns accumulator value -*/ -type TernaryReducer = ( this: W, accumulator: V, value: U, index: number ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type QuaternaryReducer = ( this: W, accumulator: V, value: U, index: number, arr: typedndarray ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayQuaternaryReducer = ( this: W, accumulator: V, value: U, index: number, arr: Collection ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type Reducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | QuaternaryReducer; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayReducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | ArrayQuaternaryReducer; - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* var naryFunction = require( `@stdlib/utils/nary-function` ); -* var abs = require( `@stdlib/math/base/special/abs` ); -* var add = require( `@stdlib/math/base/ops/add` ); -* var array = require( `@stdlib/ndarray/array` ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 2 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -declare function mapReduceRight( arr: typedndarray, initial: V, mapper: Mapper, reducer: Reducer, thisArg?: ThisParameterType> ): V; - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -*/ -declare function mapReduceRight( arr: Collection, initial: V, mapper: ArrayMapper, reducer: ArrayReducer, thisArg?: ThisParameterType> ): V; - - -// EXPORTS // - -export = mapReduceRight; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 80fc989..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.1.0-esm/index.mjs";function o(o,a,m,l,j){if(!e(m))throw new TypeError(n("1VL3N,G4",m));if(!e(l))throw new TypeError(n("1VL32,MM",l));if(s(o))return function(r,s,e,t,i){var n,o,a,m,l,j,f,h,c,p,v;if(m=r.length,f=r.shape,n=r.data,h=r.strides,c=r.offset,o=r.order,l=r.accessors[0],j=r.ref,0===f.length)return t.call(i,s,e(l(n,c),0,j),0,j);for(a=s,v=m-1;v>=0;v--)p=d(f,h,c,o,v,"throw"),a=t.call(i,a,e(l(n,p),v,j),v,j);return a}(t(o),a,m,l,j);if(r(o))return function(r,s,e,t,i){var n,d,o,a;for(n=r.data,d=r.accessors[0],o=s,a=n.length-1;a>=0;a--)o=t.call(i,o,e(d(n,a),a,n),a,n);return o}(i(o),a,m,l,j);throw new TypeError(n("1VLBH,O9",o))}export{o as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 2978771..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js","../lib/ndarray.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isFunction from '@stdlib/assert-is-function';\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object';\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndarrayFcn from './ndarray.js';\nimport arrayFcn from './array.js';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function';\n* import add from '@stdlib/math-base-ops-add';\n* import abs from '@stdlib/math-base-special-abs';\n* import array from '@stdlib/ndarray-array';\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '1VL3N,G4', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '1VL32,MM', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '1VLBH,O9', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind';\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64';\n* import Complex64 from '@stdlib/complex-float32';\n* import realf from '@stdlib/complex-realf';\n* import imagf from '@stdlib/complex-imagf';\n* import cceil from '@stdlib/math-base-special-cceil';\n* import cadd from '@stdlib/math-base-ops-cadd';\n* import naryFunction from '@stdlib/utils-nary-function';\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","accessors","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;+qBA0FA,SAASA,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,WAAYL,IAE1C,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,WAAYJ,IAE1C,GAAKK,EAAeR,GACnB,OCGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,UAAW,GAGnBZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAtH1B,SAuHTR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,CACR,CDnDSkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OE1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,UAAW,GAGnBf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,CACR,CFwBSqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,WAAYP,GAC1C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 684b5f0..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From dc8eaa30cb92dc008e95befef1af2628e6d2819b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 3 Oct 2023 03:03:55 +0000 Subject: [PATCH 42/91] Auto-generated commit --- .editorconfig | 186 - .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 | 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 | 63 +- benchmark/benchmark.array.js | 98 - benchmark/benchmark.ndarray.js | 109 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 9 - dist/index.js.map | 7 - docs/repl.txt | 65 - docs/types/test.ts | 184 - examples/index.js | 52 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/array.js | 83 - lib/index.js | 65 - lib/main.js | 110 - lib/ndarray.js | 155 - package.json | 76 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 637 --- test/test.js | 637 --- 45 files changed, 6213 insertions(+), 5537 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 benchmark/benchmark.array.js delete mode 100644 benchmark/benchmark.ndarray.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/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/array.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/ndarray.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.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/.keepalive b/.github/.keepalive deleted file mode 100644 index 4af55ed..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-10-01T05:37:37.768Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3b4c7b4..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/utils/map-reduce-right) 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 f23359f..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/utils/map-reduce-right) 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 d3c6ace..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: '21 21 * * 4' - - # 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 + + ```
@@ -271,7 +264,7 @@ console.log( 'sum: %d', out ); ## 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]. @@ -331,11 +324,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/utils-map-reduce-right/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/stdlib +[@stdlib/array/complex64]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/array/complex128]: https://github.com/stdlib-js/stdlib +[@stdlib/array/complex128]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.array.js b/benchmark/benchmark.array.js deleted file mode 100644 index e87feb5..0000000 --- a/benchmark/benchmark.array.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = filled( -3.0, len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::array:len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.ndarray.js b/benchmark/benchmark.ndarray.js deleted file mode 100644 index e3bfba2..0000000 --- a/benchmark/benchmark.ndarray.js +++ /dev/null @@ -1,109 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var xbuf; - var opts; - var x; - - xbuf = filled( -3.0, len ); - - opts = { - 'dtype': 'generic' - }; - x = array( xbuf, opts ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::ndarray:len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index cd78ec7..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/utils/map-reduce-right" -%% click B href "https://github.com/stdlib-js/utils-map-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-map-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-map-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-map-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-map-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/map-reduce-right -[production-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-map-reduce-right/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 63ea99a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import mapReduceRight from '../docs/types/index'; -export = mapReduceRight; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 3180c8b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,9 +0,0 @@ -"use strict";var g=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var q=g(function(H,m){ -var E=require('@stdlib/ndarray-base-vind2bind/dist'),T="throw";function p(r,e,a,t,s){var i,v,n,u,f,c,l,y,d,b,o;if(u=r.length,l=r.shape,i=r.data,y=r.strides,d=r.offset,v=r.order,f=r.accessors[0],c=r.ref,l.length===0)return t.call(s,e,a(f(i,d),0,c),0,c);for(n=e,o=u-1;o>=0;o--)b=E(l,y,d,v,o,T),n=t.call(s,n,a(f(i,b),o,c),o,c);return n}m.exports=p -});var R=g(function(I,w){ -function x(r,e,a,t,s){var i,v,n,u;for(i=r.data,v=r.accessors[0],n=e,u=i.length-1;u>=0;u--)n=t.call(s,n,a(v(i,u),u,i),u,i);return n}w.exports=x -});var j=g(function(J,F){ -var V=require('@stdlib/assert-is-array-like-object/dist'),L=require('@stdlib/assert-is-ndarray-like/dist'),k=require('@stdlib/assert-is-function/dist'),O=require('@stdlib/ndarray-base-ndarraylike2object/dist'),D=require('@stdlib/array-base-arraylike2object/dist'),h=require('@stdlib/error-tools-fmtprodmsg/dist'),M=q(),z=R();function B(r,e,a,t,s){if(!k(a))throw new TypeError(h('1VL3N',a));if(!k(t))throw new TypeError(h('1VL32',t));if(L(r))return M(O(r),e,a,t,s);if(V(r))return z(D(r),e,a,t,s);throw new TypeError(h('1VLBH',r))}F.exports=B -});var C=j();module.exports=C; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 641859d..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/ndarray.js", "../lib/array.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* var Complex64Array = require( '@stdlib/array-complex64' );\n* var Complex64 = require( '@stdlib/complex-float32' );\n* var realf = require( '@stdlib/complex-realf' );\n* var imagf = require( '@stdlib/complex-imagf' );\n* var cceil = require( '@stdlib/math-base-special-cceil' );\n* var cadd = require( '@stdlib/math-base-ops-cadd' );\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar format = require( '@stdlib/string-format' );\nvar ndarrayFcn = require( './ndarray.js' );\nvar arrayFcn = require( './array.js' );\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/math-base-ops-add' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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* Perform a map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.\n*\n* @module @stdlib/utils-map-reduce-right\n*\n* @example\n* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' );\n*\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, sum );\n* // returns 30\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/math-base-ops-add' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\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,EAAY,QAAS,gCAAiC,EAKtDC,EAAO,QA0EX,SAASC,EAAgBC,EAAGC,EAASC,EAAQC,EAASC,EAAU,CAC/D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMR,EAAE,OAGRW,EAAMX,EAAE,MAGRK,EAAOL,EAAE,KAGTY,EAAKZ,EAAE,QAGPa,EAAKb,EAAE,OAGPM,EAAON,EAAE,MAGTS,EAAMT,EAAE,UAAW,CAAE,EAGrBU,EAAMV,EAAE,IAGHW,EAAI,SAAW,EACnB,OAAOR,EAAQ,KAAMC,EAASH,EAASC,EAAQO,EAAKJ,EAAMQ,CAAG,EAAG,EAAGH,CAAI,EAAG,EAAGA,CAAI,EAIlF,IADAH,EAAMN,EACAc,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKjB,EAAWc,EAAKC,EAAIC,EAAIP,EAAMS,EAAGjB,CAAK,EAC3CS,EAAMJ,EAAQ,KAAMC,EAASG,EAAKL,EAAQO,EAAKJ,EAAMS,CAAG,EAAGC,EAAGL,CAAI,EAAGK,EAAGL,CAAI,EAE7E,OAAOH,CACR,CAKAX,EAAO,QAAUG,IC1JjB,IAAAiB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA2DA,SAASC,EAAgBC,EAAGC,EAASC,EAAQC,EAASC,EAAU,CAC/D,IAAIC,EACAC,EACAC,EACAC,EAUJ,IAPAH,EAAOL,EAAE,KAGTM,EAAMN,EAAE,UAAW,CAAE,EAGrBO,EAAMN,EACAO,EAAIH,EAAK,OAAO,EAAGG,GAAK,EAAGA,IAChCD,EAAMJ,EAAQ,KAAMC,EAASG,EAAKL,EAAQI,EAAKD,EAAMG,CAAE,EAAGA,EAAGH,CAAK,EAAGG,EAAGH,CAAK,EAE9E,OAAOE,CACR,CAKAT,EAAO,QAAUC,IClFjB,IAAAU,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAoB,QAAS,qCAAsC,EACnEC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,4BAA6B,EACnDC,EAAqB,QAAS,yCAA0C,EACxEC,EAAmB,QAAS,qCAAsC,EAClEC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAW,IA6Df,SAASC,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,EAAU,CACjE,GAAK,CAACX,EAAYS,CAAO,EACxB,MAAM,IAAI,UAAWN,EAAQ,oEAAqEM,CAAO,CAAE,EAE5G,GAAK,CAACT,EAAYU,CAAQ,EACzB,MAAM,IAAI,UAAWP,EAAQ,qEAAsEO,CAAQ,CAAE,EAE9G,GAAKX,EAAeQ,CAAI,EACvB,OAAOH,EAAYH,EAAoBM,CAAI,EAAGC,EAASC,EAAQC,EAASC,CAAQ,EAEjF,GAAKb,EAAmBS,CAAI,EAC3B,OAAOF,EAAUH,EAAkBK,CAAI,EAAGC,EAASC,EAAQC,EAASC,CAAQ,EAE7E,MAAM,IAAI,UAAWR,EAAQ,4FAA6FI,CAAI,CAAE,CACjI,CAKAV,EAAO,QAAUS,IClDjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_ndarray", "__commonJSMin", "exports", "module", "vind2bind", "MODE", "mapReduceRight", "x", "initial", "mapper", "reducer", "thisArg", "xbuf", "ordx", "acc", "len", "get", "ref", "shx", "sx", "ox", "ix", "i", "require_array", "__commonJSMin", "exports", "module", "mapReduceRight", "x", "initial", "mapper", "reducer", "thisArg", "xbuf", "get", "acc", "i", "require_main", "__commonJSMin", "exports", "module", "isArrayLikeObject", "isndarrayLike", "isFunction", "ndarraylike2object", "arraylike2object", "format", "ndarrayFcn", "arrayFcn", "mapReduceRight", "arr", "initial", "mapper", "reducer", "thisArg", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b580e87..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, initial, mapper, reducer[, thisArg] ) - Performs a map-reduce operation for each element in an array while iterating - from right to left and returns the accumulated result. - - When invoked, the mapping function is provided three arguments: - - - value: array element. - - index: element index. - - arr: input array. - - When invoked, the reducing function is provided four arguments: - - - accumulator: accumulated value. - - value: result after applying the mapping function to the current array - element. - - index: element index. - - arr: input array. - - If provided an empty array, the function returns the initial value. - - When provided an ndarray, the function performs a single-pass map-reduce - operation over the entire input ndarray (i.e., higher-order ndarray - dimensions are flattened to a single-dimension). - - Parameters - ---------- - arr: ArrayLikeObject|ndarray - Input array. - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - mapper: Function - Mapping function. - - reducer: Function - Reducing function. - - thisArg: any (optional) - Execution context for the reducing function. - - Returns - ------- - out: any - Accumulated result. - - Examples - -------- - // array-like object: - > var f1 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/special/abs}}, 1 ); - > var f2 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/ops/add}}, 2 ); - > var arr = [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0 ]; - > var out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - // ndarray: - > arr = {{alias:@stdlib/ndarray/array}}( arr, { 'shape': [ 2, 3 ] } ); - > out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 3fcccbb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,184 +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. -*/ - -import array = require( '@stdlib/ndarray-array' ); -import mapReduceRight = require( './index' ); - -/** -* Mapping function. -* -* @param value - array element -* @returns result -*/ -function mapper( value: number ): number { - return value; -} - -/** -* Reducing function. -* -* @param acc - accumulated value -* @param v - array element -* @returns result -*/ -function reducer( acc: number, value: number ): number { - return acc + value; -} - - -// TESTS // - -// The function returns the accumulated value when provided a collection... -{ - mapReduceRight( [ 0, 1, 1, NaN, 2 ], 0, mapper, reducer ); // $ExpectType number - mapReduceRight( [ -1, 1, 2 ], 100, mapper, reducer ); // $ExpectType number - mapReduceRight( [ -1, 1, 2 ], 0, mapper, reducer, {} ); // $ExpectType number -} - -// The function returns the accumulated value when provided an ndarray... -{ - const arr = array( [ 1, 2, 3, 4, 5, 6 ] ); - - mapReduceRight( arr, 0, mapper, reducer ); // $ExpectType number - mapReduceRight( arr, 100, mapper, reducer ); // $ExpectType number - mapReduceRight( arr, 0, mapper, reducer, {} ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not a collection or ndarray... -{ - mapReduceRight( 2, 0, mapper, reducer ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer ); // $ExpectError - - mapReduceRight( 2, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr1, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr2, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const arr1 = [ 1, 2, 3 ]; - - mapReduceRight(); // $ExpectError - mapReduceRight( arr1 ); // $ExpectError - mapReduceRight( arr1, 0 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ); // $ExpectError - mapReduceRight( arr1, 0, mapper, reducer, {}, 3 ); // $ExpectError - - const arr2 = array( [ 1, 2, 3 ] ); - - mapReduceRight(); // $ExpectError - mapReduceRight( arr2 ); // $ExpectError - mapReduceRight( arr2, 0 ); // $ExpectError - mapReduceRight( arr2, 0, mapper ); // $ExpectError - mapReduceRight( arr2, 0, mapper, reducer, {}, 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 7474059..0000000 --- a/examples/index.js +++ /dev/null @@ -1,52 +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. -*/ - -'use strict'; - -var filledarrayBy = require( '@stdlib/array-filled-by' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ).factory; -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var mapReduceRight = require( './../lib' ); - -function fill( i ) { - var rand = discreteUniform( -10*(i+1), 10*(i+1) ); - return filledarrayBy( 10, 'generic', rand ); -} - -// Create a two-dimensional ndarray (i.e., a matrix): -var x = array( filledarrayBy( 10, 'generic', fill ), { - 'dtype': 'generic', - 'flatten': true -}); - -// Create an explicit unary function: -var f1 = naryFunction( abs, 1 ); - -// Create an explicit binary function: -var f2 = naryFunction( add, 2 ); - -// Compute the sum of absolute values: -var out = mapReduceRight( x, 0, f1, f2 ); - -console.log( 'x:' ); -console.log( x.data ); - -console.log( 'sum: %d', out ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 2d0e5da..ed593f9 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; import { typedndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..ffca626 --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.1.0-esm/index.mjs";function o(o,a,m,l,j){if(!e(m))throw new TypeError(n("1VL3N,G4",m));if(!e(l))throw new TypeError(n("1VL32,MM",l));if(s(o))return function(r,s,e,t,i){var n,o,a,m,l,j,f,h,c,p,v;if(m=r.length,f=r.shape,n=r.data,h=r.strides,c=r.offset,o=r.order,l=r.accessors[0],j=r.ref,0===f.length)return t.call(i,s,e(l(n,c),0,j),0,j);for(a=s,v=m-1;v>=0;v--)p=d(f,h,c,o,v,"throw"),a=t.call(i,a,e(l(n,p),v,j),v,j);return a}(t(o),a,m,l,j);if(r(o))return function(r,s,e,t,i){var n,d,o,a;for(n=r.data,d=r.accessors[0],o=s,a=n.length-1;a>=0;a--)o=t.call(i,o,e(d(n,a),a,n),a,n);return o}(i(o),a,m,l,j);throw new TypeError(n("1VLBH,O9",o))}export{o as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..d07fb53 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js","../lib/ndarray.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isFunction from '@stdlib/assert-is-function';\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object';\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndarrayFcn from './ndarray.js';\nimport arrayFcn from './array.js';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function';\n* import add from '@stdlib/math-base-ops-add';\n* import abs from '@stdlib/math-base-special-abs';\n* import array from '@stdlib/ndarray-array';\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '1VL3N,G4', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '1VL32,MM', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '1VLBH,O9', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind';\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64';\n* import Complex64 from '@stdlib/complex-float32';\n* import realf from '@stdlib/complex-realf';\n* import imagf from '@stdlib/complex-imagf';\n* import cceil from '@stdlib/math-base-special-cceil';\n* import cadd from '@stdlib/math-base-ops-cadd';\n* import naryFunction from '@stdlib/utils-nary-function';\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","accessors","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;srBA0FA,SAASA,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,WAAYL,IAE1C,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,WAAYJ,IAE1C,GAAKK,EAAeR,GACnB,OCGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,UAAW,GAGnBZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAtH1B,SAuHTR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,CACR,CDnDSkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OE1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,UAAW,GAGnBf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,CACR,CFwBSqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,WAAYP,GAC1C"} \ No newline at end of file diff --git a/lib/array.js b/lib/array.js deleted file mode 100644 index 69c0a8c..0000000 --- a/lib/array.js +++ /dev/null @@ -1,83 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input array data -* @param {ArrayLikeObject} x.data - input array data -* @param {Array} x.accessors - input array accessors -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf[ idx ]; -* } -* -* // Create the input array object: -* var x = { -* 'data': [ 1, 2, 3, 4 ], -* 'accessors': [ getter ] -* }; -* -* // Compute the sum of squared values: -* var out = mapReduceRight( x, 0, square, sum ); -* // returns 30 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var get; - var acc; - var i; - - // Cache reference to the input data: - xbuf = x.data; - - // Cache the element accessor: - get = x.accessors[ 0 ]; - - // Iterate over each element... - acc = initial; - for ( i = xbuf.length-1; i >= 0; i-- ) { - acc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 522693e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +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. -*/ - -'use strict'; - -/** -* Perform a map-reduce operation against each element in an array while iterating from right to left and return the accumulated result. -* -* @module @stdlib/utils-map-reduce-right -* -* @example -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ - -// 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 20efedd..0000000 --- a/lib/main.js +++ /dev/null @@ -1,110 +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. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ndarrayFcn = require( './ndarray.js' ); -var arrayFcn = require( './array.js' ); - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided the following arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided the following arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result of applying the mapping function against the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* @param {(ArrayLikeObject|ndarray)} arr - input array -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} [thisArg] - reduction function execution context -* @throws {TypeError} first argument must be an array-like object or an ndarray -* @throws {TypeError} third argument must be a function -* @throws {TypeError} fourth argument must be a function -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { - if ( !isFunction( mapper ) ) { - throw new TypeError( format( '1VL3N,G4', mapper ) ); - } - if ( !isFunction( reducer ) ) { - throw new TypeError( format( '1VL32,MM', reducer ) ); - } - if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like - return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - if ( isArrayLikeObject( arr ) ) { - return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - throw new TypeError( format( '1VLBH,O9', arr ) ); -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/ndarray.js b/lib/ndarray.js deleted file mode 100644 index 06e19a5..0000000 --- a/lib/ndarray.js +++ /dev/null @@ -1,155 +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. -*/ - -'use strict'; - -// MODULES // - -var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); - - -// VARIABLES // - -var MODE = 'throw'; - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input ndarray meta data -* @param {string} x.ref - reference to original input ndarray-like object -* @param {string} x.dtype - data type -* @param {Collection} x.data - data buffer -* @param {NonNegativeInteger} x.length - number of elements -* @param {NonNegativeIntegerArray} x.shape - dimensions -* @param {IntegerArray} x.strides - stride lengths -* @param {NonNegativeInteger} x.offset - index offset -* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) -* @param {Array} x.accessors - accessors for accessing data buffer elements -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var Complex64 = require( '@stdlib/complex-float32' ); -* var realf = require( '@stdlib/complex-realf' ); -* var imagf = require( '@stdlib/complex-imagf' ); -* var cceil = require( '@stdlib/math-base-special-cceil' ); -* var cadd = require( '@stdlib/math-base-ops-cadd' ); -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* -* // Create a data buffer: -* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] ); -* -* // Define the shape of the input array: -* var shape = [ 2, 2 ]; -* -* // Define the array strides: -* var sx = [ 2, 1 ]; -* -* // Define the index offset: -* var ox = 0; -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf.get( idx ); -* } -* -* // Create the input ndarray-like object: -* var x = { -* 'ref': null, -* 'dtype': 'complex64', -* 'data': xbuf, -* 'length': 4, -* 'shape': shape, -* 'strides': sx, -* 'offset': ox, -* 'order': 'row-major', -* 'accessors': [ getter ] -* }; -* x.ref = x; -* -* // Compute the sum: -* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) ); -* -* var re = realf( v ); -* // returns 20.0 -* -* var im = imagf( v ); -* // returns 24.0 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var ordx; - var acc; - var len; - var get; - var ref; - var shx; - var sx; - var ox; - var ix; - var i; - - // Cache the total number of elements over which to iterate: - len = x.length; - - // Cache the input array shape: - shx = x.shape; - - // Cache reference to the input ndarray data buffer: - xbuf = x.data; - - // Cache reference to the stride array: - sx = x.strides; - - // Cache the index of the first indexed element: - ox = x.offset; - - // Cache the array order: - ordx = x.order; - - // Cache the element accessor: - get = x.accessors[ 0 ]; - - // Cache the reference to the original input array: - ref = x.ref; - - // Check for a zero-dimensional array... - if ( shx.length === 0 ) { - return reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len - } - // Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)... - acc = initial; - for ( i = len-1; i >= 0; i-- ) { - ix = vind2bind( shx, sx, ox, ordx, i, MODE ); - acc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/package.json b/package.json index f5f8d3a..75d88cc 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Perform a single-pass map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.", "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/array-base-arraylike2object": "^0.1.0", - "@stdlib/assert-is-array-like-object": "^0.1.0", - "@stdlib/assert-is-function": "^0.1.0", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/ndarray-base-ndarraylike2object": "^0.1.0", - "@stdlib/ndarray-base-vind2bind": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.0", - "@stdlib/types": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-base-filled": "^0.1.0", - "@stdlib/array-complex64": "^0.1.0", - "@stdlib/array-filled-by": "^0.1.0", - "@stdlib/array-float64": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/complex-float32": "^0.1.0", - "@stdlib/complex-imagf": "^0.1.0", - "@stdlib/complex-realf": "^0.1.0", - "@stdlib/math-base-assert-is-nan": "^0.1.0", - "@stdlib/math-base-ops-add": "^0.1.0", - "@stdlib/math-base-ops-cadd": "^0.1.0", - "@stdlib/math-base-special-abs": "^0.1.0", - "@stdlib/math-base-special-cceil": "^0.1.0", - "@stdlib/math-base-special-pow": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/random-base-discrete-uniform": "^0.1.0", - "@stdlib/utils-nary-function": "^0.1.0", - "@stdlib/utils-noop": "^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", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..bfa2f00 --- /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 67461fc..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,637 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var cadd = require( '@stdlib/math-base-ops-cadd' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var cceil = require( '@stdlib/math-base-special-cceil' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var mapReduceRight = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapReduceRight, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a first argument which is either an array-like object or an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( value, 0, noop, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value, {} ); - }; - } -}); - -tape( 'the function performs a map-reduce operation for each element in an array (array-like object)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = [ -1, -2, -3 ]; - expected = 7; - actual = mapReduceRight( arr, 1, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (typed array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - expected = 7.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (complex number array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( cceil, 1 ); - f2 = naryFunction( cadd, 2 ); - - arr = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5 ] ); - expected = new Complex64( 12.0, 15.0 ); - actual = mapReduceRight( arr, new Complex64( 0.0, 0.0 ), f1, f2 ); - - t.strictEqual( realf( actual ), realf( expected ), 'returns expected value' ); - t.strictEqual( imagf( actual ), imagf( expected ), 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = array( [ -1.0, -2.0, -3.0, -4.0 ], { - 'dtype': 'generic' - }); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray; 0-dimensional)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = ndarray( 'generic', [ -10.0 ], [], [ 0 ], 0, 'row-major' ); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (array-like object)', function test( t ) { - var out = mapReduceRight( [], 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (ndarray)', function test( t ) { - var arr; - var out; - - arr = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 0, 2 ], [ 0, 2, 1 ], 0, 'row-major' ); - out = mapReduceRight( arr, 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function supports providing a `this` context (array-like object)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = [ -1.0, -2.0, -3.0 ]; - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function supports providing a `this` context (ndarray)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = array( [ -1.0, -2.0, -3.0 ], { - 'dtype': 'generic' - }); - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = array( [ 1, , , 4 ], { // eslint-disable-line no-sparse-arrays - 'dtype': 'generic' - }); - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2c78efa..0000000 --- a/test/test.js +++ /dev/null @@ -1,637 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var cadd = require( '@stdlib/math-base-ops-cadd' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var cceil = require( '@stdlib/math-base-special-cceil' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var mapReduceRight = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapReduceRight, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a first argument which is either an array-like object or an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( value, 0, noop, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value, {} ); - }; - } -}); - -tape( 'the function performs a map-reduce operation for each element in an array (array-like object)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = [ -1, -2, -3 ]; - expected = 7; - actual = mapReduceRight( arr, 1, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (typed array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - expected = 7.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (complex number array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( cceil, 1 ); - f2 = naryFunction( cadd, 2 ); - - arr = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5 ] ); - expected = new Complex64( 12.0, 15.0 ); - actual = mapReduceRight( arr, new Complex64( 0.0, 0.0 ), f1, f2 ); - - t.strictEqual( realf( actual ), realf( expected ), 'returns expected value' ); - t.strictEqual( imagf( actual ), imagf( expected ), 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = array( [ -1.0, -2.0, -3.0, -4.0 ], { - 'dtype': 'generic' - }); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray; 0-dimensional)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = ndarray( 'generic', [ -10.0 ], [], [ 0 ], 0, 'row-major' ); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (array-like object)', function test( t ) { - var out = mapReduceRight( [], 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (ndarray)', function test( t ) { - var arr; - var out; - - arr = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 0, 2 ], [ 0, 2, 1 ], 0, 'row-major' ); - out = mapReduceRight( arr, 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function supports providing a `this` context (array-like object)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = [ -1.0, -2.0, -3.0 ]; - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function supports providing a `this` context (ndarray)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = array( [ -1.0, -2.0, -3.0 ], { - 'dtype': 'generic' - }); - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = array( [ 1, , , 4 ], { // eslint-disable-line no-sparse-arrays - 'dtype': 'generic' - }); - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); From 95d2776ea4540dfccd7ab1b035ebc7d726a2659f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 5 Oct 2023 20:26:54 +0000 Subject: [PATCH 43/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index d95cde3..20efedd 100644 --- a/lib/main.js +++ b/lib/main.js @@ -25,7 +25,7 @@ var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); var isFunction = require( '@stdlib/assert-is-function' ); var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ndarrayFcn = require( './ndarray.js' ); var arrayFcn = require( './array.js' ); @@ -90,10 +90,10 @@ var arrayFcn = require( './array.js' ); */ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( !isFunction( mapper ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) ); + throw new TypeError( format( '1VL3N,G4', mapper ) ); } if ( !isFunction( reducer ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) ); + throw new TypeError( format( '1VL32,MM', reducer ) ); } if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len @@ -101,7 +101,7 @@ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( isArrayLikeObject( arr ) ) { return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len } - throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) ); + throw new TypeError( format( '1VLBH,O9', arr ) ); } diff --git a/package.json b/package.json index eac9ddd..eee4b47 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-ndarray-like": "^0.1.0", "@stdlib/ndarray-base-ndarraylike2object": "^0.1.0", "@stdlib/ndarray-base-vind2bind": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.1.0" }, "devDependencies": { From d78d06615f8d9b3c8114295a45ef78125ea0330c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 7 Oct 2023 03:48:05 +0000 Subject: [PATCH 44/91] Remove files --- index.d.ts | 257 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6439 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 ed593f9..0000000 --- a/index.d.ts +++ /dev/null @@ -1,257 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; -import { typedndarray } from '@stdlib/types/ndarray'; - -/** -* Callback invoked for each array element. -* -* @returns result -*/ -type Nullary = () => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @returns result -*/ -type Unary = ( value: T ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @returns result -*/ -type Binary = ( value: T, index: number ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Ternary = ( value: T, index: number, arr: typedndarray ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayTernary = ( value: T, index: number, arr: Collection ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Mapper = Nullary | Unary | Binary | Ternary; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayMapper = Nullary | Unary | Binary | ArrayTernary; - -/** -* Function applied against an accumulator. -* -* @returns accumulator value -*/ -type NullaryReducer = ( this: W ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @returns accumulator value -*/ -type UnaryReducer = ( this: W, accumulator: V ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @returns accumulator value -*/ -type BinaryReducer = ( this: W, accumulator: V, value: U ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @returns accumulator value -*/ -type TernaryReducer = ( this: W, accumulator: V, value: U, index: number ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type QuaternaryReducer = ( this: W, accumulator: V, value: U, index: number, arr: typedndarray ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayQuaternaryReducer = ( this: W, accumulator: V, value: U, index: number, arr: Collection ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type Reducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | QuaternaryReducer; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayReducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | ArrayQuaternaryReducer; - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* var naryFunction = require( `@stdlib/utils/nary-function` ); -* var abs = require( `@stdlib/math/base/special/abs` ); -* var add = require( `@stdlib/math/base/ops/add` ); -* var array = require( `@stdlib/ndarray/array` ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 2 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -declare function mapReduceRight( arr: typedndarray, initial: V, mapper: Mapper, reducer: Reducer, thisArg?: ThisParameterType> ): V; - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -*/ -declare function mapReduceRight( arr: Collection, initial: V, mapper: ArrayMapper, reducer: ArrayReducer, thisArg?: ThisParameterType> ): V; - - -// EXPORTS // - -export = mapReduceRight; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index ffca626..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.1.0-esm/index.mjs";function o(o,a,m,l,j){if(!e(m))throw new TypeError(n("1VL3N,G4",m));if(!e(l))throw new TypeError(n("1VL32,MM",l));if(s(o))return function(r,s,e,t,i){var n,o,a,m,l,j,f,h,c,p,v;if(m=r.length,f=r.shape,n=r.data,h=r.strides,c=r.offset,o=r.order,l=r.accessors[0],j=r.ref,0===f.length)return t.call(i,s,e(l(n,c),0,j),0,j);for(a=s,v=m-1;v>=0;v--)p=d(f,h,c,o,v,"throw"),a=t.call(i,a,e(l(n,p),v,j),v,j);return a}(t(o),a,m,l,j);if(r(o))return function(r,s,e,t,i){var n,d,o,a;for(n=r.data,d=r.accessors[0],o=s,a=n.length-1;a>=0;a--)o=t.call(i,o,e(d(n,a),a,n),a,n);return o}(i(o),a,m,l,j);throw new TypeError(n("1VLBH,O9",o))}export{o as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index d07fb53..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js","../lib/ndarray.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isFunction from '@stdlib/assert-is-function';\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object';\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndarrayFcn from './ndarray.js';\nimport arrayFcn from './array.js';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function';\n* import add from '@stdlib/math-base-ops-add';\n* import abs from '@stdlib/math-base-special-abs';\n* import array from '@stdlib/ndarray-array';\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '1VL3N,G4', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '1VL32,MM', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '1VLBH,O9', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind';\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64';\n* import Complex64 from '@stdlib/complex-float32';\n* import realf from '@stdlib/complex-realf';\n* import imagf from '@stdlib/complex-imagf';\n* import cceil from '@stdlib/math-base-special-cceil';\n* import cadd from '@stdlib/math-base-ops-cadd';\n* import naryFunction from '@stdlib/utils-nary-function';\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","accessors","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;srBA0FA,SAASA,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,WAAYL,IAE1C,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,WAAYJ,IAE1C,GAAKK,EAAeR,GACnB,OCGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,UAAW,GAGnBZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAtH1B,SAuHTR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,CACR,CDnDSkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OE1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,UAAW,GAGnBf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,CACR,CFwBSqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,WAAYP,GAC1C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index bfa2f00..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From cd0f7749e7b10075757eee44395d6a7b184c1d4d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 7 Oct 2023 03:51:52 +0000 Subject: [PATCH 45/91] 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 | 63 +- benchmark/benchmark.array.js | 98 - benchmark/benchmark.ndarray.js | 109 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 9 - dist/index.js.map | 7 - docs/repl.txt | 65 - docs/types/test.ts | 184 - examples/index.js | 52 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/array.js | 83 - lib/index.js | 65 - lib/main.js | 110 - lib/ndarray.js | 155 - package.json | 76 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 637 --- test/test.js | 637 --- 44 files changed, 6213 insertions(+), 5536 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.array.js delete mode 100644 benchmark/benchmark.ndarray.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/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/array.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/ndarray.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.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 3b4c7b4..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/utils/map-reduce-right) 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 f23359f..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/utils/map-reduce-right) 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 d3c6ace..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: '21 21 * * 4' - - # 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 + + ```
@@ -271,7 +264,7 @@ console.log( 'sum: %d', out ); ## 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]. @@ -331,11 +324,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/utils-map-reduce-right/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/stdlib +[@stdlib/array/complex64]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/array/complex128]: https://github.com/stdlib-js/stdlib +[@stdlib/array/complex128]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.array.js b/benchmark/benchmark.array.js deleted file mode 100644 index e87feb5..0000000 --- a/benchmark/benchmark.array.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = filled( -3.0, len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::array:len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.ndarray.js b/benchmark/benchmark.ndarray.js deleted file mode 100644 index e3bfba2..0000000 --- a/benchmark/benchmark.ndarray.js +++ /dev/null @@ -1,109 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var xbuf; - var opts; - var x; - - xbuf = filled( -3.0, len ); - - opts = { - 'dtype': 'generic' - }; - x = array( xbuf, opts ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::ndarray:len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index cd78ec7..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/utils/map-reduce-right" -%% click B href "https://github.com/stdlib-js/utils-map-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-map-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-map-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-map-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-map-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/map-reduce-right -[production-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-map-reduce-right/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 63ea99a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import mapReduceRight from '../docs/types/index'; -export = mapReduceRight; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 3180c8b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,9 +0,0 @@ -"use strict";var g=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var q=g(function(H,m){ -var E=require('@stdlib/ndarray-base-vind2bind/dist'),T="throw";function p(r,e,a,t,s){var i,v,n,u,f,c,l,y,d,b,o;if(u=r.length,l=r.shape,i=r.data,y=r.strides,d=r.offset,v=r.order,f=r.accessors[0],c=r.ref,l.length===0)return t.call(s,e,a(f(i,d),0,c),0,c);for(n=e,o=u-1;o>=0;o--)b=E(l,y,d,v,o,T),n=t.call(s,n,a(f(i,b),o,c),o,c);return n}m.exports=p -});var R=g(function(I,w){ -function x(r,e,a,t,s){var i,v,n,u;for(i=r.data,v=r.accessors[0],n=e,u=i.length-1;u>=0;u--)n=t.call(s,n,a(v(i,u),u,i),u,i);return n}w.exports=x -});var j=g(function(J,F){ -var V=require('@stdlib/assert-is-array-like-object/dist'),L=require('@stdlib/assert-is-ndarray-like/dist'),k=require('@stdlib/assert-is-function/dist'),O=require('@stdlib/ndarray-base-ndarraylike2object/dist'),D=require('@stdlib/array-base-arraylike2object/dist'),h=require('@stdlib/error-tools-fmtprodmsg/dist'),M=q(),z=R();function B(r,e,a,t,s){if(!k(a))throw new TypeError(h('1VL3N',a));if(!k(t))throw new TypeError(h('1VL32',t));if(L(r))return M(O(r),e,a,t,s);if(V(r))return z(D(r),e,a,t,s);throw new TypeError(h('1VLBH',r))}F.exports=B -});var C=j();module.exports=C; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 641859d..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/ndarray.js", "../lib/array.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* var Complex64Array = require( '@stdlib/array-complex64' );\n* var Complex64 = require( '@stdlib/complex-float32' );\n* var realf = require( '@stdlib/complex-realf' );\n* var imagf = require( '@stdlib/complex-imagf' );\n* var cceil = require( '@stdlib/math-base-special-cceil' );\n* var cadd = require( '@stdlib/math-base-ops-cadd' );\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar format = require( '@stdlib/string-format' );\nvar ndarrayFcn = require( './ndarray.js' );\nvar arrayFcn = require( './array.js' );\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/math-base-ops-add' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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* Perform a map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.\n*\n* @module @stdlib/utils-map-reduce-right\n*\n* @example\n* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' );\n*\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, sum );\n* // returns 30\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/math-base-ops-add' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\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,EAAY,QAAS,gCAAiC,EAKtDC,EAAO,QA0EX,SAASC,EAAgBC,EAAGC,EAASC,EAAQC,EAASC,EAAU,CAC/D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMR,EAAE,OAGRW,EAAMX,EAAE,MAGRK,EAAOL,EAAE,KAGTY,EAAKZ,EAAE,QAGPa,EAAKb,EAAE,OAGPM,EAAON,EAAE,MAGTS,EAAMT,EAAE,UAAW,CAAE,EAGrBU,EAAMV,EAAE,IAGHW,EAAI,SAAW,EACnB,OAAOR,EAAQ,KAAMC,EAASH,EAASC,EAAQO,EAAKJ,EAAMQ,CAAG,EAAG,EAAGH,CAAI,EAAG,EAAGA,CAAI,EAIlF,IADAH,EAAMN,EACAc,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKjB,EAAWc,EAAKC,EAAIC,EAAIP,EAAMS,EAAGjB,CAAK,EAC3CS,EAAMJ,EAAQ,KAAMC,EAASG,EAAKL,EAAQO,EAAKJ,EAAMS,CAAG,EAAGC,EAAGL,CAAI,EAAGK,EAAGL,CAAI,EAE7E,OAAOH,CACR,CAKAX,EAAO,QAAUG,IC1JjB,IAAAiB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA2DA,SAASC,EAAgBC,EAAGC,EAASC,EAAQC,EAASC,EAAU,CAC/D,IAAIC,EACAC,EACAC,EACAC,EAUJ,IAPAH,EAAOL,EAAE,KAGTM,EAAMN,EAAE,UAAW,CAAE,EAGrBO,EAAMN,EACAO,EAAIH,EAAK,OAAO,EAAGG,GAAK,EAAGA,IAChCD,EAAMJ,EAAQ,KAAMC,EAASG,EAAKL,EAAQI,EAAKD,EAAMG,CAAE,EAAGA,EAAGH,CAAK,EAAGG,EAAGH,CAAK,EAE9E,OAAOE,CACR,CAKAT,EAAO,QAAUC,IClFjB,IAAAU,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAoB,QAAS,qCAAsC,EACnEC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,4BAA6B,EACnDC,EAAqB,QAAS,yCAA0C,EACxEC,EAAmB,QAAS,qCAAsC,EAClEC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAW,IA6Df,SAASC,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,EAAU,CACjE,GAAK,CAACX,EAAYS,CAAO,EACxB,MAAM,IAAI,UAAWN,EAAQ,oEAAqEM,CAAO,CAAE,EAE5G,GAAK,CAACT,EAAYU,CAAQ,EACzB,MAAM,IAAI,UAAWP,EAAQ,qEAAsEO,CAAQ,CAAE,EAE9G,GAAKX,EAAeQ,CAAI,EACvB,OAAOH,EAAYH,EAAoBM,CAAI,EAAGC,EAASC,EAAQC,EAASC,CAAQ,EAEjF,GAAKb,EAAmBS,CAAI,EAC3B,OAAOF,EAAUH,EAAkBK,CAAI,EAAGC,EAASC,EAAQC,EAASC,CAAQ,EAE7E,MAAM,IAAI,UAAWR,EAAQ,4FAA6FI,CAAI,CAAE,CACjI,CAKAV,EAAO,QAAUS,IClDjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_ndarray", "__commonJSMin", "exports", "module", "vind2bind", "MODE", "mapReduceRight", "x", "initial", "mapper", "reducer", "thisArg", "xbuf", "ordx", "acc", "len", "get", "ref", "shx", "sx", "ox", "ix", "i", "require_array", "__commonJSMin", "exports", "module", "mapReduceRight", "x", "initial", "mapper", "reducer", "thisArg", "xbuf", "get", "acc", "i", "require_main", "__commonJSMin", "exports", "module", "isArrayLikeObject", "isndarrayLike", "isFunction", "ndarraylike2object", "arraylike2object", "format", "ndarrayFcn", "arrayFcn", "mapReduceRight", "arr", "initial", "mapper", "reducer", "thisArg", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b580e87..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, initial, mapper, reducer[, thisArg] ) - Performs a map-reduce operation for each element in an array while iterating - from right to left and returns the accumulated result. - - When invoked, the mapping function is provided three arguments: - - - value: array element. - - index: element index. - - arr: input array. - - When invoked, the reducing function is provided four arguments: - - - accumulator: accumulated value. - - value: result after applying the mapping function to the current array - element. - - index: element index. - - arr: input array. - - If provided an empty array, the function returns the initial value. - - When provided an ndarray, the function performs a single-pass map-reduce - operation over the entire input ndarray (i.e., higher-order ndarray - dimensions are flattened to a single-dimension). - - Parameters - ---------- - arr: ArrayLikeObject|ndarray - Input array. - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - mapper: Function - Mapping function. - - reducer: Function - Reducing function. - - thisArg: any (optional) - Execution context for the reducing function. - - Returns - ------- - out: any - Accumulated result. - - Examples - -------- - // array-like object: - > var f1 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/special/abs}}, 1 ); - > var f2 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/ops/add}}, 2 ); - > var arr = [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0 ]; - > var out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - // ndarray: - > arr = {{alias:@stdlib/ndarray/array}}( arr, { 'shape': [ 2, 3 ] } ); - > out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 3fcccbb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,184 +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. -*/ - -import array = require( '@stdlib/ndarray-array' ); -import mapReduceRight = require( './index' ); - -/** -* Mapping function. -* -* @param value - array element -* @returns result -*/ -function mapper( value: number ): number { - return value; -} - -/** -* Reducing function. -* -* @param acc - accumulated value -* @param v - array element -* @returns result -*/ -function reducer( acc: number, value: number ): number { - return acc + value; -} - - -// TESTS // - -// The function returns the accumulated value when provided a collection... -{ - mapReduceRight( [ 0, 1, 1, NaN, 2 ], 0, mapper, reducer ); // $ExpectType number - mapReduceRight( [ -1, 1, 2 ], 100, mapper, reducer ); // $ExpectType number - mapReduceRight( [ -1, 1, 2 ], 0, mapper, reducer, {} ); // $ExpectType number -} - -// The function returns the accumulated value when provided an ndarray... -{ - const arr = array( [ 1, 2, 3, 4, 5, 6 ] ); - - mapReduceRight( arr, 0, mapper, reducer ); // $ExpectType number - mapReduceRight( arr, 100, mapper, reducer ); // $ExpectType number - mapReduceRight( arr, 0, mapper, reducer, {} ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not a collection or ndarray... -{ - mapReduceRight( 2, 0, mapper, reducer ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer ); // $ExpectError - - mapReduceRight( 2, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr1, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr2, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const arr1 = [ 1, 2, 3 ]; - - mapReduceRight(); // $ExpectError - mapReduceRight( arr1 ); // $ExpectError - mapReduceRight( arr1, 0 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ); // $ExpectError - mapReduceRight( arr1, 0, mapper, reducer, {}, 3 ); // $ExpectError - - const arr2 = array( [ 1, 2, 3 ] ); - - mapReduceRight(); // $ExpectError - mapReduceRight( arr2 ); // $ExpectError - mapReduceRight( arr2, 0 ); // $ExpectError - mapReduceRight( arr2, 0, mapper ); // $ExpectError - mapReduceRight( arr2, 0, mapper, reducer, {}, 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 7474059..0000000 --- a/examples/index.js +++ /dev/null @@ -1,52 +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. -*/ - -'use strict'; - -var filledarrayBy = require( '@stdlib/array-filled-by' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ).factory; -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var mapReduceRight = require( './../lib' ); - -function fill( i ) { - var rand = discreteUniform( -10*(i+1), 10*(i+1) ); - return filledarrayBy( 10, 'generic', rand ); -} - -// Create a two-dimensional ndarray (i.e., a matrix): -var x = array( filledarrayBy( 10, 'generic', fill ), { - 'dtype': 'generic', - 'flatten': true -}); - -// Create an explicit unary function: -var f1 = naryFunction( abs, 1 ); - -// Create an explicit binary function: -var f2 = naryFunction( add, 2 ); - -// Compute the sum of absolute values: -var out = mapReduceRight( x, 0, f1, f2 ); - -console.log( 'x:' ); -console.log( x.data ); - -console.log( 'sum: %d', out ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 2d0e5da..ed593f9 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; import { typedndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..b9d643d --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.1.1-esm/index.mjs";function o(o,a,m,l,j){if(!e(m))throw new TypeError(n("1VL3N,G4",m));if(!e(l))throw new TypeError(n("1VL32,MM",l));if(s(o))return function(r,s,e,t,i){var n,o,a,m,l,j,f,h,c,p,v;if(m=r.length,f=r.shape,n=r.data,h=r.strides,c=r.offset,o=r.order,l=r.accessors[0],j=r.ref,0===f.length)return t.call(i,s,e(l(n,c),0,j),0,j);for(a=s,v=m-1;v>=0;v--)p=d(f,h,c,o,v,"throw"),a=t.call(i,a,e(l(n,p),v,j),v,j);return a}(t(o),a,m,l,j);if(r(o))return function(r,s,e,t,i){var n,d,o,a;for(n=r.data,d=r.accessors[0],o=s,a=n.length-1;a>=0;a--)o=t.call(i,o,e(d(n,a),a,n),a,n);return o}(i(o),a,m,l,j);throw new TypeError(n("1VLBH,O9",o))}export{o as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..d07fb53 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js","../lib/ndarray.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isFunction from '@stdlib/assert-is-function';\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object';\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndarrayFcn from './ndarray.js';\nimport arrayFcn from './array.js';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function';\n* import add from '@stdlib/math-base-ops-add';\n* import abs from '@stdlib/math-base-special-abs';\n* import array from '@stdlib/ndarray-array';\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '1VL3N,G4', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '1VL32,MM', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '1VLBH,O9', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind';\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64';\n* import Complex64 from '@stdlib/complex-float32';\n* import realf from '@stdlib/complex-realf';\n* import imagf from '@stdlib/complex-imagf';\n* import cceil from '@stdlib/math-base-special-cceil';\n* import cadd from '@stdlib/math-base-ops-cadd';\n* import naryFunction from '@stdlib/utils-nary-function';\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","accessors","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;srBA0FA,SAASA,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,WAAYL,IAE1C,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,WAAYJ,IAE1C,GAAKK,EAAeR,GACnB,OCGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,UAAW,GAGnBZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAtH1B,SAuHTR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,CACR,CDnDSkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OE1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,UAAW,GAGnBf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,CACR,CFwBSqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,WAAYP,GAC1C"} \ No newline at end of file diff --git a/lib/array.js b/lib/array.js deleted file mode 100644 index 69c0a8c..0000000 --- a/lib/array.js +++ /dev/null @@ -1,83 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input array data -* @param {ArrayLikeObject} x.data - input array data -* @param {Array} x.accessors - input array accessors -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf[ idx ]; -* } -* -* // Create the input array object: -* var x = { -* 'data': [ 1, 2, 3, 4 ], -* 'accessors': [ getter ] -* }; -* -* // Compute the sum of squared values: -* var out = mapReduceRight( x, 0, square, sum ); -* // returns 30 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var get; - var acc; - var i; - - // Cache reference to the input data: - xbuf = x.data; - - // Cache the element accessor: - get = x.accessors[ 0 ]; - - // Iterate over each element... - acc = initial; - for ( i = xbuf.length-1; i >= 0; i-- ) { - acc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 522693e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +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. -*/ - -'use strict'; - -/** -* Perform a map-reduce operation against each element in an array while iterating from right to left and return the accumulated result. -* -* @module @stdlib/utils-map-reduce-right -* -* @example -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ - -// 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 20efedd..0000000 --- a/lib/main.js +++ /dev/null @@ -1,110 +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. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ndarrayFcn = require( './ndarray.js' ); -var arrayFcn = require( './array.js' ); - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided the following arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided the following arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result of applying the mapping function against the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* @param {(ArrayLikeObject|ndarray)} arr - input array -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} [thisArg] - reduction function execution context -* @throws {TypeError} first argument must be an array-like object or an ndarray -* @throws {TypeError} third argument must be a function -* @throws {TypeError} fourth argument must be a function -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { - if ( !isFunction( mapper ) ) { - throw new TypeError( format( '1VL3N,G4', mapper ) ); - } - if ( !isFunction( reducer ) ) { - throw new TypeError( format( '1VL32,MM', reducer ) ); - } - if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like - return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - if ( isArrayLikeObject( arr ) ) { - return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - throw new TypeError( format( '1VLBH,O9', arr ) ); -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/ndarray.js b/lib/ndarray.js deleted file mode 100644 index 06e19a5..0000000 --- a/lib/ndarray.js +++ /dev/null @@ -1,155 +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. -*/ - -'use strict'; - -// MODULES // - -var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); - - -// VARIABLES // - -var MODE = 'throw'; - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input ndarray meta data -* @param {string} x.ref - reference to original input ndarray-like object -* @param {string} x.dtype - data type -* @param {Collection} x.data - data buffer -* @param {NonNegativeInteger} x.length - number of elements -* @param {NonNegativeIntegerArray} x.shape - dimensions -* @param {IntegerArray} x.strides - stride lengths -* @param {NonNegativeInteger} x.offset - index offset -* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) -* @param {Array} x.accessors - accessors for accessing data buffer elements -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var Complex64 = require( '@stdlib/complex-float32' ); -* var realf = require( '@stdlib/complex-realf' ); -* var imagf = require( '@stdlib/complex-imagf' ); -* var cceil = require( '@stdlib/math-base-special-cceil' ); -* var cadd = require( '@stdlib/math-base-ops-cadd' ); -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* -* // Create a data buffer: -* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] ); -* -* // Define the shape of the input array: -* var shape = [ 2, 2 ]; -* -* // Define the array strides: -* var sx = [ 2, 1 ]; -* -* // Define the index offset: -* var ox = 0; -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf.get( idx ); -* } -* -* // Create the input ndarray-like object: -* var x = { -* 'ref': null, -* 'dtype': 'complex64', -* 'data': xbuf, -* 'length': 4, -* 'shape': shape, -* 'strides': sx, -* 'offset': ox, -* 'order': 'row-major', -* 'accessors': [ getter ] -* }; -* x.ref = x; -* -* // Compute the sum: -* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) ); -* -* var re = realf( v ); -* // returns 20.0 -* -* var im = imagf( v ); -* // returns 24.0 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var ordx; - var acc; - var len; - var get; - var ref; - var shx; - var sx; - var ox; - var ix; - var i; - - // Cache the total number of elements over which to iterate: - len = x.length; - - // Cache the input array shape: - shx = x.shape; - - // Cache reference to the input ndarray data buffer: - xbuf = x.data; - - // Cache reference to the stride array: - sx = x.strides; - - // Cache the index of the first indexed element: - ox = x.offset; - - // Cache the array order: - ordx = x.order; - - // Cache the element accessor: - get = x.accessors[ 0 ]; - - // Cache the reference to the original input array: - ref = x.ref; - - // Check for a zero-dimensional array... - if ( shx.length === 0 ) { - return reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len - } - // Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)... - acc = initial; - for ( i = len-1; i >= 0; i-- ) { - ix = vind2bind( shx, sx, ox, ordx, i, MODE ); - acc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/package.json b/package.json index eee4b47..75d88cc 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Perform a single-pass map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.", "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/array-base-arraylike2object": "^0.1.0", - "@stdlib/assert-is-array-like-object": "^0.1.0", - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/ndarray-base-ndarraylike2object": "^0.1.0", - "@stdlib/ndarray-base-vind2bind": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-base-filled": "^0.1.0", - "@stdlib/array-complex64": "^0.1.0", - "@stdlib/array-filled-by": "^0.1.0", - "@stdlib/array-float64": "^0.1.0", - "@stdlib/bench": "^0.1.0", - "@stdlib/complex-float32": "^0.1.0", - "@stdlib/complex-imagf": "^0.1.0", - "@stdlib/complex-realf": "^0.1.0", - "@stdlib/math-base-assert-is-nan": "^0.1.1", - "@stdlib/math-base-ops-add": "^0.1.0", - "@stdlib/math-base-ops-cadd": "^0.1.0", - "@stdlib/math-base-special-abs": "^0.1.0", - "@stdlib/math-base-special-cceil": "^0.1.0", - "@stdlib/math-base-special-pow": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/random-base-discrete-uniform": "^0.1.0", - "@stdlib/utils-nary-function": "^0.1.0", - "@stdlib/utils-noop": "^0.1.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" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..a8bf954 --- /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 67461fc..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,637 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var cadd = require( '@stdlib/math-base-ops-cadd' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var cceil = require( '@stdlib/math-base-special-cceil' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var mapReduceRight = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapReduceRight, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a first argument which is either an array-like object or an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( value, 0, noop, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value, {} ); - }; - } -}); - -tape( 'the function performs a map-reduce operation for each element in an array (array-like object)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = [ -1, -2, -3 ]; - expected = 7; - actual = mapReduceRight( arr, 1, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (typed array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - expected = 7.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (complex number array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( cceil, 1 ); - f2 = naryFunction( cadd, 2 ); - - arr = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5 ] ); - expected = new Complex64( 12.0, 15.0 ); - actual = mapReduceRight( arr, new Complex64( 0.0, 0.0 ), f1, f2 ); - - t.strictEqual( realf( actual ), realf( expected ), 'returns expected value' ); - t.strictEqual( imagf( actual ), imagf( expected ), 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = array( [ -1.0, -2.0, -3.0, -4.0 ], { - 'dtype': 'generic' - }); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray; 0-dimensional)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = ndarray( 'generic', [ -10.0 ], [], [ 0 ], 0, 'row-major' ); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (array-like object)', function test( t ) { - var out = mapReduceRight( [], 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (ndarray)', function test( t ) { - var arr; - var out; - - arr = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 0, 2 ], [ 0, 2, 1 ], 0, 'row-major' ); - out = mapReduceRight( arr, 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function supports providing a `this` context (array-like object)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = [ -1.0, -2.0, -3.0 ]; - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function supports providing a `this` context (ndarray)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = array( [ -1.0, -2.0, -3.0 ], { - 'dtype': 'generic' - }); - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = array( [ 1, , , 4 ], { // eslint-disable-line no-sparse-arrays - 'dtype': 'generic' - }); - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 2c78efa..0000000 --- a/test/test.js +++ /dev/null @@ -1,637 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var cadd = require( '@stdlib/math-base-ops-cadd' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var cceil = require( '@stdlib/math-base-special-cceil' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var mapReduceRight = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapReduceRight, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a first argument which is either an array-like object or an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( value, 0, noop, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value, {} ); - }; - } -}); - -tape( 'the function performs a map-reduce operation for each element in an array (array-like object)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = [ -1, -2, -3 ]; - expected = 7; - actual = mapReduceRight( arr, 1, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (typed array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - expected = 7.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (complex number array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( cceil, 1 ); - f2 = naryFunction( cadd, 2 ); - - arr = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5 ] ); - expected = new Complex64( 12.0, 15.0 ); - actual = mapReduceRight( arr, new Complex64( 0.0, 0.0 ), f1, f2 ); - - t.strictEqual( realf( actual ), realf( expected ), 'returns expected value' ); - t.strictEqual( imagf( actual ), imagf( expected ), 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = array( [ -1.0, -2.0, -3.0, -4.0 ], { - 'dtype': 'generic' - }); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray; 0-dimensional)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = ndarray( 'generic', [ -10.0 ], [], [ 0 ], 0, 'row-major' ); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (array-like object)', function test( t ) { - var out = mapReduceRight( [], 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (ndarray)', function test( t ) { - var arr; - var out; - - arr = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 0, 2 ], [ 0, 2, 1 ], 0, 'row-major' ); - out = mapReduceRight( arr, 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function supports providing a `this` context (array-like object)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = [ -1.0, -2.0, -3.0 ]; - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function supports providing a `this` context (ndarray)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = array( [ -1.0, -2.0, -3.0 ], { - 'dtype': 'generic' - }); - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = array( [ 1, , , 4 ], { // eslint-disable-line no-sparse-arrays - 'dtype': 'generic' - }); - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); From bfe3b585429faf48a997b2a56297d4219c727c33 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Nov 2023 18:12:17 +0000 Subject: [PATCH 46/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index d95cde3..20efedd 100644 --- a/lib/main.js +++ b/lib/main.js @@ -25,7 +25,7 @@ var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); var isFunction = require( '@stdlib/assert-is-function' ); var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ndarrayFcn = require( './ndarray.js' ); var arrayFcn = require( './array.js' ); @@ -90,10 +90,10 @@ var arrayFcn = require( './array.js' ); */ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( !isFunction( mapper ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) ); + throw new TypeError( format( '1VL3N,G4', mapper ) ); } if ( !isFunction( reducer ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) ); + throw new TypeError( format( '1VL32,MM', reducer ) ); } if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len @@ -101,7 +101,7 @@ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( isArrayLikeObject( arr ) ) { return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len } - throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) ); + throw new TypeError( format( '1VLBH,O9', arr ) ); } diff --git a/package.json b/package.json index a6fadcf..0c55c59 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-ndarray-like": "^0.1.0", "@stdlib/ndarray-base-ndarraylike2object": "^0.1.0", "@stdlib/ndarray-base-vind2bind": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.1.0" }, "devDependencies": { From f433ae36cd5b7f2b472f971d99e35849a996001c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 3 Nov 2023 02:56:02 +0000 Subject: [PATCH 47/91] Remove files --- index.d.ts | 257 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6439 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 ed593f9..0000000 --- a/index.d.ts +++ /dev/null @@ -1,257 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; -import { typedndarray } from '@stdlib/types/ndarray'; - -/** -* Callback invoked for each array element. -* -* @returns result -*/ -type Nullary = () => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @returns result -*/ -type Unary = ( value: T ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @returns result -*/ -type Binary = ( value: T, index: number ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Ternary = ( value: T, index: number, arr: typedndarray ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayTernary = ( value: T, index: number, arr: Collection ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Mapper = Nullary | Unary | Binary | Ternary; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayMapper = Nullary | Unary | Binary | ArrayTernary; - -/** -* Function applied against an accumulator. -* -* @returns accumulator value -*/ -type NullaryReducer = ( this: W ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @returns accumulator value -*/ -type UnaryReducer = ( this: W, accumulator: V ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @returns accumulator value -*/ -type BinaryReducer = ( this: W, accumulator: V, value: U ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @returns accumulator value -*/ -type TernaryReducer = ( this: W, accumulator: V, value: U, index: number ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type QuaternaryReducer = ( this: W, accumulator: V, value: U, index: number, arr: typedndarray ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayQuaternaryReducer = ( this: W, accumulator: V, value: U, index: number, arr: Collection ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type Reducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | QuaternaryReducer; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayReducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | ArrayQuaternaryReducer; - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* var naryFunction = require( `@stdlib/utils/nary-function` ); -* var abs = require( `@stdlib/math/base/special/abs` ); -* var add = require( `@stdlib/math/base/ops/add` ); -* var array = require( `@stdlib/ndarray/array` ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 2 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -declare function mapReduceRight( arr: typedndarray, initial: V, mapper: Mapper, reducer: Reducer, thisArg?: ThisParameterType> ): V; - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -*/ -declare function mapReduceRight( arr: Collection, initial: V, mapper: ArrayMapper, reducer: ArrayReducer, thisArg?: ThisParameterType> ): V; - - -// EXPORTS // - -export = mapReduceRight; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index b9d643d..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.1.1-esm/index.mjs";function o(o,a,m,l,j){if(!e(m))throw new TypeError(n("1VL3N,G4",m));if(!e(l))throw new TypeError(n("1VL32,MM",l));if(s(o))return function(r,s,e,t,i){var n,o,a,m,l,j,f,h,c,p,v;if(m=r.length,f=r.shape,n=r.data,h=r.strides,c=r.offset,o=r.order,l=r.accessors[0],j=r.ref,0===f.length)return t.call(i,s,e(l(n,c),0,j),0,j);for(a=s,v=m-1;v>=0;v--)p=d(f,h,c,o,v,"throw"),a=t.call(i,a,e(l(n,p),v,j),v,j);return a}(t(o),a,m,l,j);if(r(o))return function(r,s,e,t,i){var n,d,o,a;for(n=r.data,d=r.accessors[0],o=s,a=n.length-1;a>=0;a--)o=t.call(i,o,e(d(n,a),a,n),a,n);return o}(i(o),a,m,l,j);throw new TypeError(n("1VLBH,O9",o))}export{o as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index d07fb53..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js","../lib/ndarray.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isFunction from '@stdlib/assert-is-function';\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object';\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndarrayFcn from './ndarray.js';\nimport arrayFcn from './array.js';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function';\n* import add from '@stdlib/math-base-ops-add';\n* import abs from '@stdlib/math-base-special-abs';\n* import array from '@stdlib/ndarray-array';\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '1VL3N,G4', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '1VL32,MM', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '1VLBH,O9', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind';\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64';\n* import Complex64 from '@stdlib/complex-float32';\n* import realf from '@stdlib/complex-realf';\n* import imagf from '@stdlib/complex-imagf';\n* import cceil from '@stdlib/math-base-special-cceil';\n* import cadd from '@stdlib/math-base-ops-cadd';\n* import naryFunction from '@stdlib/utils-nary-function';\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","accessors","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;srBA0FA,SAASA,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,WAAYL,IAE1C,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,WAAYJ,IAE1C,GAAKK,EAAeR,GACnB,OCGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,UAAW,GAGnBZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAtH1B,SAuHTR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,CACR,CDnDSkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OE1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,UAAW,GAGnBf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,CACR,CFwBSqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,WAAYP,GAC1C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index a8bf954..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 10bfd6018e09acf760175691920865d72b590269 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 3 Nov 2023 02:59:28 +0000 Subject: [PATCH 48/91] Auto-generated commit --- .editorconfig | 186 - .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 | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 63 +- benchmark/benchmark.array.js | 98 - benchmark/benchmark.ndarray.js | 109 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 9 - dist/index.js.map | 7 - docs/repl.txt | 65 - docs/types/test.ts | 184 - examples/index.js | 52 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/array.js | 83 - lib/index.js | 65 - lib/main.js | 110 - lib/ndarray.js | 155 - package.json | 76 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 637 --- 45 files changed, 6213 insertions(+), 4941 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 benchmark/benchmark.array.js delete mode 100644 benchmark/benchmark.ndarray.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/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/array.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/ndarray.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.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/.keepalive b/.github/.keepalive deleted file mode 100644 index b97135e..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-11-01T05:59:02.679Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3b4c7b4..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/utils/map-reduce-right) 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 f23359f..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/utils/map-reduce-right) 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 d3c6ace..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: '21 21 * * 4' - - # 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 + + ```
@@ -271,7 +264,7 @@ console.log( 'sum: %d', out ); ## 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]. @@ -331,11 +324,11 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/utils-map-reduce-right/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/stdlib +[@stdlib/array/complex64]: https://github.com/stdlib-js/stdlib/tree/esm -[@stdlib/array/complex128]: https://github.com/stdlib-js/stdlib +[@stdlib/array/complex128]: https://github.com/stdlib-js/stdlib/tree/esm
diff --git a/benchmark/benchmark.array.js b/benchmark/benchmark.array.js deleted file mode 100644 index e87feb5..0000000 --- a/benchmark/benchmark.array.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = filled( -3.0, len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::array:len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.ndarray.js b/benchmark/benchmark.ndarray.js deleted file mode 100644 index e3bfba2..0000000 --- a/benchmark/benchmark.ndarray.js +++ /dev/null @@ -1,109 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var xbuf; - var opts; - var x; - - xbuf = filled( -3.0, len ); - - opts = { - 'dtype': 'generic' - }; - x = array( xbuf, opts ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::ndarray:len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index cd78ec7..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/utils/map-reduce-right" -%% click B href "https://github.com/stdlib-js/utils-map-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-map-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-map-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-map-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-map-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/map-reduce-right -[production-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-map-reduce-right/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 63ea99a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import mapReduceRight from '../docs/types/index'; -export = mapReduceRight; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 3180c8b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,9 +0,0 @@ -"use strict";var g=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var q=g(function(H,m){ -var E=require('@stdlib/ndarray-base-vind2bind/dist'),T="throw";function p(r,e,a,t,s){var i,v,n,u,f,c,l,y,d,b,o;if(u=r.length,l=r.shape,i=r.data,y=r.strides,d=r.offset,v=r.order,f=r.accessors[0],c=r.ref,l.length===0)return t.call(s,e,a(f(i,d),0,c),0,c);for(n=e,o=u-1;o>=0;o--)b=E(l,y,d,v,o,T),n=t.call(s,n,a(f(i,b),o,c),o,c);return n}m.exports=p -});var R=g(function(I,w){ -function x(r,e,a,t,s){var i,v,n,u;for(i=r.data,v=r.accessors[0],n=e,u=i.length-1;u>=0;u--)n=t.call(s,n,a(v(i,u),u,i),u,i);return n}w.exports=x -});var j=g(function(J,F){ -var V=require('@stdlib/assert-is-array-like-object/dist'),L=require('@stdlib/assert-is-ndarray-like/dist'),k=require('@stdlib/assert-is-function/dist'),O=require('@stdlib/ndarray-base-ndarraylike2object/dist'),D=require('@stdlib/array-base-arraylike2object/dist'),h=require('@stdlib/error-tools-fmtprodmsg/dist'),M=q(),z=R();function B(r,e,a,t,s){if(!k(a))throw new TypeError(h('1VL3N',a));if(!k(t))throw new TypeError(h('1VL32',t));if(L(r))return M(O(r),e,a,t,s);if(V(r))return z(D(r),e,a,t,s);throw new TypeError(h('1VLBH',r))}F.exports=B -});var C=j();module.exports=C; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 641859d..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/ndarray.js", "../lib/array.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* var Complex64Array = require( '@stdlib/array-complex64' );\n* var Complex64 = require( '@stdlib/complex-float32' );\n* var realf = require( '@stdlib/complex-realf' );\n* var imagf = require( '@stdlib/complex-imagf' );\n* var cceil = require( '@stdlib/math-base-special-cceil' );\n* var cadd = require( '@stdlib/math-base-ops-cadd' );\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar format = require( '@stdlib/string-format' );\nvar ndarrayFcn = require( './ndarray.js' );\nvar arrayFcn = require( './array.js' );\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/math-base-ops-add' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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* Perform a map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.\n*\n* @module @stdlib/utils-map-reduce-right\n*\n* @example\n* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' );\n*\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, sum );\n* // returns 30\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/math-base-ops-add' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\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,EAAY,QAAS,gCAAiC,EAKtDC,EAAO,QA0EX,SAASC,EAAgBC,EAAGC,EAASC,EAAQC,EAASC,EAAU,CAC/D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMR,EAAE,OAGRW,EAAMX,EAAE,MAGRK,EAAOL,EAAE,KAGTY,EAAKZ,EAAE,QAGPa,EAAKb,EAAE,OAGPM,EAAON,EAAE,MAGTS,EAAMT,EAAE,UAAW,CAAE,EAGrBU,EAAMV,EAAE,IAGHW,EAAI,SAAW,EACnB,OAAOR,EAAQ,KAAMC,EAASH,EAASC,EAAQO,EAAKJ,EAAMQ,CAAG,EAAG,EAAGH,CAAI,EAAG,EAAGA,CAAI,EAIlF,IADAH,EAAMN,EACAc,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKjB,EAAWc,EAAKC,EAAIC,EAAIP,EAAMS,EAAGjB,CAAK,EAC3CS,EAAMJ,EAAQ,KAAMC,EAASG,EAAKL,EAAQO,EAAKJ,EAAMS,CAAG,EAAGC,EAAGL,CAAI,EAAGK,EAAGL,CAAI,EAE7E,OAAOH,CACR,CAKAX,EAAO,QAAUG,IC1JjB,IAAAiB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA2DA,SAASC,EAAgBC,EAAGC,EAASC,EAAQC,EAASC,EAAU,CAC/D,IAAIC,EACAC,EACAC,EACAC,EAUJ,IAPAH,EAAOL,EAAE,KAGTM,EAAMN,EAAE,UAAW,CAAE,EAGrBO,EAAMN,EACAO,EAAIH,EAAK,OAAO,EAAGG,GAAK,EAAGA,IAChCD,EAAMJ,EAAQ,KAAMC,EAASG,EAAKL,EAAQI,EAAKD,EAAMG,CAAE,EAAGA,EAAGH,CAAK,EAAGG,EAAGH,CAAK,EAE9E,OAAOE,CACR,CAKAT,EAAO,QAAUC,IClFjB,IAAAU,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAoB,QAAS,qCAAsC,EACnEC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,4BAA6B,EACnDC,EAAqB,QAAS,yCAA0C,EACxEC,EAAmB,QAAS,qCAAsC,EAClEC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAW,IA6Df,SAASC,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,EAAU,CACjE,GAAK,CAACX,EAAYS,CAAO,EACxB,MAAM,IAAI,UAAWN,EAAQ,oEAAqEM,CAAO,CAAE,EAE5G,GAAK,CAACT,EAAYU,CAAQ,EACzB,MAAM,IAAI,UAAWP,EAAQ,qEAAsEO,CAAQ,CAAE,EAE9G,GAAKX,EAAeQ,CAAI,EACvB,OAAOH,EAAYH,EAAoBM,CAAI,EAAGC,EAASC,EAAQC,EAASC,CAAQ,EAEjF,GAAKb,EAAmBS,CAAI,EAC3B,OAAOF,EAAUH,EAAkBK,CAAI,EAAGC,EAASC,EAAQC,EAASC,CAAQ,EAE7E,MAAM,IAAI,UAAWR,EAAQ,4FAA6FI,CAAI,CAAE,CACjI,CAKAV,EAAO,QAAUS,IClDjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_ndarray", "__commonJSMin", "exports", "module", "vind2bind", "MODE", "mapReduceRight", "x", "initial", "mapper", "reducer", "thisArg", "xbuf", "ordx", "acc", "len", "get", "ref", "shx", "sx", "ox", "ix", "i", "require_array", "__commonJSMin", "exports", "module", "mapReduceRight", "x", "initial", "mapper", "reducer", "thisArg", "xbuf", "get", "acc", "i", "require_main", "__commonJSMin", "exports", "module", "isArrayLikeObject", "isndarrayLike", "isFunction", "ndarraylike2object", "arraylike2object", "format", "ndarrayFcn", "arrayFcn", "mapReduceRight", "arr", "initial", "mapper", "reducer", "thisArg", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b580e87..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, initial, mapper, reducer[, thisArg] ) - Performs a map-reduce operation for each element in an array while iterating - from right to left and returns the accumulated result. - - When invoked, the mapping function is provided three arguments: - - - value: array element. - - index: element index. - - arr: input array. - - When invoked, the reducing function is provided four arguments: - - - accumulator: accumulated value. - - value: result after applying the mapping function to the current array - element. - - index: element index. - - arr: input array. - - If provided an empty array, the function returns the initial value. - - When provided an ndarray, the function performs a single-pass map-reduce - operation over the entire input ndarray (i.e., higher-order ndarray - dimensions are flattened to a single-dimension). - - Parameters - ---------- - arr: ArrayLikeObject|ndarray - Input array. - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - mapper: Function - Mapping function. - - reducer: Function - Reducing function. - - thisArg: any (optional) - Execution context for the reducing function. - - Returns - ------- - out: any - Accumulated result. - - Examples - -------- - // array-like object: - > var f1 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/special/abs}}, 1 ); - > var f2 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/ops/add}}, 2 ); - > var arr = [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0 ]; - > var out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - // ndarray: - > arr = {{alias:@stdlib/ndarray/array}}( arr, { 'shape': [ 2, 3 ] } ); - > out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 3fcccbb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,184 +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. -*/ - -import array = require( '@stdlib/ndarray-array' ); -import mapReduceRight = require( './index' ); - -/** -* Mapping function. -* -* @param value - array element -* @returns result -*/ -function mapper( value: number ): number { - return value; -} - -/** -* Reducing function. -* -* @param acc - accumulated value -* @param v - array element -* @returns result -*/ -function reducer( acc: number, value: number ): number { - return acc + value; -} - - -// TESTS // - -// The function returns the accumulated value when provided a collection... -{ - mapReduceRight( [ 0, 1, 1, NaN, 2 ], 0, mapper, reducer ); // $ExpectType number - mapReduceRight( [ -1, 1, 2 ], 100, mapper, reducer ); // $ExpectType number - mapReduceRight( [ -1, 1, 2 ], 0, mapper, reducer, {} ); // $ExpectType number -} - -// The function returns the accumulated value when provided an ndarray... -{ - const arr = array( [ 1, 2, 3, 4, 5, 6 ] ); - - mapReduceRight( arr, 0, mapper, reducer ); // $ExpectType number - mapReduceRight( arr, 100, mapper, reducer ); // $ExpectType number - mapReduceRight( arr, 0, mapper, reducer, {} ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not a collection or ndarray... -{ - mapReduceRight( 2, 0, mapper, reducer ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer ); // $ExpectError - - mapReduceRight( 2, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr1, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr2, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const arr1 = [ 1, 2, 3 ]; - - mapReduceRight(); // $ExpectError - mapReduceRight( arr1 ); // $ExpectError - mapReduceRight( arr1, 0 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ); // $ExpectError - mapReduceRight( arr1, 0, mapper, reducer, {}, 3 ); // $ExpectError - - const arr2 = array( [ 1, 2, 3 ] ); - - mapReduceRight(); // $ExpectError - mapReduceRight( arr2 ); // $ExpectError - mapReduceRight( arr2, 0 ); // $ExpectError - mapReduceRight( arr2, 0, mapper ); // $ExpectError - mapReduceRight( arr2, 0, mapper, reducer, {}, 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 7474059..0000000 --- a/examples/index.js +++ /dev/null @@ -1,52 +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. -*/ - -'use strict'; - -var filledarrayBy = require( '@stdlib/array-filled-by' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ).factory; -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var mapReduceRight = require( './../lib' ); - -function fill( i ) { - var rand = discreteUniform( -10*(i+1), 10*(i+1) ); - return filledarrayBy( 10, 'generic', rand ); -} - -// Create a two-dimensional ndarray (i.e., a matrix): -var x = array( filledarrayBy( 10, 'generic', fill ), { - 'dtype': 'generic', - 'flatten': true -}); - -// Create an explicit unary function: -var f1 = naryFunction( abs, 1 ); - -// Create an explicit binary function: -var f2 = naryFunction( add, 2 ); - -// Compute the sum of absolute values: -var out = mapReduceRight( x, 0, f1, f2 ); - -console.log( 'x:' ); -console.log( x.data ); - -console.log( 'sum: %d', out ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 2d0e5da..ed593f9 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; import { typedndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..b9d643d --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.1.1-esm/index.mjs";function o(o,a,m,l,j){if(!e(m))throw new TypeError(n("1VL3N,G4",m));if(!e(l))throw new TypeError(n("1VL32,MM",l));if(s(o))return function(r,s,e,t,i){var n,o,a,m,l,j,f,h,c,p,v;if(m=r.length,f=r.shape,n=r.data,h=r.strides,c=r.offset,o=r.order,l=r.accessors[0],j=r.ref,0===f.length)return t.call(i,s,e(l(n,c),0,j),0,j);for(a=s,v=m-1;v>=0;v--)p=d(f,h,c,o,v,"throw"),a=t.call(i,a,e(l(n,p),v,j),v,j);return a}(t(o),a,m,l,j);if(r(o))return function(r,s,e,t,i){var n,d,o,a;for(n=r.data,d=r.accessors[0],o=s,a=n.length-1;a>=0;a--)o=t.call(i,o,e(d(n,a),a,n),a,n);return o}(i(o),a,m,l,j);throw new TypeError(n("1VLBH,O9",o))}export{o as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..d07fb53 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js","../lib/ndarray.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isFunction from '@stdlib/assert-is-function';\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object';\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndarrayFcn from './ndarray.js';\nimport arrayFcn from './array.js';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function';\n* import add from '@stdlib/math-base-ops-add';\n* import abs from '@stdlib/math-base-special-abs';\n* import array from '@stdlib/ndarray-array';\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '1VL3N,G4', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '1VL32,MM', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '1VLBH,O9', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind';\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64';\n* import Complex64 from '@stdlib/complex-float32';\n* import realf from '@stdlib/complex-realf';\n* import imagf from '@stdlib/complex-imagf';\n* import cceil from '@stdlib/math-base-special-cceil';\n* import cadd from '@stdlib/math-base-ops-cadd';\n* import naryFunction from '@stdlib/utils-nary-function';\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","accessors","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;srBA0FA,SAASA,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,WAAYL,IAE1C,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,WAAYJ,IAE1C,GAAKK,EAAeR,GACnB,OCGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,UAAW,GAGnBZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAtH1B,SAuHTR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,CACR,CDnDSkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OE1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,UAAW,GAGnBf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,CACR,CFwBSqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,WAAYP,GAC1C"} \ No newline at end of file diff --git a/lib/array.js b/lib/array.js deleted file mode 100644 index 69c0a8c..0000000 --- a/lib/array.js +++ /dev/null @@ -1,83 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input array data -* @param {ArrayLikeObject} x.data - input array data -* @param {Array} x.accessors - input array accessors -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf[ idx ]; -* } -* -* // Create the input array object: -* var x = { -* 'data': [ 1, 2, 3, 4 ], -* 'accessors': [ getter ] -* }; -* -* // Compute the sum of squared values: -* var out = mapReduceRight( x, 0, square, sum ); -* // returns 30 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var get; - var acc; - var i; - - // Cache reference to the input data: - xbuf = x.data; - - // Cache the element accessor: - get = x.accessors[ 0 ]; - - // Iterate over each element... - acc = initial; - for ( i = xbuf.length-1; i >= 0; i-- ) { - acc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 522693e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +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. -*/ - -'use strict'; - -/** -* Perform a map-reduce operation against each element in an array while iterating from right to left and return the accumulated result. -* -* @module @stdlib/utils-map-reduce-right -* -* @example -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ - -// 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 20efedd..0000000 --- a/lib/main.js +++ /dev/null @@ -1,110 +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. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ndarrayFcn = require( './ndarray.js' ); -var arrayFcn = require( './array.js' ); - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided the following arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided the following arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result of applying the mapping function against the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* @param {(ArrayLikeObject|ndarray)} arr - input array -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} [thisArg] - reduction function execution context -* @throws {TypeError} first argument must be an array-like object or an ndarray -* @throws {TypeError} third argument must be a function -* @throws {TypeError} fourth argument must be a function -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { - if ( !isFunction( mapper ) ) { - throw new TypeError( format( '1VL3N,G4', mapper ) ); - } - if ( !isFunction( reducer ) ) { - throw new TypeError( format( '1VL32,MM', reducer ) ); - } - if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like - return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - if ( isArrayLikeObject( arr ) ) { - return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - throw new TypeError( format( '1VLBH,O9', arr ) ); -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/ndarray.js b/lib/ndarray.js deleted file mode 100644 index 06e19a5..0000000 --- a/lib/ndarray.js +++ /dev/null @@ -1,155 +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. -*/ - -'use strict'; - -// MODULES // - -var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); - - -// VARIABLES // - -var MODE = 'throw'; - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input ndarray meta data -* @param {string} x.ref - reference to original input ndarray-like object -* @param {string} x.dtype - data type -* @param {Collection} x.data - data buffer -* @param {NonNegativeInteger} x.length - number of elements -* @param {NonNegativeIntegerArray} x.shape - dimensions -* @param {IntegerArray} x.strides - stride lengths -* @param {NonNegativeInteger} x.offset - index offset -* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) -* @param {Array} x.accessors - accessors for accessing data buffer elements -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var Complex64 = require( '@stdlib/complex-float32' ); -* var realf = require( '@stdlib/complex-realf' ); -* var imagf = require( '@stdlib/complex-imagf' ); -* var cceil = require( '@stdlib/math-base-special-cceil' ); -* var cadd = require( '@stdlib/math-base-ops-cadd' ); -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* -* // Create a data buffer: -* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] ); -* -* // Define the shape of the input array: -* var shape = [ 2, 2 ]; -* -* // Define the array strides: -* var sx = [ 2, 1 ]; -* -* // Define the index offset: -* var ox = 0; -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf.get( idx ); -* } -* -* // Create the input ndarray-like object: -* var x = { -* 'ref': null, -* 'dtype': 'complex64', -* 'data': xbuf, -* 'length': 4, -* 'shape': shape, -* 'strides': sx, -* 'offset': ox, -* 'order': 'row-major', -* 'accessors': [ getter ] -* }; -* x.ref = x; -* -* // Compute the sum: -* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) ); -* -* var re = realf( v ); -* // returns 20.0 -* -* var im = imagf( v ); -* // returns 24.0 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var ordx; - var acc; - var len; - var get; - var ref; - var shx; - var sx; - var ox; - var ix; - var i; - - // Cache the total number of elements over which to iterate: - len = x.length; - - // Cache the input array shape: - shx = x.shape; - - // Cache reference to the input ndarray data buffer: - xbuf = x.data; - - // Cache reference to the stride array: - sx = x.strides; - - // Cache the index of the first indexed element: - ox = x.offset; - - // Cache the array order: - ordx = x.order; - - // Cache the element accessor: - get = x.accessors[ 0 ]; - - // Cache the reference to the original input array: - ref = x.ref; - - // Check for a zero-dimensional array... - if ( shx.length === 0 ) { - return reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len - } - // Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)... - acc = initial; - for ( i = len-1; i >= 0; i-- ) { - ix = vind2bind( shx, sx, ox, ordx, i, MODE ); - acc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/package.json b/package.json index 0c55c59..75d88cc 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Perform a single-pass map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.", "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/array-base-arraylike2object": "^0.1.0", - "@stdlib/assert-is-array-like-object": "^0.1.0", - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/ndarray-base-ndarraylike2object": "^0.1.0", - "@stdlib/ndarray-base-vind2bind": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-base-filled": "^0.1.0", - "@stdlib/array-complex64": "^0.1.0", - "@stdlib/array-filled-by": "^0.1.0", - "@stdlib/array-float64": "^0.1.1", - "@stdlib/bench": "^0.1.0", - "@stdlib/complex-float32": "^0.1.1", - "@stdlib/complex-imagf": "^0.1.1", - "@stdlib/complex-realf": "^0.1.1", - "@stdlib/math-base-assert-is-nan": "^0.1.1", - "@stdlib/math-base-ops-add": "^0.1.0", - "@stdlib/math-base-ops-cadd": "^0.1.0", - "@stdlib/math-base-special-abs": "^0.1.1", - "@stdlib/math-base-special-cceil": "^0.1.1", - "@stdlib/math-base-special-pow": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/random-base-discrete-uniform": "^0.1.0", - "@stdlib/utils-nary-function": "^0.1.0", - "@stdlib/utils-noop": "^0.1.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" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..873e8ab --- /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/test.js b/test/test.js deleted file mode 100644 index 2c78efa..0000000 --- a/test/test.js +++ /dev/null @@ -1,637 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var cadd = require( '@stdlib/math-base-ops-cadd' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var cceil = require( '@stdlib/math-base-special-cceil' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var mapReduceRight = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapReduceRight, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a first argument which is either an array-like object or an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( value, 0, noop, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value, {} ); - }; - } -}); - -tape( 'the function performs a map-reduce operation for each element in an array (array-like object)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = [ -1, -2, -3 ]; - expected = 7; - actual = mapReduceRight( arr, 1, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (typed array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - expected = 7.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (complex number array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( cceil, 1 ); - f2 = naryFunction( cadd, 2 ); - - arr = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5 ] ); - expected = new Complex64( 12.0, 15.0 ); - actual = mapReduceRight( arr, new Complex64( 0.0, 0.0 ), f1, f2 ); - - t.strictEqual( realf( actual ), realf( expected ), 'returns expected value' ); - t.strictEqual( imagf( actual ), imagf( expected ), 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = array( [ -1.0, -2.0, -3.0, -4.0 ], { - 'dtype': 'generic' - }); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray; 0-dimensional)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = ndarray( 'generic', [ -10.0 ], [], [ 0 ], 0, 'row-major' ); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (array-like object)', function test( t ) { - var out = mapReduceRight( [], 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (ndarray)', function test( t ) { - var arr; - var out; - - arr = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 0, 2 ], [ 0, 2, 1 ], 0, 'row-major' ); - out = mapReduceRight( arr, 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function supports providing a `this` context (array-like object)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = [ -1.0, -2.0, -3.0 ]; - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function supports providing a `this` context (ndarray)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = array( [ -1.0, -2.0, -3.0 ], { - 'dtype': 'generic' - }); - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = array( [ 1, , , 4 ], { // eslint-disable-line no-sparse-arrays - 'dtype': 'generic' - }); - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); From 091dabc59640ca6240af357472c349d5b0347e39 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 9 Nov 2023 11:45:08 +0000 Subject: [PATCH 49/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index d95cde3..20efedd 100644 --- a/lib/main.js +++ b/lib/main.js @@ -25,7 +25,7 @@ var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); var isFunction = require( '@stdlib/assert-is-function' ); var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ndarrayFcn = require( './ndarray.js' ); var arrayFcn = require( './array.js' ); @@ -90,10 +90,10 @@ var arrayFcn = require( './array.js' ); */ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( !isFunction( mapper ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) ); + throw new TypeError( format( '1VL3N,G4', mapper ) ); } if ( !isFunction( reducer ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) ); + throw new TypeError( format( '1VL32,MM', reducer ) ); } if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len @@ -101,7 +101,7 @@ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( isArrayLikeObject( arr ) ) { return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len } - throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) ); + throw new TypeError( format( '1VLBH,O9', arr ) ); } diff --git a/package.json b/package.json index 01b1e05..5170882 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-ndarray-like": "^0.1.0", "@stdlib/ndarray-base-ndarraylike2object": "^0.1.0", "@stdlib/ndarray-base-vind2bind": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0" }, "devDependencies": { From a594c3790d67b75ef6ce98d11bad28b02a1def6d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 9 Nov 2023 15:53:49 +0000 Subject: [PATCH 50/91] Remove files --- index.d.ts | 257 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6439 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 ed593f9..0000000 --- a/index.d.ts +++ /dev/null @@ -1,257 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; -import { typedndarray } from '@stdlib/types/ndarray'; - -/** -* Callback invoked for each array element. -* -* @returns result -*/ -type Nullary = () => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @returns result -*/ -type Unary = ( value: T ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @returns result -*/ -type Binary = ( value: T, index: number ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Ternary = ( value: T, index: number, arr: typedndarray ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayTernary = ( value: T, index: number, arr: Collection ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Mapper = Nullary | Unary | Binary | Ternary; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayMapper = Nullary | Unary | Binary | ArrayTernary; - -/** -* Function applied against an accumulator. -* -* @returns accumulator value -*/ -type NullaryReducer = ( this: W ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @returns accumulator value -*/ -type UnaryReducer = ( this: W, accumulator: V ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @returns accumulator value -*/ -type BinaryReducer = ( this: W, accumulator: V, value: U ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @returns accumulator value -*/ -type TernaryReducer = ( this: W, accumulator: V, value: U, index: number ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type QuaternaryReducer = ( this: W, accumulator: V, value: U, index: number, arr: typedndarray ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayQuaternaryReducer = ( this: W, accumulator: V, value: U, index: number, arr: Collection ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type Reducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | QuaternaryReducer; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayReducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | ArrayQuaternaryReducer; - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* var naryFunction = require( `@stdlib/utils/nary-function` ); -* var abs = require( `@stdlib/math/base/special/abs` ); -* var add = require( `@stdlib/math/base/ops/add` ); -* var array = require( `@stdlib/ndarray/array` ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 2 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -declare function mapReduceRight( arr: typedndarray, initial: V, mapper: Mapper, reducer: Reducer, thisArg?: ThisParameterType> ): V; - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -*/ -declare function mapReduceRight( arr: Collection, initial: V, mapper: ArrayMapper, reducer: ArrayReducer, thisArg?: ThisParameterType> ): V; - - -// EXPORTS // - -export = mapReduceRight; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index b9d643d..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.1.1-esm/index.mjs";function o(o,a,m,l,j){if(!e(m))throw new TypeError(n("1VL3N,G4",m));if(!e(l))throw new TypeError(n("1VL32,MM",l));if(s(o))return function(r,s,e,t,i){var n,o,a,m,l,j,f,h,c,p,v;if(m=r.length,f=r.shape,n=r.data,h=r.strides,c=r.offset,o=r.order,l=r.accessors[0],j=r.ref,0===f.length)return t.call(i,s,e(l(n,c),0,j),0,j);for(a=s,v=m-1;v>=0;v--)p=d(f,h,c,o,v,"throw"),a=t.call(i,a,e(l(n,p),v,j),v,j);return a}(t(o),a,m,l,j);if(r(o))return function(r,s,e,t,i){var n,d,o,a;for(n=r.data,d=r.accessors[0],o=s,a=n.length-1;a>=0;a--)o=t.call(i,o,e(d(n,a),a,n),a,n);return o}(i(o),a,m,l,j);throw new TypeError(n("1VLBH,O9",o))}export{o as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index d07fb53..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js","../lib/ndarray.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isFunction from '@stdlib/assert-is-function';\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object';\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndarrayFcn from './ndarray.js';\nimport arrayFcn from './array.js';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function';\n* import add from '@stdlib/math-base-ops-add';\n* import abs from '@stdlib/math-base-special-abs';\n* import array from '@stdlib/ndarray-array';\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '1VL3N,G4', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '1VL32,MM', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '1VLBH,O9', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind';\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64';\n* import Complex64 from '@stdlib/complex-float32';\n* import realf from '@stdlib/complex-realf';\n* import imagf from '@stdlib/complex-imagf';\n* import cceil from '@stdlib/math-base-special-cceil';\n* import cadd from '@stdlib/math-base-ops-cadd';\n* import naryFunction from '@stdlib/utils-nary-function';\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","accessors","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;srBA0FA,SAASA,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,WAAYL,IAE1C,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,WAAYJ,IAE1C,GAAKK,EAAeR,GACnB,OCGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,UAAW,GAGnBZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAtH1B,SAuHTR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,CACR,CDnDSkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OE1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,UAAW,GAGnBf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,CACR,CFwBSqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,WAAYP,GAC1C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 873e8ab..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 51f245394a421f4a8b07c1ad71660753024d1cba Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 9 Nov 2023 15:58:08 +0000 Subject: [PATCH 51/91] 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 | 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 | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 69 +- benchmark/benchmark.array.js | 98 - benchmark/benchmark.ndarray.js | 109 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 9 - dist/index.js.map | 7 - docs/repl.txt | 65 - docs/types/test.ts | 184 - examples/index.js | 52 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/array.js | 83 - lib/index.js | 65 - lib/main.js | 110 - lib/ndarray.js | 155 - package.json | 76 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 637 --- 44 files changed, 6216 insertions(+), 4943 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.array.js delete mode 100644 benchmark/benchmark.ndarray.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/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/array.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/ndarray.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.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 3b4c7b4..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/utils/map-reduce-right) 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 f23359f..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/utils/map-reduce-right) 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 d3c6ace..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: '21 21 * * 4' - - # 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 + + ```
@@ -279,7 +272,7 @@ console.log( 'sum: %d', out ); ## 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]. @@ -339,19 +332,19 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/utils-map-reduce-right/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64 +[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64/tree/esm -[@stdlib/array/complex128]: https://github.com/stdlib-js/array-complex128 +[@stdlib/array/complex128]: https://github.com/stdlib-js/array-complex128/tree/esm -[@stdlib/utils/map-right]: https://github.com/stdlib-js/utils-map-right +[@stdlib/utils/map-right]: https://github.com/stdlib-js/utils-map-right/tree/esm -[@stdlib/utils/map-reduce]: https://github.com/stdlib-js/utils-map-reduce +[@stdlib/utils/map-reduce]: https://github.com/stdlib-js/utils-map-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/tree/esm diff --git a/benchmark/benchmark.array.js b/benchmark/benchmark.array.js deleted file mode 100644 index e87feb5..0000000 --- a/benchmark/benchmark.array.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = filled( -3.0, len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::array:len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.ndarray.js b/benchmark/benchmark.ndarray.js deleted file mode 100644 index e3bfba2..0000000 --- a/benchmark/benchmark.ndarray.js +++ /dev/null @@ -1,109 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var xbuf; - var opts; - var x; - - xbuf = filled( -3.0, len ); - - opts = { - 'dtype': 'generic' - }; - x = array( xbuf, opts ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::ndarray:len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index cd78ec7..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/utils/map-reduce-right" -%% click B href "https://github.com/stdlib-js/utils-map-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-map-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-map-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-map-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-map-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/map-reduce-right -[production-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-map-reduce-right/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 63ea99a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import mapReduceRight from '../docs/types/index'; -export = mapReduceRight; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 3180c8b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,9 +0,0 @@ -"use strict";var g=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var q=g(function(H,m){ -var E=require('@stdlib/ndarray-base-vind2bind/dist'),T="throw";function p(r,e,a,t,s){var i,v,n,u,f,c,l,y,d,b,o;if(u=r.length,l=r.shape,i=r.data,y=r.strides,d=r.offset,v=r.order,f=r.accessors[0],c=r.ref,l.length===0)return t.call(s,e,a(f(i,d),0,c),0,c);for(n=e,o=u-1;o>=0;o--)b=E(l,y,d,v,o,T),n=t.call(s,n,a(f(i,b),o,c),o,c);return n}m.exports=p -});var R=g(function(I,w){ -function x(r,e,a,t,s){var i,v,n,u;for(i=r.data,v=r.accessors[0],n=e,u=i.length-1;u>=0;u--)n=t.call(s,n,a(v(i,u),u,i),u,i);return n}w.exports=x -});var j=g(function(J,F){ -var V=require('@stdlib/assert-is-array-like-object/dist'),L=require('@stdlib/assert-is-ndarray-like/dist'),k=require('@stdlib/assert-is-function/dist'),O=require('@stdlib/ndarray-base-ndarraylike2object/dist'),D=require('@stdlib/array-base-arraylike2object/dist'),h=require('@stdlib/error-tools-fmtprodmsg/dist'),M=q(),z=R();function B(r,e,a,t,s){if(!k(a))throw new TypeError(h('1VL3N',a));if(!k(t))throw new TypeError(h('1VL32',t));if(L(r))return M(O(r),e,a,t,s);if(V(r))return z(D(r),e,a,t,s);throw new TypeError(h('1VLBH',r))}F.exports=B -});var C=j();module.exports=C; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 641859d..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/ndarray.js", "../lib/array.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* var Complex64Array = require( '@stdlib/array-complex64' );\n* var Complex64 = require( '@stdlib/complex-float32' );\n* var realf = require( '@stdlib/complex-realf' );\n* var imagf = require( '@stdlib/complex-imagf' );\n* var cceil = require( '@stdlib/math-base-special-cceil' );\n* var cadd = require( '@stdlib/math-base-ops-cadd' );\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar format = require( '@stdlib/string-format' );\nvar ndarrayFcn = require( './ndarray.js' );\nvar arrayFcn = require( './array.js' );\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/math-base-ops-add' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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* Perform a map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.\n*\n* @module @stdlib/utils-map-reduce-right\n*\n* @example\n* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' );\n*\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, sum );\n* // returns 30\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/math-base-ops-add' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\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,EAAY,QAAS,gCAAiC,EAKtDC,EAAO,QA0EX,SAASC,EAAgBC,EAAGC,EAASC,EAAQC,EAASC,EAAU,CAC/D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMR,EAAE,OAGRW,EAAMX,EAAE,MAGRK,EAAOL,EAAE,KAGTY,EAAKZ,EAAE,QAGPa,EAAKb,EAAE,OAGPM,EAAON,EAAE,MAGTS,EAAMT,EAAE,UAAW,CAAE,EAGrBU,EAAMV,EAAE,IAGHW,EAAI,SAAW,EACnB,OAAOR,EAAQ,KAAMC,EAASH,EAASC,EAAQO,EAAKJ,EAAMQ,CAAG,EAAG,EAAGH,CAAI,EAAG,EAAGA,CAAI,EAIlF,IADAH,EAAMN,EACAc,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKjB,EAAWc,EAAKC,EAAIC,EAAIP,EAAMS,EAAGjB,CAAK,EAC3CS,EAAMJ,EAAQ,KAAMC,EAASG,EAAKL,EAAQO,EAAKJ,EAAMS,CAAG,EAAGC,EAAGL,CAAI,EAAGK,EAAGL,CAAI,EAE7E,OAAOH,CACR,CAKAX,EAAO,QAAUG,IC1JjB,IAAAiB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA2DA,SAASC,EAAgBC,EAAGC,EAASC,EAAQC,EAASC,EAAU,CAC/D,IAAIC,EACAC,EACAC,EACAC,EAUJ,IAPAH,EAAOL,EAAE,KAGTM,EAAMN,EAAE,UAAW,CAAE,EAGrBO,EAAMN,EACAO,EAAIH,EAAK,OAAO,EAAGG,GAAK,EAAGA,IAChCD,EAAMJ,EAAQ,KAAMC,EAASG,EAAKL,EAAQI,EAAKD,EAAMG,CAAE,EAAGA,EAAGH,CAAK,EAAGG,EAAGH,CAAK,EAE9E,OAAOE,CACR,CAKAT,EAAO,QAAUC,IClFjB,IAAAU,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAoB,QAAS,qCAAsC,EACnEC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,4BAA6B,EACnDC,EAAqB,QAAS,yCAA0C,EACxEC,EAAmB,QAAS,qCAAsC,EAClEC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAW,IA6Df,SAASC,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,EAAU,CACjE,GAAK,CAACX,EAAYS,CAAO,EACxB,MAAM,IAAI,UAAWN,EAAQ,oEAAqEM,CAAO,CAAE,EAE5G,GAAK,CAACT,EAAYU,CAAQ,EACzB,MAAM,IAAI,UAAWP,EAAQ,qEAAsEO,CAAQ,CAAE,EAE9G,GAAKX,EAAeQ,CAAI,EACvB,OAAOH,EAAYH,EAAoBM,CAAI,EAAGC,EAASC,EAAQC,EAASC,CAAQ,EAEjF,GAAKb,EAAmBS,CAAI,EAC3B,OAAOF,EAAUH,EAAkBK,CAAI,EAAGC,EAASC,EAAQC,EAASC,CAAQ,EAE7E,MAAM,IAAI,UAAWR,EAAQ,4FAA6FI,CAAI,CAAE,CACjI,CAKAV,EAAO,QAAUS,IClDjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_ndarray", "__commonJSMin", "exports", "module", "vind2bind", "MODE", "mapReduceRight", "x", "initial", "mapper", "reducer", "thisArg", "xbuf", "ordx", "acc", "len", "get", "ref", "shx", "sx", "ox", "ix", "i", "require_array", "__commonJSMin", "exports", "module", "mapReduceRight", "x", "initial", "mapper", "reducer", "thisArg", "xbuf", "get", "acc", "i", "require_main", "__commonJSMin", "exports", "module", "isArrayLikeObject", "isndarrayLike", "isFunction", "ndarraylike2object", "arraylike2object", "format", "ndarrayFcn", "arrayFcn", "mapReduceRight", "arr", "initial", "mapper", "reducer", "thisArg", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b580e87..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, initial, mapper, reducer[, thisArg] ) - Performs a map-reduce operation for each element in an array while iterating - from right to left and returns the accumulated result. - - When invoked, the mapping function is provided three arguments: - - - value: array element. - - index: element index. - - arr: input array. - - When invoked, the reducing function is provided four arguments: - - - accumulator: accumulated value. - - value: result after applying the mapping function to the current array - element. - - index: element index. - - arr: input array. - - If provided an empty array, the function returns the initial value. - - When provided an ndarray, the function performs a single-pass map-reduce - operation over the entire input ndarray (i.e., higher-order ndarray - dimensions are flattened to a single-dimension). - - Parameters - ---------- - arr: ArrayLikeObject|ndarray - Input array. - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - mapper: Function - Mapping function. - - reducer: Function - Reducing function. - - thisArg: any (optional) - Execution context for the reducing function. - - Returns - ------- - out: any - Accumulated result. - - Examples - -------- - // array-like object: - > var f1 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/special/abs}}, 1 ); - > var f2 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/ops/add}}, 2 ); - > var arr = [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0 ]; - > var out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - // ndarray: - > arr = {{alias:@stdlib/ndarray/array}}( arr, { 'shape': [ 2, 3 ] } ); - > out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 3fcccbb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,184 +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. -*/ - -import array = require( '@stdlib/ndarray-array' ); -import mapReduceRight = require( './index' ); - -/** -* Mapping function. -* -* @param value - array element -* @returns result -*/ -function mapper( value: number ): number { - return value; -} - -/** -* Reducing function. -* -* @param acc - accumulated value -* @param v - array element -* @returns result -*/ -function reducer( acc: number, value: number ): number { - return acc + value; -} - - -// TESTS // - -// The function returns the accumulated value when provided a collection... -{ - mapReduceRight( [ 0, 1, 1, NaN, 2 ], 0, mapper, reducer ); // $ExpectType number - mapReduceRight( [ -1, 1, 2 ], 100, mapper, reducer ); // $ExpectType number - mapReduceRight( [ -1, 1, 2 ], 0, mapper, reducer, {} ); // $ExpectType number -} - -// The function returns the accumulated value when provided an ndarray... -{ - const arr = array( [ 1, 2, 3, 4, 5, 6 ] ); - - mapReduceRight( arr, 0, mapper, reducer ); // $ExpectType number - mapReduceRight( arr, 100, mapper, reducer ); // $ExpectType number - mapReduceRight( arr, 0, mapper, reducer, {} ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not a collection or ndarray... -{ - mapReduceRight( 2, 0, mapper, reducer ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer ); // $ExpectError - - mapReduceRight( 2, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr1, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr2, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const arr1 = [ 1, 2, 3 ]; - - mapReduceRight(); // $ExpectError - mapReduceRight( arr1 ); // $ExpectError - mapReduceRight( arr1, 0 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ); // $ExpectError - mapReduceRight( arr1, 0, mapper, reducer, {}, 3 ); // $ExpectError - - const arr2 = array( [ 1, 2, 3 ] ); - - mapReduceRight(); // $ExpectError - mapReduceRight( arr2 ); // $ExpectError - mapReduceRight( arr2, 0 ); // $ExpectError - mapReduceRight( arr2, 0, mapper ); // $ExpectError - mapReduceRight( arr2, 0, mapper, reducer, {}, 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 7474059..0000000 --- a/examples/index.js +++ /dev/null @@ -1,52 +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. -*/ - -'use strict'; - -var filledarrayBy = require( '@stdlib/array-filled-by' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ).factory; -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var mapReduceRight = require( './../lib' ); - -function fill( i ) { - var rand = discreteUniform( -10*(i+1), 10*(i+1) ); - return filledarrayBy( 10, 'generic', rand ); -} - -// Create a two-dimensional ndarray (i.e., a matrix): -var x = array( filledarrayBy( 10, 'generic', fill ), { - 'dtype': 'generic', - 'flatten': true -}); - -// Create an explicit unary function: -var f1 = naryFunction( abs, 1 ); - -// Create an explicit binary function: -var f2 = naryFunction( add, 2 ); - -// Compute the sum of absolute values: -var out = mapReduceRight( x, 0, f1, f2 ); - -console.log( 'x:' ); -console.log( x.data ); - -console.log( 'sum: %d', out ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 2d0e5da..ed593f9 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; import { typedndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..b9d643d --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.1.1-esm/index.mjs";function o(o,a,m,l,j){if(!e(m))throw new TypeError(n("1VL3N,G4",m));if(!e(l))throw new TypeError(n("1VL32,MM",l));if(s(o))return function(r,s,e,t,i){var n,o,a,m,l,j,f,h,c,p,v;if(m=r.length,f=r.shape,n=r.data,h=r.strides,c=r.offset,o=r.order,l=r.accessors[0],j=r.ref,0===f.length)return t.call(i,s,e(l(n,c),0,j),0,j);for(a=s,v=m-1;v>=0;v--)p=d(f,h,c,o,v,"throw"),a=t.call(i,a,e(l(n,p),v,j),v,j);return a}(t(o),a,m,l,j);if(r(o))return function(r,s,e,t,i){var n,d,o,a;for(n=r.data,d=r.accessors[0],o=s,a=n.length-1;a>=0;a--)o=t.call(i,o,e(d(n,a),a,n),a,n);return o}(i(o),a,m,l,j);throw new TypeError(n("1VLBH,O9",o))}export{o as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..d07fb53 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js","../lib/ndarray.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isFunction from '@stdlib/assert-is-function';\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object';\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndarrayFcn from './ndarray.js';\nimport arrayFcn from './array.js';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function';\n* import add from '@stdlib/math-base-ops-add';\n* import abs from '@stdlib/math-base-special-abs';\n* import array from '@stdlib/ndarray-array';\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '1VL3N,G4', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '1VL32,MM', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '1VLBH,O9', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind';\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64';\n* import Complex64 from '@stdlib/complex-float32';\n* import realf from '@stdlib/complex-realf';\n* import imagf from '@stdlib/complex-imagf';\n* import cceil from '@stdlib/math-base-special-cceil';\n* import cadd from '@stdlib/math-base-ops-cadd';\n* import naryFunction from '@stdlib/utils-nary-function';\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","accessors","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;srBA0FA,SAASA,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,WAAYL,IAE1C,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,WAAYJ,IAE1C,GAAKK,EAAeR,GACnB,OCGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,UAAW,GAGnBZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAtH1B,SAuHTR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,CACR,CDnDSkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OE1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,UAAW,GAGnBf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,CACR,CFwBSqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,WAAYP,GAC1C"} \ No newline at end of file diff --git a/lib/array.js b/lib/array.js deleted file mode 100644 index 69c0a8c..0000000 --- a/lib/array.js +++ /dev/null @@ -1,83 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input array data -* @param {ArrayLikeObject} x.data - input array data -* @param {Array} x.accessors - input array accessors -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf[ idx ]; -* } -* -* // Create the input array object: -* var x = { -* 'data': [ 1, 2, 3, 4 ], -* 'accessors': [ getter ] -* }; -* -* // Compute the sum of squared values: -* var out = mapReduceRight( x, 0, square, sum ); -* // returns 30 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var get; - var acc; - var i; - - // Cache reference to the input data: - xbuf = x.data; - - // Cache the element accessor: - get = x.accessors[ 0 ]; - - // Iterate over each element... - acc = initial; - for ( i = xbuf.length-1; i >= 0; i-- ) { - acc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 522693e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +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. -*/ - -'use strict'; - -/** -* Perform a map-reduce operation against each element in an array while iterating from right to left and return the accumulated result. -* -* @module @stdlib/utils-map-reduce-right -* -* @example -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ - -// 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 20efedd..0000000 --- a/lib/main.js +++ /dev/null @@ -1,110 +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. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ndarrayFcn = require( './ndarray.js' ); -var arrayFcn = require( './array.js' ); - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided the following arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided the following arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result of applying the mapping function against the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* @param {(ArrayLikeObject|ndarray)} arr - input array -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} [thisArg] - reduction function execution context -* @throws {TypeError} first argument must be an array-like object or an ndarray -* @throws {TypeError} third argument must be a function -* @throws {TypeError} fourth argument must be a function -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { - if ( !isFunction( mapper ) ) { - throw new TypeError( format( '1VL3N,G4', mapper ) ); - } - if ( !isFunction( reducer ) ) { - throw new TypeError( format( '1VL32,MM', reducer ) ); - } - if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like - return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - if ( isArrayLikeObject( arr ) ) { - return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - throw new TypeError( format( '1VLBH,O9', arr ) ); -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/ndarray.js b/lib/ndarray.js deleted file mode 100644 index 06e19a5..0000000 --- a/lib/ndarray.js +++ /dev/null @@ -1,155 +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. -*/ - -'use strict'; - -// MODULES // - -var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); - - -// VARIABLES // - -var MODE = 'throw'; - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input ndarray meta data -* @param {string} x.ref - reference to original input ndarray-like object -* @param {string} x.dtype - data type -* @param {Collection} x.data - data buffer -* @param {NonNegativeInteger} x.length - number of elements -* @param {NonNegativeIntegerArray} x.shape - dimensions -* @param {IntegerArray} x.strides - stride lengths -* @param {NonNegativeInteger} x.offset - index offset -* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) -* @param {Array} x.accessors - accessors for accessing data buffer elements -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var Complex64 = require( '@stdlib/complex-float32' ); -* var realf = require( '@stdlib/complex-realf' ); -* var imagf = require( '@stdlib/complex-imagf' ); -* var cceil = require( '@stdlib/math-base-special-cceil' ); -* var cadd = require( '@stdlib/math-base-ops-cadd' ); -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* -* // Create a data buffer: -* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] ); -* -* // Define the shape of the input array: -* var shape = [ 2, 2 ]; -* -* // Define the array strides: -* var sx = [ 2, 1 ]; -* -* // Define the index offset: -* var ox = 0; -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf.get( idx ); -* } -* -* // Create the input ndarray-like object: -* var x = { -* 'ref': null, -* 'dtype': 'complex64', -* 'data': xbuf, -* 'length': 4, -* 'shape': shape, -* 'strides': sx, -* 'offset': ox, -* 'order': 'row-major', -* 'accessors': [ getter ] -* }; -* x.ref = x; -* -* // Compute the sum: -* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) ); -* -* var re = realf( v ); -* // returns 20.0 -* -* var im = imagf( v ); -* // returns 24.0 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var ordx; - var acc; - var len; - var get; - var ref; - var shx; - var sx; - var ox; - var ix; - var i; - - // Cache the total number of elements over which to iterate: - len = x.length; - - // Cache the input array shape: - shx = x.shape; - - // Cache reference to the input ndarray data buffer: - xbuf = x.data; - - // Cache reference to the stride array: - sx = x.strides; - - // Cache the index of the first indexed element: - ox = x.offset; - - // Cache the array order: - ordx = x.order; - - // Cache the element accessor: - get = x.accessors[ 0 ]; - - // Cache the reference to the original input array: - ref = x.ref; - - // Check for a zero-dimensional array... - if ( shx.length === 0 ) { - return reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len - } - // Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)... - acc = initial; - for ( i = len-1; i >= 0; i-- ) { - ix = vind2bind( shx, sx, ox, ordx, i, MODE ); - acc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/package.json b/package.json index 5170882..75d88cc 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Perform a single-pass map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.", "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/array-base-arraylike2object": "^0.1.0", - "@stdlib/assert-is-array-like-object": "^0.1.0", - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/ndarray-base-ndarraylike2object": "^0.1.0", - "@stdlib/ndarray-base-vind2bind": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0" - }, - "devDependencies": { - "@stdlib/array-base-filled": "^0.1.0", - "@stdlib/array-complex64": "^0.1.0", - "@stdlib/array-filled-by": "^0.1.0", - "@stdlib/array-float64": "^0.1.1", - "@stdlib/bench": "^0.2.0", - "@stdlib/complex-float32": "^0.1.1", - "@stdlib/complex-imagf": "^0.1.1", - "@stdlib/complex-realf": "^0.1.1", - "@stdlib/math-base-assert-is-nan": "^0.1.1", - "@stdlib/math-base-ops-add": "^0.1.0", - "@stdlib/math-base-ops-cadd": "^0.1.0", - "@stdlib/math-base-special-abs": "^0.1.1", - "@stdlib/math-base-special-cceil": "^0.1.1", - "@stdlib/math-base-special-pow": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/random-base-discrete-uniform": "^0.1.0", - "@stdlib/utils-nary-function": "^0.1.0", - "@stdlib/utils-noop": "^0.1.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" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..afb1a2d --- /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/test.js b/test/test.js deleted file mode 100644 index 2c78efa..0000000 --- a/test/test.js +++ /dev/null @@ -1,637 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var cadd = require( '@stdlib/math-base-ops-cadd' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var cceil = require( '@stdlib/math-base-special-cceil' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var mapReduceRight = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapReduceRight, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a first argument which is either an array-like object or an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( value, 0, noop, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value, {} ); - }; - } -}); - -tape( 'the function performs a map-reduce operation for each element in an array (array-like object)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = [ -1, -2, -3 ]; - expected = 7; - actual = mapReduceRight( arr, 1, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (typed array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - expected = 7.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (complex number array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( cceil, 1 ); - f2 = naryFunction( cadd, 2 ); - - arr = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5 ] ); - expected = new Complex64( 12.0, 15.0 ); - actual = mapReduceRight( arr, new Complex64( 0.0, 0.0 ), f1, f2 ); - - t.strictEqual( realf( actual ), realf( expected ), 'returns expected value' ); - t.strictEqual( imagf( actual ), imagf( expected ), 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = array( [ -1.0, -2.0, -3.0, -4.0 ], { - 'dtype': 'generic' - }); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray; 0-dimensional)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = ndarray( 'generic', [ -10.0 ], [], [ 0 ], 0, 'row-major' ); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (array-like object)', function test( t ) { - var out = mapReduceRight( [], 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (ndarray)', function test( t ) { - var arr; - var out; - - arr = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 0, 2 ], [ 0, 2, 1 ], 0, 'row-major' ); - out = mapReduceRight( arr, 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function supports providing a `this` context (array-like object)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = [ -1.0, -2.0, -3.0 ]; - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function supports providing a `this` context (ndarray)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = array( [ -1.0, -2.0, -3.0 ], { - 'dtype': 'generic' - }); - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = array( [ 1, , , 4 ], { // eslint-disable-line no-sparse-arrays - 'dtype': 'generic' - }); - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); From 320c7c84d3cd728129f507096605ec341c64fd09 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Dec 2023 14:21:47 +0000 Subject: [PATCH 52/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index d95cde3..20efedd 100644 --- a/lib/main.js +++ b/lib/main.js @@ -25,7 +25,7 @@ var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); var isFunction = require( '@stdlib/assert-is-function' ); var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ndarrayFcn = require( './ndarray.js' ); var arrayFcn = require( './array.js' ); @@ -90,10 +90,10 @@ var arrayFcn = require( './array.js' ); */ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( !isFunction( mapper ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) ); + throw new TypeError( format( '1VL3N,G4', mapper ) ); } if ( !isFunction( reducer ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) ); + throw new TypeError( format( '1VL32,MM', reducer ) ); } if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len @@ -101,7 +101,7 @@ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( isArrayLikeObject( arr ) ) { return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len } - throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) ); + throw new TypeError( format( '1VLBH,O9', arr ) ); } diff --git a/package.json b/package.json index ee471d3..e6446b2 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-ndarray-like": "^0.1.0", "@stdlib/ndarray-base-ndarraylike2object": "^0.1.0", "@stdlib/ndarray-base-vind2bind": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0" }, "devDependencies": { From c04c2828038eae44861cb313d4516d63e24876a4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Dec 2023 12:38:42 +0000 Subject: [PATCH 53/91] Remove files --- index.d.ts | 257 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6439 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 ed593f9..0000000 --- a/index.d.ts +++ /dev/null @@ -1,257 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; -import { typedndarray } from '@stdlib/types/ndarray'; - -/** -* Callback invoked for each array element. -* -* @returns result -*/ -type Nullary = () => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @returns result -*/ -type Unary = ( value: T ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @returns result -*/ -type Binary = ( value: T, index: number ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Ternary = ( value: T, index: number, arr: typedndarray ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayTernary = ( value: T, index: number, arr: Collection ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Mapper = Nullary | Unary | Binary | Ternary; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayMapper = Nullary | Unary | Binary | ArrayTernary; - -/** -* Function applied against an accumulator. -* -* @returns accumulator value -*/ -type NullaryReducer = ( this: W ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @returns accumulator value -*/ -type UnaryReducer = ( this: W, accumulator: V ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @returns accumulator value -*/ -type BinaryReducer = ( this: W, accumulator: V, value: U ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @returns accumulator value -*/ -type TernaryReducer = ( this: W, accumulator: V, value: U, index: number ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type QuaternaryReducer = ( this: W, accumulator: V, value: U, index: number, arr: typedndarray ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayQuaternaryReducer = ( this: W, accumulator: V, value: U, index: number, arr: Collection ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type Reducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | QuaternaryReducer; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayReducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | ArrayQuaternaryReducer; - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* var naryFunction = require( `@stdlib/utils/nary-function` ); -* var abs = require( `@stdlib/math/base/special/abs` ); -* var add = require( `@stdlib/math/base/ops/add` ); -* var array = require( `@stdlib/ndarray/array` ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 2 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -declare function mapReduceRight( arr: typedndarray, initial: V, mapper: Mapper, reducer: Reducer, thisArg?: ThisParameterType> ): V; - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -*/ -declare function mapReduceRight( arr: Collection, initial: V, mapper: ArrayMapper, reducer: ArrayReducer, thisArg?: ThisParameterType> ): V; - - -// EXPORTS // - -export = mapReduceRight; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index b9d643d..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.1.1-esm/index.mjs";function o(o,a,m,l,j){if(!e(m))throw new TypeError(n("1VL3N,G4",m));if(!e(l))throw new TypeError(n("1VL32,MM",l));if(s(o))return function(r,s,e,t,i){var n,o,a,m,l,j,f,h,c,p,v;if(m=r.length,f=r.shape,n=r.data,h=r.strides,c=r.offset,o=r.order,l=r.accessors[0],j=r.ref,0===f.length)return t.call(i,s,e(l(n,c),0,j),0,j);for(a=s,v=m-1;v>=0;v--)p=d(f,h,c,o,v,"throw"),a=t.call(i,a,e(l(n,p),v,j),v,j);return a}(t(o),a,m,l,j);if(r(o))return function(r,s,e,t,i){var n,d,o,a;for(n=r.data,d=r.accessors[0],o=s,a=n.length-1;a>=0;a--)o=t.call(i,o,e(d(n,a),a,n),a,n);return o}(i(o),a,m,l,j);throw new TypeError(n("1VLBH,O9",o))}export{o as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index d07fb53..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js","../lib/ndarray.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isFunction from '@stdlib/assert-is-function';\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object';\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndarrayFcn from './ndarray.js';\nimport arrayFcn from './array.js';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function';\n* import add from '@stdlib/math-base-ops-add';\n* import abs from '@stdlib/math-base-special-abs';\n* import array from '@stdlib/ndarray-array';\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '1VL3N,G4', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '1VL32,MM', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '1VLBH,O9', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind';\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64';\n* import Complex64 from '@stdlib/complex-float32';\n* import realf from '@stdlib/complex-realf';\n* import imagf from '@stdlib/complex-imagf';\n* import cceil from '@stdlib/math-base-special-cceil';\n* import cadd from '@stdlib/math-base-ops-cadd';\n* import naryFunction from '@stdlib/utils-nary-function';\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","accessors","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;srBA0FA,SAASA,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,WAAYL,IAE1C,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,WAAYJ,IAE1C,GAAKK,EAAeR,GACnB,OCGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,UAAW,GAGnBZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAtH1B,SAuHTR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,CACR,CDnDSkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OE1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,UAAW,GAGnBf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,CACR,CFwBSqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,WAAYP,GAC1C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index afb1a2d..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From df21e925a666ee42eeefafa4d475594039dd3974 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Dec 2023 12:41:38 +0000 Subject: [PATCH 54/91] 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 | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 69 +- benchmark/benchmark.array.js | 98 - benchmark/benchmark.ndarray.js | 109 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 9 - dist/index.js.map | 7 - docs/repl.txt | 65 - docs/types/test.ts | 184 - examples/index.js | 52 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/array.js | 83 - lib/index.js | 65 - lib/main.js | 110 - lib/ndarray.js | 155 - package.json | 76 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 637 --- 45 files changed, 6216 insertions(+), 4939 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 benchmark/benchmark.array.js delete mode 100644 benchmark/benchmark.ndarray.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/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/array.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/ndarray.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.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 398a8a2..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-12-01T06:04:12.547Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3b4c7b4..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/utils/map-reduce-right) 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 f23359f..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/utils/map-reduce-right) 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 d3c6ace..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: '21 21 * * 4' - - # 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 + + ```
@@ -279,7 +272,7 @@ console.log( 'sum: %d', out ); ## 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]. @@ -339,19 +332,19 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/utils-map-reduce-right/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64 +[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64/tree/esm -[@stdlib/array/complex128]: https://github.com/stdlib-js/array-complex128 +[@stdlib/array/complex128]: https://github.com/stdlib-js/array-complex128/tree/esm -[@stdlib/utils/map-right]: https://github.com/stdlib-js/utils-map-right +[@stdlib/utils/map-right]: https://github.com/stdlib-js/utils-map-right/tree/esm -[@stdlib/utils/map-reduce]: https://github.com/stdlib-js/utils-map-reduce +[@stdlib/utils/map-reduce]: https://github.com/stdlib-js/utils-map-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/tree/esm diff --git a/benchmark/benchmark.array.js b/benchmark/benchmark.array.js deleted file mode 100644 index e87feb5..0000000 --- a/benchmark/benchmark.array.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = filled( -3.0, len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::array:len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.ndarray.js b/benchmark/benchmark.ndarray.js deleted file mode 100644 index e3bfba2..0000000 --- a/benchmark/benchmark.ndarray.js +++ /dev/null @@ -1,109 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var xbuf; - var opts; - var x; - - xbuf = filled( -3.0, len ); - - opts = { - 'dtype': 'generic' - }; - x = array( xbuf, opts ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::ndarray:len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index cd78ec7..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/utils/map-reduce-right" -%% click B href "https://github.com/stdlib-js/utils-map-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-map-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-map-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-map-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-map-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/map-reduce-right -[production-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-map-reduce-right/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 63ea99a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import mapReduceRight from '../docs/types/index'; -export = mapReduceRight; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 3180c8b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,9 +0,0 @@ -"use strict";var g=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var q=g(function(H,m){ -var E=require('@stdlib/ndarray-base-vind2bind/dist'),T="throw";function p(r,e,a,t,s){var i,v,n,u,f,c,l,y,d,b,o;if(u=r.length,l=r.shape,i=r.data,y=r.strides,d=r.offset,v=r.order,f=r.accessors[0],c=r.ref,l.length===0)return t.call(s,e,a(f(i,d),0,c),0,c);for(n=e,o=u-1;o>=0;o--)b=E(l,y,d,v,o,T),n=t.call(s,n,a(f(i,b),o,c),o,c);return n}m.exports=p -});var R=g(function(I,w){ -function x(r,e,a,t,s){var i,v,n,u;for(i=r.data,v=r.accessors[0],n=e,u=i.length-1;u>=0;u--)n=t.call(s,n,a(v(i,u),u,i),u,i);return n}w.exports=x -});var j=g(function(J,F){ -var V=require('@stdlib/assert-is-array-like-object/dist'),L=require('@stdlib/assert-is-ndarray-like/dist'),k=require('@stdlib/assert-is-function/dist'),O=require('@stdlib/ndarray-base-ndarraylike2object/dist'),D=require('@stdlib/array-base-arraylike2object/dist'),h=require('@stdlib/error-tools-fmtprodmsg/dist'),M=q(),z=R();function B(r,e,a,t,s){if(!k(a))throw new TypeError(h('1VL3N',a));if(!k(t))throw new TypeError(h('1VL32',t));if(L(r))return M(O(r),e,a,t,s);if(V(r))return z(D(r),e,a,t,s);throw new TypeError(h('1VLBH',r))}F.exports=B -});var C=j();module.exports=C; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 641859d..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/ndarray.js", "../lib/array.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* var Complex64Array = require( '@stdlib/array-complex64' );\n* var Complex64 = require( '@stdlib/complex-float32' );\n* var realf = require( '@stdlib/complex-realf' );\n* var imagf = require( '@stdlib/complex-imagf' );\n* var cceil = require( '@stdlib/math-base-special-cceil' );\n* var cadd = require( '@stdlib/math-base-ops-cadd' );\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar format = require( '@stdlib/string-format' );\nvar ndarrayFcn = require( './ndarray.js' );\nvar arrayFcn = require( './array.js' );\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/math-base-ops-add' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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* Perform a map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.\n*\n* @module @stdlib/utils-map-reduce-right\n*\n* @example\n* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' );\n*\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, sum );\n* // returns 30\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/math-base-ops-add' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\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,EAAY,QAAS,gCAAiC,EAKtDC,EAAO,QA0EX,SAASC,EAAgBC,EAAGC,EAASC,EAAQC,EAASC,EAAU,CAC/D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMR,EAAE,OAGRW,EAAMX,EAAE,MAGRK,EAAOL,EAAE,KAGTY,EAAKZ,EAAE,QAGPa,EAAKb,EAAE,OAGPM,EAAON,EAAE,MAGTS,EAAMT,EAAE,UAAW,CAAE,EAGrBU,EAAMV,EAAE,IAGHW,EAAI,SAAW,EACnB,OAAOR,EAAQ,KAAMC,EAASH,EAASC,EAAQO,EAAKJ,EAAMQ,CAAG,EAAG,EAAGH,CAAI,EAAG,EAAGA,CAAI,EAIlF,IADAH,EAAMN,EACAc,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKjB,EAAWc,EAAKC,EAAIC,EAAIP,EAAMS,EAAGjB,CAAK,EAC3CS,EAAMJ,EAAQ,KAAMC,EAASG,EAAKL,EAAQO,EAAKJ,EAAMS,CAAG,EAAGC,EAAGL,CAAI,EAAGK,EAAGL,CAAI,EAE7E,OAAOH,CACR,CAKAX,EAAO,QAAUG,IC1JjB,IAAAiB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA2DA,SAASC,EAAgBC,EAAGC,EAASC,EAAQC,EAASC,EAAU,CAC/D,IAAIC,EACAC,EACAC,EACAC,EAUJ,IAPAH,EAAOL,EAAE,KAGTM,EAAMN,EAAE,UAAW,CAAE,EAGrBO,EAAMN,EACAO,EAAIH,EAAK,OAAO,EAAGG,GAAK,EAAGA,IAChCD,EAAMJ,EAAQ,KAAMC,EAASG,EAAKL,EAAQI,EAAKD,EAAMG,CAAE,EAAGA,EAAGH,CAAK,EAAGG,EAAGH,CAAK,EAE9E,OAAOE,CACR,CAKAT,EAAO,QAAUC,IClFjB,IAAAU,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAoB,QAAS,qCAAsC,EACnEC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,4BAA6B,EACnDC,EAAqB,QAAS,yCAA0C,EACxEC,EAAmB,QAAS,qCAAsC,EAClEC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAW,IA6Df,SAASC,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,EAAU,CACjE,GAAK,CAACX,EAAYS,CAAO,EACxB,MAAM,IAAI,UAAWN,EAAQ,oEAAqEM,CAAO,CAAE,EAE5G,GAAK,CAACT,EAAYU,CAAQ,EACzB,MAAM,IAAI,UAAWP,EAAQ,qEAAsEO,CAAQ,CAAE,EAE9G,GAAKX,EAAeQ,CAAI,EACvB,OAAOH,EAAYH,EAAoBM,CAAI,EAAGC,EAASC,EAAQC,EAASC,CAAQ,EAEjF,GAAKb,EAAmBS,CAAI,EAC3B,OAAOF,EAAUH,EAAkBK,CAAI,EAAGC,EAASC,EAAQC,EAASC,CAAQ,EAE7E,MAAM,IAAI,UAAWR,EAAQ,4FAA6FI,CAAI,CAAE,CACjI,CAKAV,EAAO,QAAUS,IClDjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_ndarray", "__commonJSMin", "exports", "module", "vind2bind", "MODE", "mapReduceRight", "x", "initial", "mapper", "reducer", "thisArg", "xbuf", "ordx", "acc", "len", "get", "ref", "shx", "sx", "ox", "ix", "i", "require_array", "__commonJSMin", "exports", "module", "mapReduceRight", "x", "initial", "mapper", "reducer", "thisArg", "xbuf", "get", "acc", "i", "require_main", "__commonJSMin", "exports", "module", "isArrayLikeObject", "isndarrayLike", "isFunction", "ndarraylike2object", "arraylike2object", "format", "ndarrayFcn", "arrayFcn", "mapReduceRight", "arr", "initial", "mapper", "reducer", "thisArg", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b580e87..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, initial, mapper, reducer[, thisArg] ) - Performs a map-reduce operation for each element in an array while iterating - from right to left and returns the accumulated result. - - When invoked, the mapping function is provided three arguments: - - - value: array element. - - index: element index. - - arr: input array. - - When invoked, the reducing function is provided four arguments: - - - accumulator: accumulated value. - - value: result after applying the mapping function to the current array - element. - - index: element index. - - arr: input array. - - If provided an empty array, the function returns the initial value. - - When provided an ndarray, the function performs a single-pass map-reduce - operation over the entire input ndarray (i.e., higher-order ndarray - dimensions are flattened to a single-dimension). - - Parameters - ---------- - arr: ArrayLikeObject|ndarray - Input array. - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - mapper: Function - Mapping function. - - reducer: Function - Reducing function. - - thisArg: any (optional) - Execution context for the reducing function. - - Returns - ------- - out: any - Accumulated result. - - Examples - -------- - // array-like object: - > var f1 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/special/abs}}, 1 ); - > var f2 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/ops/add}}, 2 ); - > var arr = [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0 ]; - > var out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - // ndarray: - > arr = {{alias:@stdlib/ndarray/array}}( arr, { 'shape': [ 2, 3 ] } ); - > out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 3fcccbb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,184 +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. -*/ - -import array = require( '@stdlib/ndarray-array' ); -import mapReduceRight = require( './index' ); - -/** -* Mapping function. -* -* @param value - array element -* @returns result -*/ -function mapper( value: number ): number { - return value; -} - -/** -* Reducing function. -* -* @param acc - accumulated value -* @param v - array element -* @returns result -*/ -function reducer( acc: number, value: number ): number { - return acc + value; -} - - -// TESTS // - -// The function returns the accumulated value when provided a collection... -{ - mapReduceRight( [ 0, 1, 1, NaN, 2 ], 0, mapper, reducer ); // $ExpectType number - mapReduceRight( [ -1, 1, 2 ], 100, mapper, reducer ); // $ExpectType number - mapReduceRight( [ -1, 1, 2 ], 0, mapper, reducer, {} ); // $ExpectType number -} - -// The function returns the accumulated value when provided an ndarray... -{ - const arr = array( [ 1, 2, 3, 4, 5, 6 ] ); - - mapReduceRight( arr, 0, mapper, reducer ); // $ExpectType number - mapReduceRight( arr, 100, mapper, reducer ); // $ExpectType number - mapReduceRight( arr, 0, mapper, reducer, {} ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not a collection or ndarray... -{ - mapReduceRight( 2, 0, mapper, reducer ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer ); // $ExpectError - - mapReduceRight( 2, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr1, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr2, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const arr1 = [ 1, 2, 3 ]; - - mapReduceRight(); // $ExpectError - mapReduceRight( arr1 ); // $ExpectError - mapReduceRight( arr1, 0 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ); // $ExpectError - mapReduceRight( arr1, 0, mapper, reducer, {}, 3 ); // $ExpectError - - const arr2 = array( [ 1, 2, 3 ] ); - - mapReduceRight(); // $ExpectError - mapReduceRight( arr2 ); // $ExpectError - mapReduceRight( arr2, 0 ); // $ExpectError - mapReduceRight( arr2, 0, mapper ); // $ExpectError - mapReduceRight( arr2, 0, mapper, reducer, {}, 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 7474059..0000000 --- a/examples/index.js +++ /dev/null @@ -1,52 +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. -*/ - -'use strict'; - -var filledarrayBy = require( '@stdlib/array-filled-by' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ).factory; -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var mapReduceRight = require( './../lib' ); - -function fill( i ) { - var rand = discreteUniform( -10*(i+1), 10*(i+1) ); - return filledarrayBy( 10, 'generic', rand ); -} - -// Create a two-dimensional ndarray (i.e., a matrix): -var x = array( filledarrayBy( 10, 'generic', fill ), { - 'dtype': 'generic', - 'flatten': true -}); - -// Create an explicit unary function: -var f1 = naryFunction( abs, 1 ); - -// Create an explicit binary function: -var f2 = naryFunction( add, 2 ); - -// Compute the sum of absolute values: -var out = mapReduceRight( x, 0, f1, f2 ); - -console.log( 'x:' ); -console.log( x.data ); - -console.log( 'sum: %d', out ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 2d0e5da..ed593f9 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; import { typedndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..b9d643d --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.1.1-esm/index.mjs";function o(o,a,m,l,j){if(!e(m))throw new TypeError(n("1VL3N,G4",m));if(!e(l))throw new TypeError(n("1VL32,MM",l));if(s(o))return function(r,s,e,t,i){var n,o,a,m,l,j,f,h,c,p,v;if(m=r.length,f=r.shape,n=r.data,h=r.strides,c=r.offset,o=r.order,l=r.accessors[0],j=r.ref,0===f.length)return t.call(i,s,e(l(n,c),0,j),0,j);for(a=s,v=m-1;v>=0;v--)p=d(f,h,c,o,v,"throw"),a=t.call(i,a,e(l(n,p),v,j),v,j);return a}(t(o),a,m,l,j);if(r(o))return function(r,s,e,t,i){var n,d,o,a;for(n=r.data,d=r.accessors[0],o=s,a=n.length-1;a>=0;a--)o=t.call(i,o,e(d(n,a),a,n),a,n);return o}(i(o),a,m,l,j);throw new TypeError(n("1VLBH,O9",o))}export{o as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..d07fb53 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js","../lib/ndarray.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isFunction from '@stdlib/assert-is-function';\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object';\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndarrayFcn from './ndarray.js';\nimport arrayFcn from './array.js';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function';\n* import add from '@stdlib/math-base-ops-add';\n* import abs from '@stdlib/math-base-special-abs';\n* import array from '@stdlib/ndarray-array';\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '1VL3N,G4', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '1VL32,MM', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '1VLBH,O9', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind';\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64';\n* import Complex64 from '@stdlib/complex-float32';\n* import realf from '@stdlib/complex-realf';\n* import imagf from '@stdlib/complex-imagf';\n* import cceil from '@stdlib/math-base-special-cceil';\n* import cadd from '@stdlib/math-base-ops-cadd';\n* import naryFunction from '@stdlib/utils-nary-function';\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","accessors","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;srBA0FA,SAASA,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,WAAYL,IAE1C,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,WAAYJ,IAE1C,GAAKK,EAAeR,GACnB,OCGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,UAAW,GAGnBZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAtH1B,SAuHTR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,CACR,CDnDSkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OE1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,UAAW,GAGnBf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,CACR,CFwBSqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,WAAYP,GAC1C"} \ No newline at end of file diff --git a/lib/array.js b/lib/array.js deleted file mode 100644 index 69c0a8c..0000000 --- a/lib/array.js +++ /dev/null @@ -1,83 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input array data -* @param {ArrayLikeObject} x.data - input array data -* @param {Array} x.accessors - input array accessors -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf[ idx ]; -* } -* -* // Create the input array object: -* var x = { -* 'data': [ 1, 2, 3, 4 ], -* 'accessors': [ getter ] -* }; -* -* // Compute the sum of squared values: -* var out = mapReduceRight( x, 0, square, sum ); -* // returns 30 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var get; - var acc; - var i; - - // Cache reference to the input data: - xbuf = x.data; - - // Cache the element accessor: - get = x.accessors[ 0 ]; - - // Iterate over each element... - acc = initial; - for ( i = xbuf.length-1; i >= 0; i-- ) { - acc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 522693e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +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. -*/ - -'use strict'; - -/** -* Perform a map-reduce operation against each element in an array while iterating from right to left and return the accumulated result. -* -* @module @stdlib/utils-map-reduce-right -* -* @example -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ - -// 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 20efedd..0000000 --- a/lib/main.js +++ /dev/null @@ -1,110 +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. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ndarrayFcn = require( './ndarray.js' ); -var arrayFcn = require( './array.js' ); - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided the following arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided the following arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result of applying the mapping function against the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* @param {(ArrayLikeObject|ndarray)} arr - input array -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} [thisArg] - reduction function execution context -* @throws {TypeError} first argument must be an array-like object or an ndarray -* @throws {TypeError} third argument must be a function -* @throws {TypeError} fourth argument must be a function -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { - if ( !isFunction( mapper ) ) { - throw new TypeError( format( '1VL3N,G4', mapper ) ); - } - if ( !isFunction( reducer ) ) { - throw new TypeError( format( '1VL32,MM', reducer ) ); - } - if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like - return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - if ( isArrayLikeObject( arr ) ) { - return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - throw new TypeError( format( '1VLBH,O9', arr ) ); -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/ndarray.js b/lib/ndarray.js deleted file mode 100644 index 06e19a5..0000000 --- a/lib/ndarray.js +++ /dev/null @@ -1,155 +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. -*/ - -'use strict'; - -// MODULES // - -var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); - - -// VARIABLES // - -var MODE = 'throw'; - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input ndarray meta data -* @param {string} x.ref - reference to original input ndarray-like object -* @param {string} x.dtype - data type -* @param {Collection} x.data - data buffer -* @param {NonNegativeInteger} x.length - number of elements -* @param {NonNegativeIntegerArray} x.shape - dimensions -* @param {IntegerArray} x.strides - stride lengths -* @param {NonNegativeInteger} x.offset - index offset -* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) -* @param {Array} x.accessors - accessors for accessing data buffer elements -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var Complex64 = require( '@stdlib/complex-float32' ); -* var realf = require( '@stdlib/complex-realf' ); -* var imagf = require( '@stdlib/complex-imagf' ); -* var cceil = require( '@stdlib/math-base-special-cceil' ); -* var cadd = require( '@stdlib/math-base-ops-cadd' ); -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* -* // Create a data buffer: -* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] ); -* -* // Define the shape of the input array: -* var shape = [ 2, 2 ]; -* -* // Define the array strides: -* var sx = [ 2, 1 ]; -* -* // Define the index offset: -* var ox = 0; -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf.get( idx ); -* } -* -* // Create the input ndarray-like object: -* var x = { -* 'ref': null, -* 'dtype': 'complex64', -* 'data': xbuf, -* 'length': 4, -* 'shape': shape, -* 'strides': sx, -* 'offset': ox, -* 'order': 'row-major', -* 'accessors': [ getter ] -* }; -* x.ref = x; -* -* // Compute the sum: -* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) ); -* -* var re = realf( v ); -* // returns 20.0 -* -* var im = imagf( v ); -* // returns 24.0 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var ordx; - var acc; - var len; - var get; - var ref; - var shx; - var sx; - var ox; - var ix; - var i; - - // Cache the total number of elements over which to iterate: - len = x.length; - - // Cache the input array shape: - shx = x.shape; - - // Cache reference to the input ndarray data buffer: - xbuf = x.data; - - // Cache reference to the stride array: - sx = x.strides; - - // Cache the index of the first indexed element: - ox = x.offset; - - // Cache the array order: - ordx = x.order; - - // Cache the element accessor: - get = x.accessors[ 0 ]; - - // Cache the reference to the original input array: - ref = x.ref; - - // Check for a zero-dimensional array... - if ( shx.length === 0 ) { - return reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len - } - // Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)... - acc = initial; - for ( i = len-1; i >= 0; i-- ) { - ix = vind2bind( shx, sx, ox, ordx, i, MODE ); - acc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/package.json b/package.json index e6446b2..75d88cc 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Perform a single-pass map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.", "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/array-base-arraylike2object": "^0.1.0", - "@stdlib/assert-is-array-like-object": "^0.1.0", - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/ndarray-base-ndarraylike2object": "^0.1.0", - "@stdlib/ndarray-base-vind2bind": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0" - }, - "devDependencies": { - "@stdlib/array-base-filled": "^0.1.0", - "@stdlib/array-complex64": "^0.1.0", - "@stdlib/array-filled-by": "^0.1.0", - "@stdlib/array-float64": "^0.1.1", - "@stdlib/bench": "^0.2.1", - "@stdlib/complex-float32": "^0.1.1", - "@stdlib/complex-imagf": "^0.1.1", - "@stdlib/complex-realf": "^0.1.1", - "@stdlib/math-base-assert-is-nan": "^0.1.1", - "@stdlib/math-base-ops-add": "^0.1.0", - "@stdlib/math-base-ops-cadd": "^0.1.0", - "@stdlib/math-base-special-abs": "^0.1.1", - "@stdlib/math-base-special-cceil": "^0.1.1", - "@stdlib/math-base-special-pow": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/random-base-discrete-uniform": "^0.1.0", - "@stdlib/utils-nary-function": "^0.1.0", - "@stdlib/utils-noop": "^0.1.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" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..08676ac --- /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/test.js b/test/test.js deleted file mode 100644 index 2c78efa..0000000 --- a/test/test.js +++ /dev/null @@ -1,637 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var cadd = require( '@stdlib/math-base-ops-cadd' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var cceil = require( '@stdlib/math-base-special-cceil' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var mapReduceRight = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapReduceRight, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a first argument which is either an array-like object or an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( value, 0, noop, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value, {} ); - }; - } -}); - -tape( 'the function performs a map-reduce operation for each element in an array (array-like object)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = [ -1, -2, -3 ]; - expected = 7; - actual = mapReduceRight( arr, 1, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (typed array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - expected = 7.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (complex number array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( cceil, 1 ); - f2 = naryFunction( cadd, 2 ); - - arr = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5 ] ); - expected = new Complex64( 12.0, 15.0 ); - actual = mapReduceRight( arr, new Complex64( 0.0, 0.0 ), f1, f2 ); - - t.strictEqual( realf( actual ), realf( expected ), 'returns expected value' ); - t.strictEqual( imagf( actual ), imagf( expected ), 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = array( [ -1.0, -2.0, -3.0, -4.0 ], { - 'dtype': 'generic' - }); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray; 0-dimensional)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = ndarray( 'generic', [ -10.0 ], [], [ 0 ], 0, 'row-major' ); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (array-like object)', function test( t ) { - var out = mapReduceRight( [], 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (ndarray)', function test( t ) { - var arr; - var out; - - arr = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 0, 2 ], [ 0, 2, 1 ], 0, 'row-major' ); - out = mapReduceRight( arr, 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function supports providing a `this` context (array-like object)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = [ -1.0, -2.0, -3.0 ]; - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function supports providing a `this` context (ndarray)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = array( [ -1.0, -2.0, -3.0 ], { - 'dtype': 'generic' - }); - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = array( [ 1, , , 4 ], { // eslint-disable-line no-sparse-arrays - 'dtype': 'generic' - }); - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); From 95fca3661f3d6843c8e921c8cb0a2e5874aa2603 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 08:37:22 +0000 Subject: [PATCH 55/91] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4507c1b..249f2f1 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-ndarray-like": "^0.1.0", "@stdlib/ndarray-base-ndarraylike2object": "^0.1.0", "@stdlib/ndarray-base-vind2bind": "^0.1.1", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0" }, "devDependencies": { From baa2028f39f9af3ac6cb42c8222285357ad7a1c1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 15:12:34 +0000 Subject: [PATCH 56/91] Remove files --- index.d.ts | 257 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6439 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 ed593f9..0000000 --- a/index.d.ts +++ /dev/null @@ -1,257 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; -import { typedndarray } from '@stdlib/types/ndarray'; - -/** -* Callback invoked for each array element. -* -* @returns result -*/ -type Nullary = () => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @returns result -*/ -type Unary = ( value: T ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @returns result -*/ -type Binary = ( value: T, index: number ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Ternary = ( value: T, index: number, arr: typedndarray ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayTernary = ( value: T, index: number, arr: Collection ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Mapper = Nullary | Unary | Binary | Ternary; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayMapper = Nullary | Unary | Binary | ArrayTernary; - -/** -* Function applied against an accumulator. -* -* @returns accumulator value -*/ -type NullaryReducer = ( this: W ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @returns accumulator value -*/ -type UnaryReducer = ( this: W, accumulator: V ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @returns accumulator value -*/ -type BinaryReducer = ( this: W, accumulator: V, value: U ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @returns accumulator value -*/ -type TernaryReducer = ( this: W, accumulator: V, value: U, index: number ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type QuaternaryReducer = ( this: W, accumulator: V, value: U, index: number, arr: typedndarray ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayQuaternaryReducer = ( this: W, accumulator: V, value: U, index: number, arr: Collection ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type Reducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | QuaternaryReducer; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayReducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | ArrayQuaternaryReducer; - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* var naryFunction = require( `@stdlib/utils/nary-function` ); -* var abs = require( `@stdlib/math/base/special/abs` ); -* var add = require( `@stdlib/math/base/ops/add` ); -* var array = require( `@stdlib/ndarray/array` ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 2 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -declare function mapReduceRight( arr: typedndarray, initial: V, mapper: Mapper, reducer: Reducer, thisArg?: ThisParameterType> ): V; - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -*/ -declare function mapReduceRight( arr: Collection, initial: V, mapper: ArrayMapper, reducer: ArrayReducer, thisArg?: ThisParameterType> ): V; - - -// EXPORTS // - -export = mapReduceRight; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index b9d643d..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@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 e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.1.1-esm/index.mjs";function o(o,a,m,l,j){if(!e(m))throw new TypeError(n("1VL3N,G4",m));if(!e(l))throw new TypeError(n("1VL32,MM",l));if(s(o))return function(r,s,e,t,i){var n,o,a,m,l,j,f,h,c,p,v;if(m=r.length,f=r.shape,n=r.data,h=r.strides,c=r.offset,o=r.order,l=r.accessors[0],j=r.ref,0===f.length)return t.call(i,s,e(l(n,c),0,j),0,j);for(a=s,v=m-1;v>=0;v--)p=d(f,h,c,o,v,"throw"),a=t.call(i,a,e(l(n,p),v,j),v,j);return a}(t(o),a,m,l,j);if(r(o))return function(r,s,e,t,i){var n,d,o,a;for(n=r.data,d=r.accessors[0],o=s,a=n.length-1;a>=0;a--)o=t.call(i,o,e(d(n,a),a,n),a,n);return o}(i(o),a,m,l,j);throw new TypeError(n("1VLBH,O9",o))}export{o as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index d07fb53..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js","../lib/ndarray.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isFunction from '@stdlib/assert-is-function';\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object';\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndarrayFcn from './ndarray.js';\nimport arrayFcn from './array.js';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function';\n* import add from '@stdlib/math-base-ops-add';\n* import abs from '@stdlib/math-base-special-abs';\n* import array from '@stdlib/ndarray-array';\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '1VL3N,G4', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '1VL32,MM', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '1VLBH,O9', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind';\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64';\n* import Complex64 from '@stdlib/complex-float32';\n* import realf from '@stdlib/complex-realf';\n* import imagf from '@stdlib/complex-imagf';\n* import cceil from '@stdlib/math-base-special-cceil';\n* import cadd from '@stdlib/math-base-ops-cadd';\n* import naryFunction from '@stdlib/utils-nary-function';\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","accessors","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;srBA0FA,SAASA,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,WAAYL,IAE1C,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,WAAYJ,IAE1C,GAAKK,EAAeR,GACnB,OCGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,UAAW,GAGnBZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAtH1B,SAuHTR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,CACR,CDnDSkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OE1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,UAAW,GAGnBf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,CACR,CFwBSqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,WAAYP,GAC1C"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 08676ac..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 064fc1467a1ac8f2bd492391d01b345cf680f94b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 15:13:04 +0000 Subject: [PATCH 57/91] 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 | 69 +- SECURITY.md | 5 - benchmark/benchmark.array.js | 98 - benchmark/benchmark.ndarray.js | 109 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 9 - dist/index.js.map | 7 - docs/repl.txt | 65 - docs/types/test.ts | 184 - examples/index.js | 52 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/array.js | 83 - lib/index.js | 65 - lib/main.js | 110 - lib/ndarray.js | 155 - package.json | 76 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 637 --- 46 files changed, 6216 insertions(+), 4945 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.array.js delete mode 100644 benchmark/benchmark.ndarray.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/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/array.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/ndarray.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.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 a37f991..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-01-01T05:33:54.918Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3b4c7b4..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/utils/map-reduce-right) 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 f23359f..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/utils/map-reduce-right) 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 071c505..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: '21 21 * * 4' - - # 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 + + ```
@@ -279,7 +272,7 @@ console.log( 'sum: %d', out ); ## 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]. @@ -339,19 +332,19 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/utils-map-reduce-right/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64 +[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64/tree/esm -[@stdlib/array/complex128]: https://github.com/stdlib-js/array-complex128 +[@stdlib/array/complex128]: https://github.com/stdlib-js/array-complex128/tree/esm -[@stdlib/utils/map-right]: https://github.com/stdlib-js/utils-map-right +[@stdlib/utils/map-right]: https://github.com/stdlib-js/utils-map-right/tree/esm -[@stdlib/utils/map-reduce]: https://github.com/stdlib-js/utils-map-reduce +[@stdlib/utils/map-reduce]: https://github.com/stdlib-js/utils-map-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/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.array.js b/benchmark/benchmark.array.js deleted file mode 100644 index da29c82..0000000 --- a/benchmark/benchmark.array.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = filled( -3.0, len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::array:len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.ndarray.js b/benchmark/benchmark.ndarray.js deleted file mode 100644 index 7806caa..0000000 --- a/benchmark/benchmark.ndarray.js +++ /dev/null @@ -1,109 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var xbuf; - var opts; - var x; - - xbuf = filled( -3.0, len ); - - opts = { - 'dtype': 'generic' - }; - x = array( xbuf, opts ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::ndarray:len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index cd78ec7..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/utils/map-reduce-right" -%% click B href "https://github.com/stdlib-js/utils-map-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-map-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-map-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-map-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-map-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/map-reduce-right -[production-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/deno -[umd-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/umd -[esm-url]: https://github.com/stdlib-js/utils-map-reduce-right/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 63ea99a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import mapReduceRight from '../docs/types/index'; -export = mapReduceRight; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 3180c8b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,9 +0,0 @@ -"use strict";var g=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var q=g(function(H,m){ -var E=require('@stdlib/ndarray-base-vind2bind/dist'),T="throw";function p(r,e,a,t,s){var i,v,n,u,f,c,l,y,d,b,o;if(u=r.length,l=r.shape,i=r.data,y=r.strides,d=r.offset,v=r.order,f=r.accessors[0],c=r.ref,l.length===0)return t.call(s,e,a(f(i,d),0,c),0,c);for(n=e,o=u-1;o>=0;o--)b=E(l,y,d,v,o,T),n=t.call(s,n,a(f(i,b),o,c),o,c);return n}m.exports=p -});var R=g(function(I,w){ -function x(r,e,a,t,s){var i,v,n,u;for(i=r.data,v=r.accessors[0],n=e,u=i.length-1;u>=0;u--)n=t.call(s,n,a(v(i,u),u,i),u,i);return n}w.exports=x -});var j=g(function(J,F){ -var V=require('@stdlib/assert-is-array-like-object/dist'),L=require('@stdlib/assert-is-ndarray-like/dist'),k=require('@stdlib/assert-is-function/dist'),O=require('@stdlib/ndarray-base-ndarraylike2object/dist'),D=require('@stdlib/array-base-arraylike2object/dist'),h=require('@stdlib/error-tools-fmtprodmsg/dist'),M=q(),z=R();function B(r,e,a,t,s){if(!k(a))throw new TypeError(h('1VL3N',a));if(!k(t))throw new TypeError(h('1VL32',t));if(L(r))return M(O(r),e,a,t,s);if(V(r))return z(D(r),e,a,t,s);throw new TypeError(h('1VLBH',r))}F.exports=B -});var C=j();module.exports=C; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 641859d..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/ndarray.js", "../lib/array.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* var Complex64Array = require( '@stdlib/array-complex64' );\n* var Complex64 = require( '@stdlib/complex-float32' );\n* var realf = require( '@stdlib/complex-realf' );\n* var imagf = require( '@stdlib/complex-imagf' );\n* var cceil = require( '@stdlib/math-base-special-cceil' );\n* var cadd = require( '@stdlib/math-base-ops-cadd' );\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar format = require( '@stdlib/string-format' );\nvar ndarrayFcn = require( './ndarray.js' );\nvar arrayFcn = require( './array.js' );\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/math-base-ops-add' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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* Perform a map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.\n*\n* @module @stdlib/utils-map-reduce-right\n*\n* @example\n* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' );\n*\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, sum );\n* // returns 30\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/math-base-ops-add' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\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,EAAY,QAAS,gCAAiC,EAKtDC,EAAO,QA0EX,SAASC,EAAgBC,EAAGC,EAASC,EAAQC,EAASC,EAAU,CAC/D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMR,EAAE,OAGRW,EAAMX,EAAE,MAGRK,EAAOL,EAAE,KAGTY,EAAKZ,EAAE,QAGPa,EAAKb,EAAE,OAGPM,EAAON,EAAE,MAGTS,EAAMT,EAAE,UAAW,CAAE,EAGrBU,EAAMV,EAAE,IAGHW,EAAI,SAAW,EACnB,OAAOR,EAAQ,KAAMC,EAASH,EAASC,EAAQO,EAAKJ,EAAMQ,CAAG,EAAG,EAAGH,CAAI,EAAG,EAAGA,CAAI,EAIlF,IADAH,EAAMN,EACAc,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKjB,EAAWc,EAAKC,EAAIC,EAAIP,EAAMS,EAAGjB,CAAK,EAC3CS,EAAMJ,EAAQ,KAAMC,EAASG,EAAKL,EAAQO,EAAKJ,EAAMS,CAAG,EAAGC,EAAGL,CAAI,EAAGK,EAAGL,CAAI,EAE7E,OAAOH,CACR,CAKAX,EAAO,QAAUG,IC1JjB,IAAAiB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA2DA,SAASC,EAAgBC,EAAGC,EAASC,EAAQC,EAASC,EAAU,CAC/D,IAAIC,EACAC,EACAC,EACAC,EAUJ,IAPAH,EAAOL,EAAE,KAGTM,EAAMN,EAAE,UAAW,CAAE,EAGrBO,EAAMN,EACAO,EAAIH,EAAK,OAAO,EAAGG,GAAK,EAAGA,IAChCD,EAAMJ,EAAQ,KAAMC,EAASG,EAAKL,EAAQI,EAAKD,EAAMG,CAAE,EAAGA,EAAGH,CAAK,EAAGG,EAAGH,CAAK,EAE9E,OAAOE,CACR,CAKAT,EAAO,QAAUC,IClFjB,IAAAU,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAoB,QAAS,qCAAsC,EACnEC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,4BAA6B,EACnDC,EAAqB,QAAS,yCAA0C,EACxEC,EAAmB,QAAS,qCAAsC,EAClEC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAW,IA6Df,SAASC,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,EAAU,CACjE,GAAK,CAACX,EAAYS,CAAO,EACxB,MAAM,IAAI,UAAWN,EAAQ,oEAAqEM,CAAO,CAAE,EAE5G,GAAK,CAACT,EAAYU,CAAQ,EACzB,MAAM,IAAI,UAAWP,EAAQ,qEAAsEO,CAAQ,CAAE,EAE9G,GAAKX,EAAeQ,CAAI,EACvB,OAAOH,EAAYH,EAAoBM,CAAI,EAAGC,EAASC,EAAQC,EAASC,CAAQ,EAEjF,GAAKb,EAAmBS,CAAI,EAC3B,OAAOF,EAAUH,EAAkBK,CAAI,EAAGC,EAASC,EAAQC,EAASC,CAAQ,EAE7E,MAAM,IAAI,UAAWR,EAAQ,4FAA6FI,CAAI,CAAE,CACjI,CAKAV,EAAO,QAAUS,IClDjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_ndarray", "__commonJSMin", "exports", "module", "vind2bind", "MODE", "mapReduceRight", "x", "initial", "mapper", "reducer", "thisArg", "xbuf", "ordx", "acc", "len", "get", "ref", "shx", "sx", "ox", "ix", "i", "require_array", "__commonJSMin", "exports", "module", "mapReduceRight", "x", "initial", "mapper", "reducer", "thisArg", "xbuf", "get", "acc", "i", "require_main", "__commonJSMin", "exports", "module", "isArrayLikeObject", "isndarrayLike", "isFunction", "ndarraylike2object", "arraylike2object", "format", "ndarrayFcn", "arrayFcn", "mapReduceRight", "arr", "initial", "mapper", "reducer", "thisArg", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b580e87..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, initial, mapper, reducer[, thisArg] ) - Performs a map-reduce operation for each element in an array while iterating - from right to left and returns the accumulated result. - - When invoked, the mapping function is provided three arguments: - - - value: array element. - - index: element index. - - arr: input array. - - When invoked, the reducing function is provided four arguments: - - - accumulator: accumulated value. - - value: result after applying the mapping function to the current array - element. - - index: element index. - - arr: input array. - - If provided an empty array, the function returns the initial value. - - When provided an ndarray, the function performs a single-pass map-reduce - operation over the entire input ndarray (i.e., higher-order ndarray - dimensions are flattened to a single-dimension). - - Parameters - ---------- - arr: ArrayLikeObject|ndarray - Input array. - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - mapper: Function - Mapping function. - - reducer: Function - Reducing function. - - thisArg: any (optional) - Execution context for the reducing function. - - Returns - ------- - out: any - Accumulated result. - - Examples - -------- - // array-like object: - > var f1 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/special/abs}}, 1 ); - > var f2 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/ops/add}}, 2 ); - > var arr = [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0 ]; - > var out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - // ndarray: - > arr = {{alias:@stdlib/ndarray/array}}( arr, { 'shape': [ 2, 3 ] } ); - > out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 3fcccbb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,184 +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. -*/ - -import array = require( '@stdlib/ndarray-array' ); -import mapReduceRight = require( './index' ); - -/** -* Mapping function. -* -* @param value - array element -* @returns result -*/ -function mapper( value: number ): number { - return value; -} - -/** -* Reducing function. -* -* @param acc - accumulated value -* @param v - array element -* @returns result -*/ -function reducer( acc: number, value: number ): number { - return acc + value; -} - - -// TESTS // - -// The function returns the accumulated value when provided a collection... -{ - mapReduceRight( [ 0, 1, 1, NaN, 2 ], 0, mapper, reducer ); // $ExpectType number - mapReduceRight( [ -1, 1, 2 ], 100, mapper, reducer ); // $ExpectType number - mapReduceRight( [ -1, 1, 2 ], 0, mapper, reducer, {} ); // $ExpectType number -} - -// The function returns the accumulated value when provided an ndarray... -{ - const arr = array( [ 1, 2, 3, 4, 5, 6 ] ); - - mapReduceRight( arr, 0, mapper, reducer ); // $ExpectType number - mapReduceRight( arr, 100, mapper, reducer ); // $ExpectType number - mapReduceRight( arr, 0, mapper, reducer, {} ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not a collection or ndarray... -{ - mapReduceRight( 2, 0, mapper, reducer ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer ); // $ExpectError - - mapReduceRight( 2, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr1, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr2, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const arr1 = [ 1, 2, 3 ]; - - mapReduceRight(); // $ExpectError - mapReduceRight( arr1 ); // $ExpectError - mapReduceRight( arr1, 0 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ); // $ExpectError - mapReduceRight( arr1, 0, mapper, reducer, {}, 3 ); // $ExpectError - - const arr2 = array( [ 1, 2, 3 ] ); - - mapReduceRight(); // $ExpectError - mapReduceRight( arr2 ); // $ExpectError - mapReduceRight( arr2, 0 ); // $ExpectError - mapReduceRight( arr2, 0, mapper ); // $ExpectError - mapReduceRight( arr2, 0, mapper, reducer, {}, 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 7474059..0000000 --- a/examples/index.js +++ /dev/null @@ -1,52 +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. -*/ - -'use strict'; - -var filledarrayBy = require( '@stdlib/array-filled-by' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ).factory; -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var mapReduceRight = require( './../lib' ); - -function fill( i ) { - var rand = discreteUniform( -10*(i+1), 10*(i+1) ); - return filledarrayBy( 10, 'generic', rand ); -} - -// Create a two-dimensional ndarray (i.e., a matrix): -var x = array( filledarrayBy( 10, 'generic', fill ), { - 'dtype': 'generic', - 'flatten': true -}); - -// Create an explicit unary function: -var f1 = naryFunction( abs, 1 ); - -// Create an explicit binary function: -var f2 = naryFunction( add, 2 ); - -// Compute the sum of absolute values: -var out = mapReduceRight( x, 0, f1, f2 ); - -console.log( 'x:' ); -console.log( x.data ); - -console.log( 'sum: %d', out ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 2d0e5da..ed593f9 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; import { typedndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..c68801a --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.1.1-esm/index.mjs";function d(d,o,m,l,f){if(!e(m))throw new TypeError(i("invalid argument. Third argument must be a function. Value: `%s`.",m));if(!e(l))throw new TypeError(i("invalid argument. Fourth argument must be a function. Value: `%s`.",l));if(t(d))return function(r,t,e,s,n){var i,d,o,m,l,f,j,u,c,h,v;if(m=r.length,j=r.shape,i=r.data,u=r.strides,c=r.offset,d=r.order,l=r.accessors[0],f=r.ref,0===j.length)return s.call(n,t,e(l(i,c),0,f),0,f);for(o=t,v=m-1;v>=0;v--)h=a(j,u,c,d,v,"throw"),o=s.call(n,o,e(l(i,h),v,f),v,f);return o}(s(d),o,m,l,f);if(r(d))return function(r,t,e,s,n){var i,a,d,o;for(i=r.data,a=r.accessors[0],d=t,o=i.length-1;o>=0;o--)d=s.call(n,d,e(a(i,o),o,i),o,i);return d}(n(d),o,m,l,f);throw new TypeError(i("invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.",d))}export{d as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..56515c0 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js","../lib/ndarray.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isFunction from '@stdlib/assert-is-function';\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object';\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport format from '@stdlib/string-format';\nimport ndarrayFcn from './ndarray.js';\nimport arrayFcn from './array.js';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function';\n* import add from '@stdlib/math-base-ops-add';\n* import abs from '@stdlib/math-base-special-abs';\n* import array from '@stdlib/ndarray-array';\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind';\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64';\n* import Complex64 from '@stdlib/complex-float32';\n* import realf from '@stdlib/complex-realf';\n* import imagf from '@stdlib/complex-imagf';\n* import cceil from '@stdlib/math-base-special-cceil';\n* import cadd from '@stdlib/math-base-ops-cadd';\n* import naryFunction from '@stdlib/utils-nary-function';\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","accessors","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;6qBA0FA,SAASA,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,oEAAqEL,IAEnG,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,qEAAsEJ,IAEpG,GAAKK,EAAeR,GACnB,OCGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,UAAW,GAGnBZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAtH1B,SAuHTR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,CACR,CDnDSkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OE1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,UAAW,GAGnBf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,CACR,CFwBSqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,4FAA6FP,GAC3H"} \ No newline at end of file diff --git a/lib/array.js b/lib/array.js deleted file mode 100644 index 69c0a8c..0000000 --- a/lib/array.js +++ /dev/null @@ -1,83 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input array data -* @param {ArrayLikeObject} x.data - input array data -* @param {Array} x.accessors - input array accessors -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf[ idx ]; -* } -* -* // Create the input array object: -* var x = { -* 'data': [ 1, 2, 3, 4 ], -* 'accessors': [ getter ] -* }; -* -* // Compute the sum of squared values: -* var out = mapReduceRight( x, 0, square, sum ); -* // returns 30 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var get; - var acc; - var i; - - // Cache reference to the input data: - xbuf = x.data; - - // Cache the element accessor: - get = x.accessors[ 0 ]; - - // Iterate over each element... - acc = initial; - for ( i = xbuf.length-1; i >= 0; i-- ) { - acc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 522693e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +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. -*/ - -'use strict'; - -/** -* Perform a map-reduce operation against each element in an array while iterating from right to left and return the accumulated result. -* -* @module @stdlib/utils-map-reduce-right -* -* @example -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ - -// 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 d95cde3..0000000 --- a/lib/main.js +++ /dev/null @@ -1,110 +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. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/string-format' ); -var ndarrayFcn = require( './ndarray.js' ); -var arrayFcn = require( './array.js' ); - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided the following arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided the following arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result of applying the mapping function against the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* @param {(ArrayLikeObject|ndarray)} arr - input array -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} [thisArg] - reduction function execution context -* @throws {TypeError} first argument must be an array-like object or an ndarray -* @throws {TypeError} third argument must be a function -* @throws {TypeError} fourth argument must be a function -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { - if ( !isFunction( mapper ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) ); - } - if ( !isFunction( reducer ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) ); - } - if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like - return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - if ( isArrayLikeObject( arr ) ) { - return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) ); -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/ndarray.js b/lib/ndarray.js deleted file mode 100644 index 06e19a5..0000000 --- a/lib/ndarray.js +++ /dev/null @@ -1,155 +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. -*/ - -'use strict'; - -// MODULES // - -var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); - - -// VARIABLES // - -var MODE = 'throw'; - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input ndarray meta data -* @param {string} x.ref - reference to original input ndarray-like object -* @param {string} x.dtype - data type -* @param {Collection} x.data - data buffer -* @param {NonNegativeInteger} x.length - number of elements -* @param {NonNegativeIntegerArray} x.shape - dimensions -* @param {IntegerArray} x.strides - stride lengths -* @param {NonNegativeInteger} x.offset - index offset -* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) -* @param {Array} x.accessors - accessors for accessing data buffer elements -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var Complex64 = require( '@stdlib/complex-float32' ); -* var realf = require( '@stdlib/complex-realf' ); -* var imagf = require( '@stdlib/complex-imagf' ); -* var cceil = require( '@stdlib/math-base-special-cceil' ); -* var cadd = require( '@stdlib/math-base-ops-cadd' ); -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* -* // Create a data buffer: -* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] ); -* -* // Define the shape of the input array: -* var shape = [ 2, 2 ]; -* -* // Define the array strides: -* var sx = [ 2, 1 ]; -* -* // Define the index offset: -* var ox = 0; -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf.get( idx ); -* } -* -* // Create the input ndarray-like object: -* var x = { -* 'ref': null, -* 'dtype': 'complex64', -* 'data': xbuf, -* 'length': 4, -* 'shape': shape, -* 'strides': sx, -* 'offset': ox, -* 'order': 'row-major', -* 'accessors': [ getter ] -* }; -* x.ref = x; -* -* // Compute the sum: -* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) ); -* -* var re = realf( v ); -* // returns 20.0 -* -* var im = imagf( v ); -* // returns 24.0 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var ordx; - var acc; - var len; - var get; - var ref; - var shx; - var sx; - var ox; - var ix; - var i; - - // Cache the total number of elements over which to iterate: - len = x.length; - - // Cache the input array shape: - shx = x.shape; - - // Cache reference to the input ndarray data buffer: - xbuf = x.data; - - // Cache reference to the stride array: - sx = x.strides; - - // Cache the index of the first indexed element: - ox = x.offset; - - // Cache the array order: - ordx = x.order; - - // Cache the element accessor: - get = x.accessors[ 0 ]; - - // Cache the reference to the original input array: - ref = x.ref; - - // Check for a zero-dimensional array... - if ( shx.length === 0 ) { - return reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len - } - // Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)... - acc = initial; - for ( i = len-1; i >= 0; i-- ) { - ix = vind2bind( shx, sx, ox, ordx, i, MODE ); - acc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/package.json b/package.json index 249f2f1..75d88cc 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Perform a single-pass map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.", "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/array-base-arraylike2object": "^0.1.0", - "@stdlib/assert-is-array-like-object": "^0.1.0", - "@stdlib/assert-is-function": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/ndarray-base-ndarraylike2object": "^0.1.0", - "@stdlib/ndarray-base-vind2bind": "^0.1.1", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0" - }, - "devDependencies": { - "@stdlib/array-base-filled": "^0.1.0", - "@stdlib/array-complex64": "^0.1.0", - "@stdlib/array-filled-by": "^0.1.0", - "@stdlib/array-float64": "^0.1.1", - "@stdlib/complex-float32": "^0.1.1", - "@stdlib/complex-imagf": "^0.1.1", - "@stdlib/complex-realf": "^0.1.1", - "@stdlib/math-base-assert-is-nan": "^0.1.1", - "@stdlib/math-base-ops-add": "^0.1.0", - "@stdlib/math-base-ops-cadd": "^0.1.0", - "@stdlib/math-base-special-abs": "^0.1.1", - "@stdlib/math-base-special-cceil": "^0.1.1", - "@stdlib/math-base-special-pow": "^0.1.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/random-base-discrete-uniform": "^0.1.0", - "@stdlib/utils-nary-function": "^0.1.0", - "@stdlib/utils-noop": "^0.1.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.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..95d8c2e --- /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/test.js b/test/test.js deleted file mode 100644 index 2c78efa..0000000 --- a/test/test.js +++ /dev/null @@ -1,637 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var cadd = require( '@stdlib/math-base-ops-cadd' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var cceil = require( '@stdlib/math-base-special-cceil' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var mapReduceRight = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapReduceRight, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a first argument which is either an array-like object or an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( value, 0, noop, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value, {} ); - }; - } -}); - -tape( 'the function performs a map-reduce operation for each element in an array (array-like object)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = [ -1, -2, -3 ]; - expected = 7; - actual = mapReduceRight( arr, 1, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (typed array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - expected = 7.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (complex number array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( cceil, 1 ); - f2 = naryFunction( cadd, 2 ); - - arr = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5 ] ); - expected = new Complex64( 12.0, 15.0 ); - actual = mapReduceRight( arr, new Complex64( 0.0, 0.0 ), f1, f2 ); - - t.strictEqual( realf( actual ), realf( expected ), 'returns expected value' ); - t.strictEqual( imagf( actual ), imagf( expected ), 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = array( [ -1.0, -2.0, -3.0, -4.0 ], { - 'dtype': 'generic' - }); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray; 0-dimensional)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = ndarray( 'generic', [ -10.0 ], [], [ 0 ], 0, 'row-major' ); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (array-like object)', function test( t ) { - var out = mapReduceRight( [], 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (ndarray)', function test( t ) { - var arr; - var out; - - arr = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 0, 2 ], [ 0, 2, 1 ], 0, 'row-major' ); - out = mapReduceRight( arr, 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function supports providing a `this` context (array-like object)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = [ -1.0, -2.0, -3.0 ]; - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function supports providing a `this` context (ndarray)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = array( [ -1.0, -2.0, -3.0 ], { - 'dtype': 'generic' - }); - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = array( [ 1, , , 4 ], { // eslint-disable-line no-sparse-arrays - 'dtype': 'generic' - }); - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); From 26d3d29f5e21bc22c8785cf22b45c3ce64d2d679 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 01:24:50 +0000 Subject: [PATCH 58/91] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e44b779..b5ff1a8 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-ndarray-like": "^0.2.0", "@stdlib/ndarray-base-ndarraylike2object": "^0.2.0", "@stdlib/ndarray-base-vind2bind": "^0.2.0", - "@stdlib/string-format": "^0.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.2.0", "@stdlib/types": "^0.3.1" }, "devDependencies": { From 5be86331364d0de3c73731c36574ad8968bd0dd9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 04:54:45 +0000 Subject: [PATCH 59/91] Remove files --- index.d.ts | 257 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6439 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 ed593f9..0000000 --- a/index.d.ts +++ /dev/null @@ -1,257 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; -import { typedndarray } from '@stdlib/types/ndarray'; - -/** -* Callback invoked for each array element. -* -* @returns result -*/ -type Nullary = () => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @returns result -*/ -type Unary = ( value: T ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @returns result -*/ -type Binary = ( value: T, index: number ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Ternary = ( value: T, index: number, arr: typedndarray ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayTernary = ( value: T, index: number, arr: Collection ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Mapper = Nullary | Unary | Binary | Ternary; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayMapper = Nullary | Unary | Binary | ArrayTernary; - -/** -* Function applied against an accumulator. -* -* @returns accumulator value -*/ -type NullaryReducer = ( this: W ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @returns accumulator value -*/ -type UnaryReducer = ( this: W, accumulator: V ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @returns accumulator value -*/ -type BinaryReducer = ( this: W, accumulator: V, value: U ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @returns accumulator value -*/ -type TernaryReducer = ( this: W, accumulator: V, value: U, index: number ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type QuaternaryReducer = ( this: W, accumulator: V, value: U, index: number, arr: typedndarray ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayQuaternaryReducer = ( this: W, accumulator: V, value: U, index: number, arr: Collection ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type Reducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | QuaternaryReducer; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayReducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | ArrayQuaternaryReducer; - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* var naryFunction = require( `@stdlib/utils/nary-function` ); -* var abs = require( `@stdlib/math/base/special/abs` ); -* var add = require( `@stdlib/math/base/ops/add` ); -* var array = require( `@stdlib/ndarray/array` ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 2 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -declare function mapReduceRight( arr: typedndarray, initial: V, mapper: Mapper, reducer: Reducer, thisArg?: ThisParameterType> ): V; - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -*/ -declare function mapReduceRight( arr: Collection, initial: V, mapper: ArrayMapper, reducer: ArrayReducer, thisArg?: ThisParameterType> ): V; - - -// EXPORTS // - -export = mapReduceRight; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index c68801a..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.1.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.1.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@v0.1.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.1.1-esm/index.mjs";function d(d,o,m,l,f){if(!e(m))throw new TypeError(i("invalid argument. Third argument must be a function. Value: `%s`.",m));if(!e(l))throw new TypeError(i("invalid argument. Fourth argument must be a function. Value: `%s`.",l));if(t(d))return function(r,t,e,s,n){var i,d,o,m,l,f,j,u,c,h,v;if(m=r.length,j=r.shape,i=r.data,u=r.strides,c=r.offset,d=r.order,l=r.accessors[0],f=r.ref,0===j.length)return s.call(n,t,e(l(i,c),0,f),0,f);for(o=t,v=m-1;v>=0;v--)h=a(j,u,c,d,v,"throw"),o=s.call(n,o,e(l(i,h),v,f),v,f);return o}(s(d),o,m,l,f);if(r(d))return function(r,t,e,s,n){var i,a,d,o;for(i=r.data,a=r.accessors[0],d=t,o=i.length-1;o>=0;o--)d=s.call(n,d,e(a(i,o),o,i),o,i);return d}(n(d),o,m,l,f);throw new TypeError(i("invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.",d))}export{d as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 56515c0..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js","../lib/ndarray.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isFunction from '@stdlib/assert-is-function';\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object';\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport format from '@stdlib/string-format';\nimport ndarrayFcn from './ndarray.js';\nimport arrayFcn from './array.js';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function';\n* import add from '@stdlib/math-base-ops-add';\n* import abs from '@stdlib/math-base-special-abs';\n* import array from '@stdlib/ndarray-array';\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind';\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64';\n* import Complex64 from '@stdlib/complex-float32';\n* import realf from '@stdlib/complex-realf';\n* import imagf from '@stdlib/complex-imagf';\n* import cceil from '@stdlib/math-base-special-cceil';\n* import cadd from '@stdlib/math-base-ops-cadd';\n* import naryFunction from '@stdlib/utils-nary-function';\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","accessors","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;6qBA0FA,SAASA,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,oEAAqEL,IAEnG,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,qEAAsEJ,IAEpG,GAAKK,EAAeR,GACnB,OCGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,UAAW,GAGnBZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAtH1B,SAuHTR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,CACR,CDnDSkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OE1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,UAAW,GAGnBf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,CACR,CFwBSqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,4FAA6FP,GAC3H"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 95d8c2e..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From e6afffd6a652c7d0e4c8adba5e7f47f2ac568f07 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 04:56:19 +0000 Subject: [PATCH 60/91] 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 | 71 +- SECURITY.md | 5 - benchmark/benchmark.array.js | 98 - benchmark/benchmark.ndarray.js | 109 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 9 - dist/index.js.map | 7 - docs/repl.txt | 65 - docs/types/test.ts | 184 - examples/index.js | 52 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/array.js | 83 - lib/index.js | 65 - lib/main.js | 110 - lib/ndarray.js | 155 - package.json | 76 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 637 --- 45 files changed, 6216 insertions(+), 4953 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.array.js delete mode 100644 benchmark/benchmark.ndarray.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/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/array.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/ndarray.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.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 3b4c7b4..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/utils/map-reduce-right) 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 f23359f..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/utils/map-reduce-right) 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 90161b2..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: '21 21 * * 4' - - # 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 + + ```
@@ -281,7 +272,7 @@ console.log( 'sum: %d', out ); ## 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]. @@ -344,19 +335,19 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/utils-map-reduce-right/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64 +[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64/tree/esm -[@stdlib/array/complex128]: https://github.com/stdlib-js/array-complex128 +[@stdlib/array/complex128]: https://github.com/stdlib-js/array-complex128/tree/esm -[@stdlib/utils/map-right]: https://github.com/stdlib-js/utils-map-right +[@stdlib/utils/map-right]: https://github.com/stdlib-js/utils-map-right/tree/esm -[@stdlib/utils/map-reduce]: https://github.com/stdlib-js/utils-map-reduce +[@stdlib/utils/map-reduce]: https://github.com/stdlib-js/utils-map-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/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.array.js b/benchmark/benchmark.array.js deleted file mode 100644 index da29c82..0000000 --- a/benchmark/benchmark.array.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = filled( -3.0, len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::array:len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.ndarray.js b/benchmark/benchmark.ndarray.js deleted file mode 100644 index 7806caa..0000000 --- a/benchmark/benchmark.ndarray.js +++ /dev/null @@ -1,109 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var xbuf; - var opts; - var x; - - xbuf = filled( -3.0, len ); - - opts = { - 'dtype': 'generic' - }; - x = array( xbuf, opts ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::ndarray:len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0816c5f..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/utils/map-reduce-right" -%% click B href "https://github.com/stdlib-js/utils-map-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-map-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-map-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-map-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-map-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/map-reduce-right -[production-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-map-reduce-right/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-map-reduce-right/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-map-reduce-right/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 63ea99a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import mapReduceRight from '../docs/types/index'; -export = mapReduceRight; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 3180c8b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,9 +0,0 @@ -"use strict";var g=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var q=g(function(H,m){ -var E=require('@stdlib/ndarray-base-vind2bind/dist'),T="throw";function p(r,e,a,t,s){var i,v,n,u,f,c,l,y,d,b,o;if(u=r.length,l=r.shape,i=r.data,y=r.strides,d=r.offset,v=r.order,f=r.accessors[0],c=r.ref,l.length===0)return t.call(s,e,a(f(i,d),0,c),0,c);for(n=e,o=u-1;o>=0;o--)b=E(l,y,d,v,o,T),n=t.call(s,n,a(f(i,b),o,c),o,c);return n}m.exports=p -});var R=g(function(I,w){ -function x(r,e,a,t,s){var i,v,n,u;for(i=r.data,v=r.accessors[0],n=e,u=i.length-1;u>=0;u--)n=t.call(s,n,a(v(i,u),u,i),u,i);return n}w.exports=x -});var j=g(function(J,F){ -var V=require('@stdlib/assert-is-array-like-object/dist'),L=require('@stdlib/assert-is-ndarray-like/dist'),k=require('@stdlib/assert-is-function/dist'),O=require('@stdlib/ndarray-base-ndarraylike2object/dist'),D=require('@stdlib/array-base-arraylike2object/dist'),h=require('@stdlib/error-tools-fmtprodmsg/dist'),M=q(),z=R();function B(r,e,a,t,s){if(!k(a))throw new TypeError(h('1VL3N',a));if(!k(t))throw new TypeError(h('1VL32',t));if(L(r))return M(O(r),e,a,t,s);if(V(r))return z(D(r),e,a,t,s);throw new TypeError(h('1VLBH',r))}F.exports=B -});var C=j();module.exports=C; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 641859d..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/ndarray.js", "../lib/array.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* var Complex64Array = require( '@stdlib/array-complex64' );\n* var Complex64 = require( '@stdlib/complex-float32' );\n* var realf = require( '@stdlib/complex-realf' );\n* var imagf = require( '@stdlib/complex-imagf' );\n* var cceil = require( '@stdlib/math-base-special-cceil' );\n* var cadd = require( '@stdlib/math-base-ops-cadd' );\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar format = require( '@stdlib/string-format' );\nvar ndarrayFcn = require( './ndarray.js' );\nvar arrayFcn = require( './array.js' );\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/math-base-ops-add' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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* Perform a map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.\n*\n* @module @stdlib/utils-map-reduce-right\n*\n* @example\n* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' );\n*\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, sum );\n* // returns 30\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/math-base-ops-add' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\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,EAAY,QAAS,gCAAiC,EAKtDC,EAAO,QA0EX,SAASC,EAAgBC,EAAGC,EAASC,EAAQC,EAASC,EAAU,CAC/D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMR,EAAE,OAGRW,EAAMX,EAAE,MAGRK,EAAOL,EAAE,KAGTY,EAAKZ,EAAE,QAGPa,EAAKb,EAAE,OAGPM,EAAON,EAAE,MAGTS,EAAMT,EAAE,UAAW,CAAE,EAGrBU,EAAMV,EAAE,IAGHW,EAAI,SAAW,EACnB,OAAOR,EAAQ,KAAMC,EAASH,EAASC,EAAQO,EAAKJ,EAAMQ,CAAG,EAAG,EAAGH,CAAI,EAAG,EAAGA,CAAI,EAIlF,IADAH,EAAMN,EACAc,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKjB,EAAWc,EAAKC,EAAIC,EAAIP,EAAMS,EAAGjB,CAAK,EAC3CS,EAAMJ,EAAQ,KAAMC,EAASG,EAAKL,EAAQO,EAAKJ,EAAMS,CAAG,EAAGC,EAAGL,CAAI,EAAGK,EAAGL,CAAI,EAE7E,OAAOH,CACR,CAKAX,EAAO,QAAUG,IC1JjB,IAAAiB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA2DA,SAASC,EAAgBC,EAAGC,EAASC,EAAQC,EAASC,EAAU,CAC/D,IAAIC,EACAC,EACAC,EACAC,EAUJ,IAPAH,EAAOL,EAAE,KAGTM,EAAMN,EAAE,UAAW,CAAE,EAGrBO,EAAMN,EACAO,EAAIH,EAAK,OAAO,EAAGG,GAAK,EAAGA,IAChCD,EAAMJ,EAAQ,KAAMC,EAASG,EAAKL,EAAQI,EAAKD,EAAMG,CAAE,EAAGA,EAAGH,CAAK,EAAGG,EAAGH,CAAK,EAE9E,OAAOE,CACR,CAKAT,EAAO,QAAUC,IClFjB,IAAAU,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAoB,QAAS,qCAAsC,EACnEC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,4BAA6B,EACnDC,EAAqB,QAAS,yCAA0C,EACxEC,EAAmB,QAAS,qCAAsC,EAClEC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAW,IA6Df,SAASC,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,EAAU,CACjE,GAAK,CAACX,EAAYS,CAAO,EACxB,MAAM,IAAI,UAAWN,EAAQ,oEAAqEM,CAAO,CAAE,EAE5G,GAAK,CAACT,EAAYU,CAAQ,EACzB,MAAM,IAAI,UAAWP,EAAQ,qEAAsEO,CAAQ,CAAE,EAE9G,GAAKX,EAAeQ,CAAI,EACvB,OAAOH,EAAYH,EAAoBM,CAAI,EAAGC,EAASC,EAAQC,EAASC,CAAQ,EAEjF,GAAKb,EAAmBS,CAAI,EAC3B,OAAOF,EAAUH,EAAkBK,CAAI,EAAGC,EAASC,EAAQC,EAASC,CAAQ,EAE7E,MAAM,IAAI,UAAWR,EAAQ,4FAA6FI,CAAI,CAAE,CACjI,CAKAV,EAAO,QAAUS,IClDjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_ndarray", "__commonJSMin", "exports", "module", "vind2bind", "MODE", "mapReduceRight", "x", "initial", "mapper", "reducer", "thisArg", "xbuf", "ordx", "acc", "len", "get", "ref", "shx", "sx", "ox", "ix", "i", "require_array", "__commonJSMin", "exports", "module", "mapReduceRight", "x", "initial", "mapper", "reducer", "thisArg", "xbuf", "get", "acc", "i", "require_main", "__commonJSMin", "exports", "module", "isArrayLikeObject", "isndarrayLike", "isFunction", "ndarraylike2object", "arraylike2object", "format", "ndarrayFcn", "arrayFcn", "mapReduceRight", "arr", "initial", "mapper", "reducer", "thisArg", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b580e87..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, initial, mapper, reducer[, thisArg] ) - Performs a map-reduce operation for each element in an array while iterating - from right to left and returns the accumulated result. - - When invoked, the mapping function is provided three arguments: - - - value: array element. - - index: element index. - - arr: input array. - - When invoked, the reducing function is provided four arguments: - - - accumulator: accumulated value. - - value: result after applying the mapping function to the current array - element. - - index: element index. - - arr: input array. - - If provided an empty array, the function returns the initial value. - - When provided an ndarray, the function performs a single-pass map-reduce - operation over the entire input ndarray (i.e., higher-order ndarray - dimensions are flattened to a single-dimension). - - Parameters - ---------- - arr: ArrayLikeObject|ndarray - Input array. - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - mapper: Function - Mapping function. - - reducer: Function - Reducing function. - - thisArg: any (optional) - Execution context for the reducing function. - - Returns - ------- - out: any - Accumulated result. - - Examples - -------- - // array-like object: - > var f1 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/special/abs}}, 1 ); - > var f2 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/ops/add}}, 2 ); - > var arr = [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0 ]; - > var out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - // ndarray: - > arr = {{alias:@stdlib/ndarray/array}}( arr, { 'shape': [ 2, 3 ] } ); - > out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 3fcccbb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,184 +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. -*/ - -import array = require( '@stdlib/ndarray-array' ); -import mapReduceRight = require( './index' ); - -/** -* Mapping function. -* -* @param value - array element -* @returns result -*/ -function mapper( value: number ): number { - return value; -} - -/** -* Reducing function. -* -* @param acc - accumulated value -* @param v - array element -* @returns result -*/ -function reducer( acc: number, value: number ): number { - return acc + value; -} - - -// TESTS // - -// The function returns the accumulated value when provided a collection... -{ - mapReduceRight( [ 0, 1, 1, NaN, 2 ], 0, mapper, reducer ); // $ExpectType number - mapReduceRight( [ -1, 1, 2 ], 100, mapper, reducer ); // $ExpectType number - mapReduceRight( [ -1, 1, 2 ], 0, mapper, reducer, {} ); // $ExpectType number -} - -// The function returns the accumulated value when provided an ndarray... -{ - const arr = array( [ 1, 2, 3, 4, 5, 6 ] ); - - mapReduceRight( arr, 0, mapper, reducer ); // $ExpectType number - mapReduceRight( arr, 100, mapper, reducer ); // $ExpectType number - mapReduceRight( arr, 0, mapper, reducer, {} ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not a collection or ndarray... -{ - mapReduceRight( 2, 0, mapper, reducer ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer ); // $ExpectError - - mapReduceRight( 2, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr1, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr2, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const arr1 = [ 1, 2, 3 ]; - - mapReduceRight(); // $ExpectError - mapReduceRight( arr1 ); // $ExpectError - mapReduceRight( arr1, 0 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ); // $ExpectError - mapReduceRight( arr1, 0, mapper, reducer, {}, 3 ); // $ExpectError - - const arr2 = array( [ 1, 2, 3 ] ); - - mapReduceRight(); // $ExpectError - mapReduceRight( arr2 ); // $ExpectError - mapReduceRight( arr2, 0 ); // $ExpectError - mapReduceRight( arr2, 0, mapper ); // $ExpectError - mapReduceRight( arr2, 0, mapper, reducer, {}, 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 7474059..0000000 --- a/examples/index.js +++ /dev/null @@ -1,52 +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. -*/ - -'use strict'; - -var filledarrayBy = require( '@stdlib/array-filled-by' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ).factory; -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var mapReduceRight = require( './../lib' ); - -function fill( i ) { - var rand = discreteUniform( -10*(i+1), 10*(i+1) ); - return filledarrayBy( 10, 'generic', rand ); -} - -// Create a two-dimensional ndarray (i.e., a matrix): -var x = array( filledarrayBy( 10, 'generic', fill ), { - 'dtype': 'generic', - 'flatten': true -}); - -// Create an explicit unary function: -var f1 = naryFunction( abs, 1 ); - -// Create an explicit binary function: -var f2 = naryFunction( add, 2 ); - -// Compute the sum of absolute values: -var out = mapReduceRight( x, 0, f1, f2 ); - -console.log( 'x:' ); -console.log( x.data ); - -console.log( 'sum: %d', out ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index f3614c6..861830b 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; import { typedndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..d6fe246 --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@v0.2.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.2.0-esm/index.mjs";function d(d,o,m,l,f){if(!e(m))throw new TypeError(i("invalid argument. Third argument must be a function. Value: `%s`.",m));if(!e(l))throw new TypeError(i("invalid argument. Fourth argument must be a function. Value: `%s`.",l));if(t(d))return function(r,t,e,s,n){var i,d,o,m,l,f,j,u,c,h,v;if(m=r.length,j=r.shape,i=r.data,u=r.strides,c=r.offset,d=r.order,l=r.accessors[0],f=r.ref,0===j.length)return s.call(n,t,e(l(i,c),0,f),0,f);for(o=t,v=m-1;v>=0;v--)h=a(j,u,c,d,v,"throw"),o=s.call(n,o,e(l(i,h),v,f),v,f);return o}(s(d),o,m,l,f);if(r(d))return function(r,t,e,s,n){var i,a,d,o;for(i=r.data,a=r.accessors[0],d=t,o=i.length-1;o>=0;o--)d=s.call(n,d,e(a(i,o),o,i),o,i);return d}(n(d),o,m,l,f);throw new TypeError(i("invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.",d))}export{d as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..56515c0 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/main.js","../lib/ndarray.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isFunction from '@stdlib/assert-is-function';\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object';\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport format from '@stdlib/string-format';\nimport ndarrayFcn from './ndarray.js';\nimport arrayFcn from './array.js';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function';\n* import add from '@stdlib/math-base-ops-add';\n* import abs from '@stdlib/math-base-special-abs';\n* import array from '@stdlib/ndarray-array';\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind';\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64';\n* import Complex64 from '@stdlib/complex-float32';\n* import realf from '@stdlib/complex-realf';\n* import imagf from '@stdlib/complex-imagf';\n* import cceil from '@stdlib/math-base-special-cceil';\n* import cadd from '@stdlib/math-base-ops-cadd';\n* import naryFunction from '@stdlib/utils-nary-function';\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","accessors","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;6qBA0FA,SAASA,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,oEAAqEL,IAEnG,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,qEAAsEJ,IAEpG,GAAKK,EAAeR,GACnB,OCGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,UAAW,GAGnBZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAtH1B,SAuHTR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,CACR,CDnDSkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OE1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,UAAW,GAGnBf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,CACR,CFwBSqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,4FAA6FP,GAC3H"} \ No newline at end of file diff --git a/lib/array.js b/lib/array.js deleted file mode 100644 index 69c0a8c..0000000 --- a/lib/array.js +++ /dev/null @@ -1,83 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input array data -* @param {ArrayLikeObject} x.data - input array data -* @param {Array} x.accessors - input array accessors -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf[ idx ]; -* } -* -* // Create the input array object: -* var x = { -* 'data': [ 1, 2, 3, 4 ], -* 'accessors': [ getter ] -* }; -* -* // Compute the sum of squared values: -* var out = mapReduceRight( x, 0, square, sum ); -* // returns 30 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var get; - var acc; - var i; - - // Cache reference to the input data: - xbuf = x.data; - - // Cache the element accessor: - get = x.accessors[ 0 ]; - - // Iterate over each element... - acc = initial; - for ( i = xbuf.length-1; i >= 0; i-- ) { - acc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 522693e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +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. -*/ - -'use strict'; - -/** -* Perform a map-reduce operation against each element in an array while iterating from right to left and return the accumulated result. -* -* @module @stdlib/utils-map-reduce-right -* -* @example -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ - -// 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 d95cde3..0000000 --- a/lib/main.js +++ /dev/null @@ -1,110 +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. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/string-format' ); -var ndarrayFcn = require( './ndarray.js' ); -var arrayFcn = require( './array.js' ); - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided the following arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided the following arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result of applying the mapping function against the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* @param {(ArrayLikeObject|ndarray)} arr - input array -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} [thisArg] - reduction function execution context -* @throws {TypeError} first argument must be an array-like object or an ndarray -* @throws {TypeError} third argument must be a function -* @throws {TypeError} fourth argument must be a function -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { - if ( !isFunction( mapper ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) ); - } - if ( !isFunction( reducer ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) ); - } - if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like - return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - if ( isArrayLikeObject( arr ) ) { - return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) ); -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/ndarray.js b/lib/ndarray.js deleted file mode 100644 index 06e19a5..0000000 --- a/lib/ndarray.js +++ /dev/null @@ -1,155 +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. -*/ - -'use strict'; - -// MODULES // - -var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); - - -// VARIABLES // - -var MODE = 'throw'; - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input ndarray meta data -* @param {string} x.ref - reference to original input ndarray-like object -* @param {string} x.dtype - data type -* @param {Collection} x.data - data buffer -* @param {NonNegativeInteger} x.length - number of elements -* @param {NonNegativeIntegerArray} x.shape - dimensions -* @param {IntegerArray} x.strides - stride lengths -* @param {NonNegativeInteger} x.offset - index offset -* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) -* @param {Array} x.accessors - accessors for accessing data buffer elements -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var Complex64 = require( '@stdlib/complex-float32' ); -* var realf = require( '@stdlib/complex-realf' ); -* var imagf = require( '@stdlib/complex-imagf' ); -* var cceil = require( '@stdlib/math-base-special-cceil' ); -* var cadd = require( '@stdlib/math-base-ops-cadd' ); -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* -* // Create a data buffer: -* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] ); -* -* // Define the shape of the input array: -* var shape = [ 2, 2 ]; -* -* // Define the array strides: -* var sx = [ 2, 1 ]; -* -* // Define the index offset: -* var ox = 0; -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf.get( idx ); -* } -* -* // Create the input ndarray-like object: -* var x = { -* 'ref': null, -* 'dtype': 'complex64', -* 'data': xbuf, -* 'length': 4, -* 'shape': shape, -* 'strides': sx, -* 'offset': ox, -* 'order': 'row-major', -* 'accessors': [ getter ] -* }; -* x.ref = x; -* -* // Compute the sum: -* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) ); -* -* var re = realf( v ); -* // returns 20.0 -* -* var im = imagf( v ); -* // returns 24.0 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var ordx; - var acc; - var len; - var get; - var ref; - var shx; - var sx; - var ox; - var ix; - var i; - - // Cache the total number of elements over which to iterate: - len = x.length; - - // Cache the input array shape: - shx = x.shape; - - // Cache reference to the input ndarray data buffer: - xbuf = x.data; - - // Cache reference to the stride array: - sx = x.strides; - - // Cache the index of the first indexed element: - ox = x.offset; - - // Cache the array order: - ordx = x.order; - - // Cache the element accessor: - get = x.accessors[ 0 ]; - - // Cache the reference to the original input array: - ref = x.ref; - - // Check for a zero-dimensional array... - if ( shx.length === 0 ) { - return reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len - } - // Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)... - acc = initial; - for ( i = len-1; i >= 0; i-- ) { - ix = vind2bind( shx, sx, ox, ordx, i, MODE ); - acc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/package.json b/package.json index b5ff1a8..adcd22c 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.0", "description": "Perform a single-pass map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.", "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/array-base-arraylike2object": "^0.2.0", - "@stdlib/assert-is-array-like-object": "^0.2.0", - "@stdlib/assert-is-function": "^0.2.0", - "@stdlib/assert-is-ndarray-like": "^0.2.0", - "@stdlib/ndarray-base-ndarraylike2object": "^0.2.0", - "@stdlib/ndarray-base-vind2bind": "^0.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.0", - "@stdlib/types": "^0.3.1" - }, - "devDependencies": { - "@stdlib/array-base-filled": "^0.2.0", - "@stdlib/array-complex64": "^0.1.0", - "@stdlib/array-filled-by": "^0.1.0", - "@stdlib/array-float64": "^0.2.0", - "@stdlib/complex-float32": "^0.2.0", - "@stdlib/complex-imagf": "^0.2.0", - "@stdlib/complex-realf": "^0.2.0", - "@stdlib/math-base-assert-is-nan": "^0.2.0", - "@stdlib/math-base-ops-add": "^0.2.0", - "@stdlib/math-base-ops-cadd": "^0.2.0", - "@stdlib/math-base-special-abs": "^0.2.0", - "@stdlib/math-base-special-cceil": "^0.2.0", - "@stdlib/math-base-special-pow": "^0.2.0", - "@stdlib/ndarray-array": "^0.1.0", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/random-base-discrete-uniform": "^0.1.0", - "@stdlib/utils-nary-function": "^0.2.0", - "@stdlib/utils-noop": "^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", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..2434aba --- /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/test.js b/test/test.js deleted file mode 100644 index 2c78efa..0000000 --- a/test/test.js +++ /dev/null @@ -1,637 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var cadd = require( '@stdlib/math-base-ops-cadd' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var cceil = require( '@stdlib/math-base-special-cceil' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var mapReduceRight = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapReduceRight, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a first argument which is either an array-like object or an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( value, 0, noop, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value, {} ); - }; - } -}); - -tape( 'the function performs a map-reduce operation for each element in an array (array-like object)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = [ -1, -2, -3 ]; - expected = 7; - actual = mapReduceRight( arr, 1, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (typed array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - expected = 7.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (complex number array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( cceil, 1 ); - f2 = naryFunction( cadd, 2 ); - - arr = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5 ] ); - expected = new Complex64( 12.0, 15.0 ); - actual = mapReduceRight( arr, new Complex64( 0.0, 0.0 ), f1, f2 ); - - t.strictEqual( realf( actual ), realf( expected ), 'returns expected value' ); - t.strictEqual( imagf( actual ), imagf( expected ), 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = array( [ -1.0, -2.0, -3.0, -4.0 ], { - 'dtype': 'generic' - }); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray; 0-dimensional)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = ndarray( 'generic', [ -10.0 ], [], [ 0 ], 0, 'row-major' ); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (array-like object)', function test( t ) { - var out = mapReduceRight( [], 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (ndarray)', function test( t ) { - var arr; - var out; - - arr = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 0, 2 ], [ 0, 2, 1 ], 0, 'row-major' ); - out = mapReduceRight( arr, 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function supports providing a `this` context (array-like object)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = [ -1.0, -2.0, -3.0 ]; - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function supports providing a `this` context (ndarray)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = array( [ -1.0, -2.0, -3.0 ], { - 'dtype': 'generic' - }); - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = array( [ 1, , , 4 ], { // eslint-disable-line no-sparse-arrays - 'dtype': 'generic' - }); - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); From ec3cbdc59c27c5fc95747a2638493aa0d60f3152 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 06:39:06 +0000 Subject: [PATCH 61/91] 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 f0c8103..3adc9d3 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import mapReduceRight from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-map-reduce-right@esm/index.mjs'; +import mapReduceRight from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-map-reduce-right@v0.2.0-esm/index.mjs'; ``` #### mapReduceRight( arr, initial, mapper, reducer\[, thisArg ] ) @@ -203,7 +203,7 @@ import naryFunction from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-nary-funct import add from 'https://cdn.jsdelivr.net/gh/stdlib-js/math-base-ops-add@esm/index.mjs'; import abs from 'https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs'; import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; -import mapReduceRight from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-map-reduce-right@esm/index.mjs'; +import mapReduceRight from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-map-reduce-right@v0.2.0-esm/index.mjs'; function fill( i ) { var rand = discreteUniform( -10*(i+1), 10*(i+1) ); From 18588b2da2d78a64533ae59d81bf0cd45e8ae19e Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 06:39:06 +0000 Subject: [PATCH 62/91] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3adc9d3..2c159f3 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import mapReduceRight from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-map-reduce-right@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/utils-map-reduce-right/tags). For example, + ```javascript import mapReduceRight from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-map-reduce-right@v0.2.0-esm/index.mjs'; ``` @@ -203,7 +208,7 @@ import naryFunction from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-nary-funct import add from 'https://cdn.jsdelivr.net/gh/stdlib-js/math-base-ops-add@esm/index.mjs'; import abs from 'https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs'; import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; -import mapReduceRight from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-map-reduce-right@v0.2.0-esm/index.mjs'; +import mapReduceRight from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-map-reduce-right@esm/index.mjs'; function fill( i ) { var rand = discreteUniform( -10*(i+1), 10*(i+1) ); From 9a5de84fd08c7a6a8d8e524294e4daa4ea6069f5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 20:05:43 +0000 Subject: [PATCH 63/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index d95cde3..4b227fe 100644 --- a/lib/main.js +++ b/lib/main.js @@ -25,7 +25,7 @@ var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); var isFunction = require( '@stdlib/assert-is-function' ); var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ndarrayFcn = require( './ndarray.js' ); var arrayFcn = require( './array.js' ); @@ -90,10 +90,10 @@ var arrayFcn = require( './array.js' ); */ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( !isFunction( mapper ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) ); + throw new TypeError( format( '1VL3N', mapper ) ); } if ( !isFunction( reducer ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) ); + throw new TypeError( format( '1VL32', reducer ) ); } if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len @@ -101,7 +101,7 @@ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( isArrayLikeObject( arr ) ) { return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len } - throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) ); + throw new TypeError( format( '1VLBH', arr ) ); } diff --git a/package.json b/package.json index c0b6fbb..a679da8 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-ndarray-like": "^0.2.1", "@stdlib/ndarray-base-ndarraylike2object": "^0.2.1", "@stdlib/ndarray-base-vind2bind": "^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 69118ad19c6076d10033a6150ec9b190238ff807 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 21:28:19 +0000 Subject: [PATCH 64/91] Remove files --- index.d.ts | 257 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6439 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 861830b..0000000 --- a/index.d.ts +++ /dev/null @@ -1,257 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; -import { typedndarray } from '@stdlib/types/ndarray'; - -/** -* Callback invoked for each array element. -* -* @returns result -*/ -type Nullary = () => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @returns result -*/ -type Unary = ( value: T ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @returns result -*/ -type Binary = ( value: T, index: number ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Ternary = ( value: T, index: number, arr: typedndarray ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayTernary = ( value: T, index: number, arr: Collection ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Mapper = Nullary | Unary | Binary | Ternary; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayMapper = Nullary | Unary | Binary | ArrayTernary; - -/** -* Function applied against an accumulator. -* -* @returns accumulator value -*/ -type NullaryReducer = ( this: W ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @returns accumulator value -*/ -type UnaryReducer = ( this: W, accumulator: V ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @returns accumulator value -*/ -type BinaryReducer = ( this: W, accumulator: V, value: U ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @returns accumulator value -*/ -type TernaryReducer = ( this: W, accumulator: V, value: U, index: number ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type QuaternaryReducer = ( this: W, accumulator: V, value: U, index: number, arr: typedndarray ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayQuaternaryReducer = ( this: W, accumulator: V, value: U, index: number, arr: Collection ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type Reducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | QuaternaryReducer; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayReducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | ArrayQuaternaryReducer; - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 2 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -declare function mapReduceRight( arr: typedndarray, initial: V, mapper: Mapper, reducer: Reducer, thisArg?: ThisParameterType> ): V; - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -*/ -declare function mapReduceRight( arr: Collection, initial: V, mapper: ArrayMapper, reducer: ArrayReducer, thisArg?: ThisParameterType> ): V; - - -// EXPORTS // - -export = mapReduceRight; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index d6fe246..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.0-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.0-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@v0.2.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.2.0-esm/index.mjs";function d(d,o,m,l,f){if(!e(m))throw new TypeError(i("invalid argument. Third argument must be a function. Value: `%s`.",m));if(!e(l))throw new TypeError(i("invalid argument. Fourth argument must be a function. Value: `%s`.",l));if(t(d))return function(r,t,e,s,n){var i,d,o,m,l,f,j,u,c,h,v;if(m=r.length,j=r.shape,i=r.data,u=r.strides,c=r.offset,d=r.order,l=r.accessors[0],f=r.ref,0===j.length)return s.call(n,t,e(l(i,c),0,f),0,f);for(o=t,v=m-1;v>=0;v--)h=a(j,u,c,d,v,"throw"),o=s.call(n,o,e(l(i,h),v,f),v,f);return o}(s(d),o,m,l,f);if(r(d))return function(r,t,e,s,n){var i,a,d,o;for(i=r.data,a=r.accessors[0],d=t,o=i.length-1;o>=0;o--)d=s.call(n,d,e(a(i,o),o,i),o,i);return d}(n(d),o,m,l,f);throw new TypeError(i("invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.",d))}export{d as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 56515c0..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/main.js","../lib/ndarray.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isFunction from '@stdlib/assert-is-function';\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object';\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport format from '@stdlib/string-format';\nimport ndarrayFcn from './ndarray.js';\nimport arrayFcn from './array.js';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function';\n* import add from '@stdlib/math-base-ops-add';\n* import abs from '@stdlib/math-base-special-abs';\n* import array from '@stdlib/ndarray-array';\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind';\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64';\n* import Complex64 from '@stdlib/complex-float32';\n* import realf from '@stdlib/complex-realf';\n* import imagf from '@stdlib/complex-imagf';\n* import cceil from '@stdlib/math-base-special-cceil';\n* import cadd from '@stdlib/math-base-ops-cadd';\n* import naryFunction from '@stdlib/utils-nary-function';\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","accessors","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;6qBA0FA,SAASA,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,oEAAqEL,IAEnG,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,qEAAsEJ,IAEpG,GAAKK,EAAeR,GACnB,OCGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,UAAW,GAGnBZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAtH1B,SAuHTR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,CACR,CDnDSkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OE1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,UAAW,GAGnBf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,CACR,CFwBSqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,4FAA6FP,GAC3H"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 2434aba..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 2ab2e77885ad7eee1f29a555f3355053d70af79a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 21:28:38 +0000 Subject: [PATCH 65/91] 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 | 71 +- SECURITY.md | 5 - benchmark/benchmark.array.js | 98 - benchmark/benchmark.ndarray.js | 109 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 9 - dist/index.js.map | 7 - docs/repl.txt | 65 - docs/types/test.ts | 184 - examples/index.js | 52 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/array.js | 83 - lib/index.js | 65 - lib/main.js | 110 - lib/ndarray.js | 155 - package.json | 77 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 637 --- 45 files changed, 4881 insertions(+), 4948 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.array.js delete mode 100644 benchmark/benchmark.ndarray.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/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/array.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/ndarray.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.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 3b4c7b4..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/utils/map-reduce-right) 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 f23359f..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/utils/map-reduce-right) 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 1308146..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: '21 21 * * 4' - - # 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 + + ```
@@ -281,7 +272,7 @@ console.log( 'sum: %d', out ); ## 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]. @@ -344,19 +335,19 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/utils-map-reduce-right/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64 +[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64/tree/esm -[@stdlib/array/complex128]: https://github.com/stdlib-js/array-complex128 +[@stdlib/array/complex128]: https://github.com/stdlib-js/array-complex128/tree/esm -[@stdlib/utils/map-right]: https://github.com/stdlib-js/utils-map-right +[@stdlib/utils/map-right]: https://github.com/stdlib-js/utils-map-right/tree/esm -[@stdlib/utils/map-reduce]: https://github.com/stdlib-js/utils-map-reduce +[@stdlib/utils/map-reduce]: https://github.com/stdlib-js/utils-map-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/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.array.js b/benchmark/benchmark.array.js deleted file mode 100644 index da29c82..0000000 --- a/benchmark/benchmark.array.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = filled( -3.0, len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::array:len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.ndarray.js b/benchmark/benchmark.ndarray.js deleted file mode 100644 index 7806caa..0000000 --- a/benchmark/benchmark.ndarray.js +++ /dev/null @@ -1,109 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var xbuf; - var opts; - var x; - - xbuf = filled( -3.0, len ); - - opts = { - 'dtype': 'generic' - }; - x = array( xbuf, opts ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::ndarray:len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0816c5f..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/utils/map-reduce-right" -%% click B href "https://github.com/stdlib-js/utils-map-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-map-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-map-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-map-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-map-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/map-reduce-right -[production-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-map-reduce-right/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-map-reduce-right/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-map-reduce-right/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 63ea99a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import mapReduceRight from '../docs/types/index'; -export = mapReduceRight; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 3180c8b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,9 +0,0 @@ -"use strict";var g=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var q=g(function(H,m){ -var E=require('@stdlib/ndarray-base-vind2bind/dist'),T="throw";function p(r,e,a,t,s){var i,v,n,u,f,c,l,y,d,b,o;if(u=r.length,l=r.shape,i=r.data,y=r.strides,d=r.offset,v=r.order,f=r.accessors[0],c=r.ref,l.length===0)return t.call(s,e,a(f(i,d),0,c),0,c);for(n=e,o=u-1;o>=0;o--)b=E(l,y,d,v,o,T),n=t.call(s,n,a(f(i,b),o,c),o,c);return n}m.exports=p -});var R=g(function(I,w){ -function x(r,e,a,t,s){var i,v,n,u;for(i=r.data,v=r.accessors[0],n=e,u=i.length-1;u>=0;u--)n=t.call(s,n,a(v(i,u),u,i),u,i);return n}w.exports=x -});var j=g(function(J,F){ -var V=require('@stdlib/assert-is-array-like-object/dist'),L=require('@stdlib/assert-is-ndarray-like/dist'),k=require('@stdlib/assert-is-function/dist'),O=require('@stdlib/ndarray-base-ndarraylike2object/dist'),D=require('@stdlib/array-base-arraylike2object/dist'),h=require('@stdlib/error-tools-fmtprodmsg/dist'),M=q(),z=R();function B(r,e,a,t,s){if(!k(a))throw new TypeError(h('1VL3N',a));if(!k(t))throw new TypeError(h('1VL32',t));if(L(r))return M(O(r),e,a,t,s);if(V(r))return z(D(r),e,a,t,s);throw new TypeError(h('1VLBH',r))}F.exports=B -});var C=j();module.exports=C; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 641859d..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/ndarray.js", "../lib/array.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* var Complex64Array = require( '@stdlib/array-complex64' );\n* var Complex64 = require( '@stdlib/complex-float32' );\n* var realf = require( '@stdlib/complex-realf' );\n* var imagf = require( '@stdlib/complex-imagf' );\n* var cceil = require( '@stdlib/math-base-special-cceil' );\n* var cadd = require( '@stdlib/math-base-ops-cadd' );\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar format = require( '@stdlib/string-format' );\nvar ndarrayFcn = require( './ndarray.js' );\nvar arrayFcn = require( './array.js' );\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/math-base-ops-add' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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* Perform a map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.\n*\n* @module @stdlib/utils-map-reduce-right\n*\n* @example\n* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' );\n*\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, sum );\n* // returns 30\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/math-base-ops-add' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\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,EAAY,QAAS,gCAAiC,EAKtDC,EAAO,QA0EX,SAASC,EAAgBC,EAAGC,EAASC,EAAQC,EAASC,EAAU,CAC/D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMR,EAAE,OAGRW,EAAMX,EAAE,MAGRK,EAAOL,EAAE,KAGTY,EAAKZ,EAAE,QAGPa,EAAKb,EAAE,OAGPM,EAAON,EAAE,MAGTS,EAAMT,EAAE,UAAW,CAAE,EAGrBU,EAAMV,EAAE,IAGHW,EAAI,SAAW,EACnB,OAAOR,EAAQ,KAAMC,EAASH,EAASC,EAAQO,EAAKJ,EAAMQ,CAAG,EAAG,EAAGH,CAAI,EAAG,EAAGA,CAAI,EAIlF,IADAH,EAAMN,EACAc,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKjB,EAAWc,EAAKC,EAAIC,EAAIP,EAAMS,EAAGjB,CAAK,EAC3CS,EAAMJ,EAAQ,KAAMC,EAASG,EAAKL,EAAQO,EAAKJ,EAAMS,CAAG,EAAGC,EAAGL,CAAI,EAAGK,EAAGL,CAAI,EAE7E,OAAOH,CACR,CAKAX,EAAO,QAAUG,IC1JjB,IAAAiB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA2DA,SAASC,EAAgBC,EAAGC,EAASC,EAAQC,EAASC,EAAU,CAC/D,IAAIC,EACAC,EACAC,EACAC,EAUJ,IAPAH,EAAOL,EAAE,KAGTM,EAAMN,EAAE,UAAW,CAAE,EAGrBO,EAAMN,EACAO,EAAIH,EAAK,OAAO,EAAGG,GAAK,EAAGA,IAChCD,EAAMJ,EAAQ,KAAMC,EAASG,EAAKL,EAAQI,EAAKD,EAAMG,CAAE,EAAGA,EAAGH,CAAK,EAAGG,EAAGH,CAAK,EAE9E,OAAOE,CACR,CAKAT,EAAO,QAAUC,IClFjB,IAAAU,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAoB,QAAS,qCAAsC,EACnEC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,4BAA6B,EACnDC,EAAqB,QAAS,yCAA0C,EACxEC,EAAmB,QAAS,qCAAsC,EAClEC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAW,IA6Df,SAASC,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,EAAU,CACjE,GAAK,CAACX,EAAYS,CAAO,EACxB,MAAM,IAAI,UAAWN,EAAQ,oEAAqEM,CAAO,CAAE,EAE5G,GAAK,CAACT,EAAYU,CAAQ,EACzB,MAAM,IAAI,UAAWP,EAAQ,qEAAsEO,CAAQ,CAAE,EAE9G,GAAKX,EAAeQ,CAAI,EACvB,OAAOH,EAAYH,EAAoBM,CAAI,EAAGC,EAASC,EAAQC,EAASC,CAAQ,EAEjF,GAAKb,EAAmBS,CAAI,EAC3B,OAAOF,EAAUH,EAAkBK,CAAI,EAAGC,EAASC,EAAQC,EAASC,CAAQ,EAE7E,MAAM,IAAI,UAAWR,EAAQ,4FAA6FI,CAAI,CAAE,CACjI,CAKAV,EAAO,QAAUS,IClDjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_ndarray", "__commonJSMin", "exports", "module", "vind2bind", "MODE", "mapReduceRight", "x", "initial", "mapper", "reducer", "thisArg", "xbuf", "ordx", "acc", "len", "get", "ref", "shx", "sx", "ox", "ix", "i", "require_array", "__commonJSMin", "exports", "module", "mapReduceRight", "x", "initial", "mapper", "reducer", "thisArg", "xbuf", "get", "acc", "i", "require_main", "__commonJSMin", "exports", "module", "isArrayLikeObject", "isndarrayLike", "isFunction", "ndarraylike2object", "arraylike2object", "format", "ndarrayFcn", "arrayFcn", "mapReduceRight", "arr", "initial", "mapper", "reducer", "thisArg", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b580e87..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, initial, mapper, reducer[, thisArg] ) - Performs a map-reduce operation for each element in an array while iterating - from right to left and returns the accumulated result. - - When invoked, the mapping function is provided three arguments: - - - value: array element. - - index: element index. - - arr: input array. - - When invoked, the reducing function is provided four arguments: - - - accumulator: accumulated value. - - value: result after applying the mapping function to the current array - element. - - index: element index. - - arr: input array. - - If provided an empty array, the function returns the initial value. - - When provided an ndarray, the function performs a single-pass map-reduce - operation over the entire input ndarray (i.e., higher-order ndarray - dimensions are flattened to a single-dimension). - - Parameters - ---------- - arr: ArrayLikeObject|ndarray - Input array. - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - mapper: Function - Mapping function. - - reducer: Function - Reducing function. - - thisArg: any (optional) - Execution context for the reducing function. - - Returns - ------- - out: any - Accumulated result. - - Examples - -------- - // array-like object: - > var f1 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/special/abs}}, 1 ); - > var f2 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/ops/add}}, 2 ); - > var arr = [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0 ]; - > var out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - // ndarray: - > arr = {{alias:@stdlib/ndarray/array}}( arr, { 'shape': [ 2, 3 ] } ); - > out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 3fcccbb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,184 +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. -*/ - -import array = require( '@stdlib/ndarray-array' ); -import mapReduceRight = require( './index' ); - -/** -* Mapping function. -* -* @param value - array element -* @returns result -*/ -function mapper( value: number ): number { - return value; -} - -/** -* Reducing function. -* -* @param acc - accumulated value -* @param v - array element -* @returns result -*/ -function reducer( acc: number, value: number ): number { - return acc + value; -} - - -// TESTS // - -// The function returns the accumulated value when provided a collection... -{ - mapReduceRight( [ 0, 1, 1, NaN, 2 ], 0, mapper, reducer ); // $ExpectType number - mapReduceRight( [ -1, 1, 2 ], 100, mapper, reducer ); // $ExpectType number - mapReduceRight( [ -1, 1, 2 ], 0, mapper, reducer, {} ); // $ExpectType number -} - -// The function returns the accumulated value when provided an ndarray... -{ - const arr = array( [ 1, 2, 3, 4, 5, 6 ] ); - - mapReduceRight( arr, 0, mapper, reducer ); // $ExpectType number - mapReduceRight( arr, 100, mapper, reducer ); // $ExpectType number - mapReduceRight( arr, 0, mapper, reducer, {} ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not a collection or ndarray... -{ - mapReduceRight( 2, 0, mapper, reducer ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer ); // $ExpectError - - mapReduceRight( 2, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr1, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr2, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const arr1 = [ 1, 2, 3 ]; - - mapReduceRight(); // $ExpectError - mapReduceRight( arr1 ); // $ExpectError - mapReduceRight( arr1, 0 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ); // $ExpectError - mapReduceRight( arr1, 0, mapper, reducer, {}, 3 ); // $ExpectError - - const arr2 = array( [ 1, 2, 3 ] ); - - mapReduceRight(); // $ExpectError - mapReduceRight( arr2 ); // $ExpectError - mapReduceRight( arr2, 0 ); // $ExpectError - mapReduceRight( arr2, 0, mapper ); // $ExpectError - mapReduceRight( arr2, 0, mapper, reducer, {}, 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 7474059..0000000 --- a/examples/index.js +++ /dev/null @@ -1,52 +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. -*/ - -'use strict'; - -var filledarrayBy = require( '@stdlib/array-filled-by' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ).factory; -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var mapReduceRight = require( './../lib' ); - -function fill( i ) { - var rand = discreteUniform( -10*(i+1), 10*(i+1) ); - return filledarrayBy( 10, 'generic', rand ); -} - -// Create a two-dimensional ndarray (i.e., a matrix): -var x = array( filledarrayBy( 10, 'generic', fill ), { - 'dtype': 'generic', - 'flatten': true -}); - -// Create an explicit unary function: -var f1 = naryFunction( abs, 1 ); - -// Create an explicit binary function: -var f2 = naryFunction( add, 2 ); - -// Compute the sum of absolute values: -var out = mapReduceRight( x, 0, f1, f2 ); - -console.log( 'x:' ); -console.log( x.data ); - -console.log( 'sum: %d', out ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index f3614c6..861830b 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; import { typedndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..61bdc76 --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.2.1-esm/index.mjs";var o="throw";function a(a,m,l,j,f){if(!e(l))throw new TypeError(n("1VL3N",l));if(!e(j))throw new TypeError(n("1VL32",j));if(s(a))return function(r,s,e,t,i){var n,a,m,l,j,f,h,c,p,v,b;if(l=r.length,h=r.shape,n=r.data,c=r.strides,p=r.offset,a=r.order,j=r.accessors[0],f=r.ref,0===h.length)return t.call(i,s,e(j(n,p),0,f),0,f);for(m=s,b=l-1;b>=0;b--)v=d(h,c,p,a,b,o),m=t.call(i,m,e(j(n,v),b,f),b,f);return m}(t(a),m,l,j,f);if(r(a))return function(r,s,e,t,i){var n,d,o,a;for(n=r.data,d=r.accessors[0],o=s,a=n.length-1;a>=0;a--)o=t.call(i,o,e(d(n,a),a,n),a,n);return o}(i(a),m,l,j,f);throw new TypeError(n("1VLBH",a))}export{a as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..f8ef5f4 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/ndarray.js","../lib/main.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind';\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64';\n* import Complex64 from '@stdlib/complex-float32';\n* import realf from '@stdlib/complex-realf';\n* import imagf from '@stdlib/complex-imagf';\n* import cceil from '@stdlib/math-base-special-cceil';\n* import cadd from '@stdlib/math-base-ops-cadd';\n* import naryFunction from '@stdlib/utils-nary-function';\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isFunction from '@stdlib/assert-is-function';\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object';\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndarrayFcn from './ndarray.js';\nimport arrayFcn from './array.js';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function';\n* import add from '@stdlib/math-base-ops-add';\n* import abs from '@stdlib/math-base-special-abs';\n* import array from '@stdlib/ndarray-array';\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '1VL3N', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '1VL32', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '1VLBH', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["MODE","mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","accessors","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;srBA2BA,IAAIA,EAAO,QC+DX,SAASC,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,GAAKK,EAAeR,GACnB,ODGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,UAAW,GAGnBZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAAGtB,GACtCc,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,CACR,CCnDSkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OC1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,UAAW,GAGnBf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,CACR,CDwBSqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,QAASP,GACvC"} \ No newline at end of file diff --git a/lib/array.js b/lib/array.js deleted file mode 100644 index 69c0a8c..0000000 --- a/lib/array.js +++ /dev/null @@ -1,83 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input array data -* @param {ArrayLikeObject} x.data - input array data -* @param {Array} x.accessors - input array accessors -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf[ idx ]; -* } -* -* // Create the input array object: -* var x = { -* 'data': [ 1, 2, 3, 4 ], -* 'accessors': [ getter ] -* }; -* -* // Compute the sum of squared values: -* var out = mapReduceRight( x, 0, square, sum ); -* // returns 30 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var get; - var acc; - var i; - - // Cache reference to the input data: - xbuf = x.data; - - // Cache the element accessor: - get = x.accessors[ 0 ]; - - // Iterate over each element... - acc = initial; - for ( i = xbuf.length-1; i >= 0; i-- ) { - acc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 522693e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +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. -*/ - -'use strict'; - -/** -* Perform a map-reduce operation against each element in an array while iterating from right to left and return the accumulated result. -* -* @module @stdlib/utils-map-reduce-right -* -* @example -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ - -// 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 4b227fe..0000000 --- a/lib/main.js +++ /dev/null @@ -1,110 +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. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ndarrayFcn = require( './ndarray.js' ); -var arrayFcn = require( './array.js' ); - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided the following arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided the following arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result of applying the mapping function against the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* @param {(ArrayLikeObject|ndarray)} arr - input array -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} [thisArg] - reduction function execution context -* @throws {TypeError} first argument must be an array-like object or an ndarray -* @throws {TypeError} third argument must be a function -* @throws {TypeError} fourth argument must be a function -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { - if ( !isFunction( mapper ) ) { - throw new TypeError( format( '1VL3N', mapper ) ); - } - if ( !isFunction( reducer ) ) { - throw new TypeError( format( '1VL32', reducer ) ); - } - if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like - return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - if ( isArrayLikeObject( arr ) ) { - return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - throw new TypeError( format( '1VLBH', arr ) ); -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/ndarray.js b/lib/ndarray.js deleted file mode 100644 index 06e19a5..0000000 --- a/lib/ndarray.js +++ /dev/null @@ -1,155 +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. -*/ - -'use strict'; - -// MODULES // - -var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); - - -// VARIABLES // - -var MODE = 'throw'; - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input ndarray meta data -* @param {string} x.ref - reference to original input ndarray-like object -* @param {string} x.dtype - data type -* @param {Collection} x.data - data buffer -* @param {NonNegativeInteger} x.length - number of elements -* @param {NonNegativeIntegerArray} x.shape - dimensions -* @param {IntegerArray} x.strides - stride lengths -* @param {NonNegativeInteger} x.offset - index offset -* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) -* @param {Array} x.accessors - accessors for accessing data buffer elements -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var Complex64 = require( '@stdlib/complex-float32' ); -* var realf = require( '@stdlib/complex-realf' ); -* var imagf = require( '@stdlib/complex-imagf' ); -* var cceil = require( '@stdlib/math-base-special-cceil' ); -* var cadd = require( '@stdlib/math-base-ops-cadd' ); -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* -* // Create a data buffer: -* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] ); -* -* // Define the shape of the input array: -* var shape = [ 2, 2 ]; -* -* // Define the array strides: -* var sx = [ 2, 1 ]; -* -* // Define the index offset: -* var ox = 0; -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf.get( idx ); -* } -* -* // Create the input ndarray-like object: -* var x = { -* 'ref': null, -* 'dtype': 'complex64', -* 'data': xbuf, -* 'length': 4, -* 'shape': shape, -* 'strides': sx, -* 'offset': ox, -* 'order': 'row-major', -* 'accessors': [ getter ] -* }; -* x.ref = x; -* -* // Compute the sum: -* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) ); -* -* var re = realf( v ); -* // returns 20.0 -* -* var im = imagf( v ); -* // returns 24.0 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var ordx; - var acc; - var len; - var get; - var ref; - var shx; - var sx; - var ox; - var ix; - var i; - - // Cache the total number of elements over which to iterate: - len = x.length; - - // Cache the input array shape: - shx = x.shape; - - // Cache reference to the input ndarray data buffer: - xbuf = x.data; - - // Cache reference to the stride array: - sx = x.strides; - - // Cache the index of the first indexed element: - ox = x.offset; - - // Cache the array order: - ordx = x.order; - - // Cache the element accessor: - get = x.accessors[ 0 ]; - - // Cache the reference to the original input array: - ref = x.ref; - - // Check for a zero-dimensional array... - if ( shx.length === 0 ) { - return reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len - } - // Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)... - acc = initial; - for ( i = len-1; i >= 0; i-- ) { - ix = vind2bind( shx, sx, ox, ordx, i, MODE ); - acc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/package.json b/package.json index a679da8..3df9694 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Perform a single-pass map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.", "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/array-base-arraylike2object": "^0.2.1", - "@stdlib/assert-is-array-like-object": "^0.2.1", - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/ndarray-base-ndarraylike2object": "^0.2.1", - "@stdlib/ndarray-base-vind2bind": "^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-base-filled": "^0.2.1", - "@stdlib/array-complex64": "^0.2.0", - "@stdlib/array-filled-by": "^0.2.0", - "@stdlib/array-float64": "^0.2.1", - "@stdlib/complex-float32": "^0.2.1", - "@stdlib/complex-imagf": "^0.2.1", - "@stdlib/complex-realf": "^0.2.1", - "@stdlib/math-base-assert-is-nan": "^0.2.1", - "@stdlib/math-base-ops-add": "^0.2.1", - "@stdlib/math-base-ops-cadd": "^0.2.1", - "@stdlib/math-base-special-abs": "^0.2.1", - "@stdlib/math-base-special-cceil": "^0.2.1", - "@stdlib/math-base-special-pow": "^0.2.1", - "@stdlib/ndarray-array": "^0.2.0", - "@stdlib/ndarray-ctor": "^0.2.0", - "@stdlib/random-base-discrete-uniform": "^0.2.0", - "@stdlib/utils-nary-function": "^0.2.1", - "@stdlib/utils-noop": "^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", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..4f77b5c --- /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/test.js b/test/test.js deleted file mode 100644 index 2c78efa..0000000 --- a/test/test.js +++ /dev/null @@ -1,637 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var cadd = require( '@stdlib/math-base-ops-cadd' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var cceil = require( '@stdlib/math-base-special-cceil' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var mapReduceRight = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapReduceRight, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a first argument which is either an array-like object or an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( value, 0, noop, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value, {} ); - }; - } -}); - -tape( 'the function performs a map-reduce operation for each element in an array (array-like object)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = [ -1, -2, -3 ]; - expected = 7; - actual = mapReduceRight( arr, 1, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (typed array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - expected = 7.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (complex number array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( cceil, 1 ); - f2 = naryFunction( cadd, 2 ); - - arr = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5 ] ); - expected = new Complex64( 12.0, 15.0 ); - actual = mapReduceRight( arr, new Complex64( 0.0, 0.0 ), f1, f2 ); - - t.strictEqual( realf( actual ), realf( expected ), 'returns expected value' ); - t.strictEqual( imagf( actual ), imagf( expected ), 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = array( [ -1.0, -2.0, -3.0, -4.0 ], { - 'dtype': 'generic' - }); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray; 0-dimensional)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = ndarray( 'generic', [ -10.0 ], [], [ 0 ], 0, 'row-major' ); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (array-like object)', function test( t ) { - var out = mapReduceRight( [], 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (ndarray)', function test( t ) { - var arr; - var out; - - arr = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 0, 2 ], [ 0, 2, 1 ], 0, 'row-major' ); - out = mapReduceRight( arr, 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function supports providing a `this` context (array-like object)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = [ -1.0, -2.0, -3.0 ]; - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function supports providing a `this` context (ndarray)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = array( [ -1.0, -2.0, -3.0 ], { - 'dtype': 'generic' - }); - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = array( [ 1, , , 4 ], { // eslint-disable-line no-sparse-arrays - 'dtype': 'generic' - }); - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); From 6f5b7be9cf68c65f570b3a3d8e39e37aae18749c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 22:07:25 +0000 Subject: [PATCH 66/91] 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 ce39000..b42f2fd 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import mapReduceRight from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-map-reduce-right@esm/index.mjs'; +import mapReduceRight from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-map-reduce-right@v0.2.1-esm/index.mjs'; ``` #### mapReduceRight( arr, initial, mapper, reducer\[, thisArg ] ) @@ -203,7 +203,7 @@ import naryFunction from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-nary-funct import add from 'https://cdn.jsdelivr.net/gh/stdlib-js/math-base-ops-add@esm/index.mjs'; import abs from 'https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs'; import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; -import mapReduceRight from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-map-reduce-right@esm/index.mjs'; +import mapReduceRight from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-map-reduce-right@v0.2.1-esm/index.mjs'; function fill( i ) { var rand = discreteUniform( -10*(i+1), 10*(i+1) ); From c8636f32879d51ea148b91ac4ca26a45c6eb9aca Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 22:07:26 +0000 Subject: [PATCH 67/91] Auto-generated commit --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b42f2fd..f5bcbeb 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ limitations under the License. ## Usage +```javascript +import mapReduceRight from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-map-reduce-right@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/utils-map-reduce-right/tags). For example, + ```javascript import mapReduceRight from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-map-reduce-right@v0.2.1-esm/index.mjs'; ``` @@ -203,7 +208,7 @@ import naryFunction from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-nary-funct import add from 'https://cdn.jsdelivr.net/gh/stdlib-js/math-base-ops-add@esm/index.mjs'; import abs from 'https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs'; import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; -import mapReduceRight from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-map-reduce-right@v0.2.1-esm/index.mjs'; +import mapReduceRight from 'https://cdn.jsdelivr.net/gh/stdlib-js/utils-map-reduce-right@esm/index.mjs'; function fill( i ) { var rand = discreteUniform( -10*(i+1), 10*(i+1) ); From 480db6e98e0e000a6b0a37a67265fa71dcfd8872 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 08:28:22 +0000 Subject: [PATCH 68/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index d95cde3..4b227fe 100644 --- a/lib/main.js +++ b/lib/main.js @@ -25,7 +25,7 @@ var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); var isFunction = require( '@stdlib/assert-is-function' ); var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ndarrayFcn = require( './ndarray.js' ); var arrayFcn = require( './array.js' ); @@ -90,10 +90,10 @@ var arrayFcn = require( './array.js' ); */ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( !isFunction( mapper ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) ); + throw new TypeError( format( '1VL3N', mapper ) ); } if ( !isFunction( reducer ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) ); + throw new TypeError( format( '1VL32', reducer ) ); } if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len @@ -101,7 +101,7 @@ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( isArrayLikeObject( arr ) ) { return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len } - throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) ); + throw new TypeError( format( '1VLBH', arr ) ); } diff --git a/package.json b/package.json index ebb3dc1..52245ed 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-ndarray-like": "^0.2.1", "@stdlib/ndarray-base-ndarraylike2object": "^0.2.1", "@stdlib/ndarray-base-vind2bind": "^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 0d5b1d573de9ce5bd98f46c0a3a31b75dcc4253c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 14:15:15 +0000 Subject: [PATCH 69/91] Remove files --- index.d.ts | 257 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5104 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 861830b..0000000 --- a/index.d.ts +++ /dev/null @@ -1,257 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; -import { typedndarray } from '@stdlib/types/ndarray'; - -/** -* Callback invoked for each array element. -* -* @returns result -*/ -type Nullary = () => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @returns result -*/ -type Unary = ( value: T ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @returns result -*/ -type Binary = ( value: T, index: number ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Ternary = ( value: T, index: number, arr: typedndarray ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayTernary = ( value: T, index: number, arr: Collection ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Mapper = Nullary | Unary | Binary | Ternary; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayMapper = Nullary | Unary | Binary | ArrayTernary; - -/** -* Function applied against an accumulator. -* -* @returns accumulator value -*/ -type NullaryReducer = ( this: W ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @returns accumulator value -*/ -type UnaryReducer = ( this: W, accumulator: V ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @returns accumulator value -*/ -type BinaryReducer = ( this: W, accumulator: V, value: U ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @returns accumulator value -*/ -type TernaryReducer = ( this: W, accumulator: V, value: U, index: number ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type QuaternaryReducer = ( this: W, accumulator: V, value: U, index: number, arr: typedndarray ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayQuaternaryReducer = ( this: W, accumulator: V, value: U, index: number, arr: Collection ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type Reducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | QuaternaryReducer; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayReducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | ArrayQuaternaryReducer; - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 2 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -declare function mapReduceRight( arr: typedndarray, initial: V, mapper: Mapper, reducer: Reducer, thisArg?: ThisParameterType> ): V; - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -*/ -declare function mapReduceRight( arr: Collection, initial: V, mapper: ArrayMapper, reducer: ArrayReducer, thisArg?: ThisParameterType> ): V; - - -// EXPORTS // - -export = mapReduceRight; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 61bdc76..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.0-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.2.1-esm/index.mjs";var o="throw";function a(a,m,l,j,f){if(!e(l))throw new TypeError(n("1VL3N",l));if(!e(j))throw new TypeError(n("1VL32",j));if(s(a))return function(r,s,e,t,i){var n,a,m,l,j,f,h,c,p,v,b;if(l=r.length,h=r.shape,n=r.data,c=r.strides,p=r.offset,a=r.order,j=r.accessors[0],f=r.ref,0===h.length)return t.call(i,s,e(j(n,p),0,f),0,f);for(m=s,b=l-1;b>=0;b--)v=d(h,c,p,a,b,o),m=t.call(i,m,e(j(n,v),b,f),b,f);return m}(t(a),m,l,j,f);if(r(a))return function(r,s,e,t,i){var n,d,o,a;for(n=r.data,d=r.accessors[0],o=s,a=n.length-1;a>=0;a--)o=t.call(i,o,e(d(n,a),a,n),a,n);return o}(i(a),m,l,j,f);throw new TypeError(n("1VLBH",a))}export{a as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index f8ef5f4..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/ndarray.js","../lib/main.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind';\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64';\n* import Complex64 from '@stdlib/complex-float32';\n* import realf from '@stdlib/complex-realf';\n* import imagf from '@stdlib/complex-imagf';\n* import cceil from '@stdlib/math-base-special-cceil';\n* import cadd from '@stdlib/math-base-ops-cadd';\n* import naryFunction from '@stdlib/utils-nary-function';\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isFunction from '@stdlib/assert-is-function';\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object';\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndarrayFcn from './ndarray.js';\nimport arrayFcn from './array.js';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function';\n* import add from '@stdlib/math-base-ops-add';\n* import abs from '@stdlib/math-base-special-abs';\n* import array from '@stdlib/ndarray-array';\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '1VL3N', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '1VL32', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '1VLBH', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["MODE","mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","accessors","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;srBA2BA,IAAIA,EAAO,QC+DX,SAASC,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,GAAKK,EAAeR,GACnB,ODGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,UAAW,GAGnBZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAAGtB,GACtCc,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,CACR,CCnDSkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OC1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,UAAW,GAGnBf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,CACR,CDwBSqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,QAASP,GACvC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 4f77b5c..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From f59a10eb714dff4865dd89038565ab669125ee11 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 14:15:36 +0000 Subject: [PATCH 70/91] 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 | 71 +- SECURITY.md | 5 - benchmark/benchmark.array.js | 98 - benchmark/benchmark.ndarray.js | 109 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 9 - dist/index.js.map | 7 - docs/repl.txt | 65 - docs/types/test.ts | 184 - examples/index.js | 52 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/array.js | 83 - lib/index.js | 65 - lib/main.js | 110 - lib/ndarray.js | 155 - package.json | 77 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 637 --- 46 files changed, 4881 insertions(+), 4950 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.array.js delete mode 100644 benchmark/benchmark.ndarray.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/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/array.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/ndarray.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.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 a50c03e..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-03-01T06:06:47.520Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3b4c7b4..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/utils/map-reduce-right) 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 f23359f..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/utils/map-reduce-right) 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 1308146..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: '21 21 * * 4' - - # 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 + + ```
@@ -281,7 +272,7 @@ console.log( 'sum: %d', out ); ## 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]. @@ -344,19 +335,19 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/utils-map-reduce-right/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64 +[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64/tree/esm -[@stdlib/array/complex128]: https://github.com/stdlib-js/array-complex128 +[@stdlib/array/complex128]: https://github.com/stdlib-js/array-complex128/tree/esm -[@stdlib/utils/map-right]: https://github.com/stdlib-js/utils-map-right +[@stdlib/utils/map-right]: https://github.com/stdlib-js/utils-map-right/tree/esm -[@stdlib/utils/map-reduce]: https://github.com/stdlib-js/utils-map-reduce +[@stdlib/utils/map-reduce]: https://github.com/stdlib-js/utils-map-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/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.array.js b/benchmark/benchmark.array.js deleted file mode 100644 index da29c82..0000000 --- a/benchmark/benchmark.array.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = filled( -3.0, len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::array:len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.ndarray.js b/benchmark/benchmark.ndarray.js deleted file mode 100644 index 7806caa..0000000 --- a/benchmark/benchmark.ndarray.js +++ /dev/null @@ -1,109 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var xbuf; - var opts; - var x; - - xbuf = filled( -3.0, len ); - - opts = { - 'dtype': 'generic' - }; - x = array( xbuf, opts ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::ndarray:len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0816c5f..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/utils/map-reduce-right" -%% click B href "https://github.com/stdlib-js/utils-map-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-map-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-map-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-map-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-map-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/map-reduce-right -[production-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-map-reduce-right/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-map-reduce-right/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-map-reduce-right/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 63ea99a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import mapReduceRight from '../docs/types/index'; -export = mapReduceRight; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 3180c8b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,9 +0,0 @@ -"use strict";var g=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var q=g(function(H,m){ -var E=require('@stdlib/ndarray-base-vind2bind/dist'),T="throw";function p(r,e,a,t,s){var i,v,n,u,f,c,l,y,d,b,o;if(u=r.length,l=r.shape,i=r.data,y=r.strides,d=r.offset,v=r.order,f=r.accessors[0],c=r.ref,l.length===0)return t.call(s,e,a(f(i,d),0,c),0,c);for(n=e,o=u-1;o>=0;o--)b=E(l,y,d,v,o,T),n=t.call(s,n,a(f(i,b),o,c),o,c);return n}m.exports=p -});var R=g(function(I,w){ -function x(r,e,a,t,s){var i,v,n,u;for(i=r.data,v=r.accessors[0],n=e,u=i.length-1;u>=0;u--)n=t.call(s,n,a(v(i,u),u,i),u,i);return n}w.exports=x -});var j=g(function(J,F){ -var V=require('@stdlib/assert-is-array-like-object/dist'),L=require('@stdlib/assert-is-ndarray-like/dist'),k=require('@stdlib/assert-is-function/dist'),O=require('@stdlib/ndarray-base-ndarraylike2object/dist'),D=require('@stdlib/array-base-arraylike2object/dist'),h=require('@stdlib/error-tools-fmtprodmsg/dist'),M=q(),z=R();function B(r,e,a,t,s){if(!k(a))throw new TypeError(h('1VL3N',a));if(!k(t))throw new TypeError(h('1VL32',t));if(L(r))return M(O(r),e,a,t,s);if(V(r))return z(D(r),e,a,t,s);throw new TypeError(h('1VLBH',r))}F.exports=B -});var C=j();module.exports=C; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 641859d..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/ndarray.js", "../lib/array.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* var Complex64Array = require( '@stdlib/array-complex64' );\n* var Complex64 = require( '@stdlib/complex-float32' );\n* var realf = require( '@stdlib/complex-realf' );\n* var imagf = require( '@stdlib/complex-imagf' );\n* var cceil = require( '@stdlib/math-base-special-cceil' );\n* var cadd = require( '@stdlib/math-base-ops-cadd' );\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar format = require( '@stdlib/string-format' );\nvar ndarrayFcn = require( './ndarray.js' );\nvar arrayFcn = require( './array.js' );\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/math-base-ops-add' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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* Perform a map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.\n*\n* @module @stdlib/utils-map-reduce-right\n*\n* @example\n* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' );\n*\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, sum );\n* // returns 30\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/math-base-ops-add' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\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,EAAY,QAAS,gCAAiC,EAKtDC,EAAO,QA0EX,SAASC,EAAgBC,EAAGC,EAASC,EAAQC,EAASC,EAAU,CAC/D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMR,EAAE,OAGRW,EAAMX,EAAE,MAGRK,EAAOL,EAAE,KAGTY,EAAKZ,EAAE,QAGPa,EAAKb,EAAE,OAGPM,EAAON,EAAE,MAGTS,EAAMT,EAAE,UAAW,CAAE,EAGrBU,EAAMV,EAAE,IAGHW,EAAI,SAAW,EACnB,OAAOR,EAAQ,KAAMC,EAASH,EAASC,EAAQO,EAAKJ,EAAMQ,CAAG,EAAG,EAAGH,CAAI,EAAG,EAAGA,CAAI,EAIlF,IADAH,EAAMN,EACAc,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKjB,EAAWc,EAAKC,EAAIC,EAAIP,EAAMS,EAAGjB,CAAK,EAC3CS,EAAMJ,EAAQ,KAAMC,EAASG,EAAKL,EAAQO,EAAKJ,EAAMS,CAAG,EAAGC,EAAGL,CAAI,EAAGK,EAAGL,CAAI,EAE7E,OAAOH,CACR,CAKAX,EAAO,QAAUG,IC1JjB,IAAAiB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA2DA,SAASC,EAAgBC,EAAGC,EAASC,EAAQC,EAASC,EAAU,CAC/D,IAAIC,EACAC,EACAC,EACAC,EAUJ,IAPAH,EAAOL,EAAE,KAGTM,EAAMN,EAAE,UAAW,CAAE,EAGrBO,EAAMN,EACAO,EAAIH,EAAK,OAAO,EAAGG,GAAK,EAAGA,IAChCD,EAAMJ,EAAQ,KAAMC,EAASG,EAAKL,EAAQI,EAAKD,EAAMG,CAAE,EAAGA,EAAGH,CAAK,EAAGG,EAAGH,CAAK,EAE9E,OAAOE,CACR,CAKAT,EAAO,QAAUC,IClFjB,IAAAU,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAoB,QAAS,qCAAsC,EACnEC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,4BAA6B,EACnDC,EAAqB,QAAS,yCAA0C,EACxEC,EAAmB,QAAS,qCAAsC,EAClEC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAW,IA6Df,SAASC,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,EAAU,CACjE,GAAK,CAACX,EAAYS,CAAO,EACxB,MAAM,IAAI,UAAWN,EAAQ,oEAAqEM,CAAO,CAAE,EAE5G,GAAK,CAACT,EAAYU,CAAQ,EACzB,MAAM,IAAI,UAAWP,EAAQ,qEAAsEO,CAAQ,CAAE,EAE9G,GAAKX,EAAeQ,CAAI,EACvB,OAAOH,EAAYH,EAAoBM,CAAI,EAAGC,EAASC,EAAQC,EAASC,CAAQ,EAEjF,GAAKb,EAAmBS,CAAI,EAC3B,OAAOF,EAAUH,EAAkBK,CAAI,EAAGC,EAASC,EAAQC,EAASC,CAAQ,EAE7E,MAAM,IAAI,UAAWR,EAAQ,4FAA6FI,CAAI,CAAE,CACjI,CAKAV,EAAO,QAAUS,IClDjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_ndarray", "__commonJSMin", "exports", "module", "vind2bind", "MODE", "mapReduceRight", "x", "initial", "mapper", "reducer", "thisArg", "xbuf", "ordx", "acc", "len", "get", "ref", "shx", "sx", "ox", "ix", "i", "require_array", "__commonJSMin", "exports", "module", "mapReduceRight", "x", "initial", "mapper", "reducer", "thisArg", "xbuf", "get", "acc", "i", "require_main", "__commonJSMin", "exports", "module", "isArrayLikeObject", "isndarrayLike", "isFunction", "ndarraylike2object", "arraylike2object", "format", "ndarrayFcn", "arrayFcn", "mapReduceRight", "arr", "initial", "mapper", "reducer", "thisArg", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b580e87..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, initial, mapper, reducer[, thisArg] ) - Performs a map-reduce operation for each element in an array while iterating - from right to left and returns the accumulated result. - - When invoked, the mapping function is provided three arguments: - - - value: array element. - - index: element index. - - arr: input array. - - When invoked, the reducing function is provided four arguments: - - - accumulator: accumulated value. - - value: result after applying the mapping function to the current array - element. - - index: element index. - - arr: input array. - - If provided an empty array, the function returns the initial value. - - When provided an ndarray, the function performs a single-pass map-reduce - operation over the entire input ndarray (i.e., higher-order ndarray - dimensions are flattened to a single-dimension). - - Parameters - ---------- - arr: ArrayLikeObject|ndarray - Input array. - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - mapper: Function - Mapping function. - - reducer: Function - Reducing function. - - thisArg: any (optional) - Execution context for the reducing function. - - Returns - ------- - out: any - Accumulated result. - - Examples - -------- - // array-like object: - > var f1 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/special/abs}}, 1 ); - > var f2 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/ops/add}}, 2 ); - > var arr = [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0 ]; - > var out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - // ndarray: - > arr = {{alias:@stdlib/ndarray/array}}( arr, { 'shape': [ 2, 3 ] } ); - > out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 3fcccbb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,184 +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. -*/ - -import array = require( '@stdlib/ndarray-array' ); -import mapReduceRight = require( './index' ); - -/** -* Mapping function. -* -* @param value - array element -* @returns result -*/ -function mapper( value: number ): number { - return value; -} - -/** -* Reducing function. -* -* @param acc - accumulated value -* @param v - array element -* @returns result -*/ -function reducer( acc: number, value: number ): number { - return acc + value; -} - - -// TESTS // - -// The function returns the accumulated value when provided a collection... -{ - mapReduceRight( [ 0, 1, 1, NaN, 2 ], 0, mapper, reducer ); // $ExpectType number - mapReduceRight( [ -1, 1, 2 ], 100, mapper, reducer ); // $ExpectType number - mapReduceRight( [ -1, 1, 2 ], 0, mapper, reducer, {} ); // $ExpectType number -} - -// The function returns the accumulated value when provided an ndarray... -{ - const arr = array( [ 1, 2, 3, 4, 5, 6 ] ); - - mapReduceRight( arr, 0, mapper, reducer ); // $ExpectType number - mapReduceRight( arr, 100, mapper, reducer ); // $ExpectType number - mapReduceRight( arr, 0, mapper, reducer, {} ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not a collection or ndarray... -{ - mapReduceRight( 2, 0, mapper, reducer ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer ); // $ExpectError - - mapReduceRight( 2, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr1, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr2, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const arr1 = [ 1, 2, 3 ]; - - mapReduceRight(); // $ExpectError - mapReduceRight( arr1 ); // $ExpectError - mapReduceRight( arr1, 0 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ); // $ExpectError - mapReduceRight( arr1, 0, mapper, reducer, {}, 3 ); // $ExpectError - - const arr2 = array( [ 1, 2, 3 ] ); - - mapReduceRight(); // $ExpectError - mapReduceRight( arr2 ); // $ExpectError - mapReduceRight( arr2, 0 ); // $ExpectError - mapReduceRight( arr2, 0, mapper ); // $ExpectError - mapReduceRight( arr2, 0, mapper, reducer, {}, 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 7474059..0000000 --- a/examples/index.js +++ /dev/null @@ -1,52 +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. -*/ - -'use strict'; - -var filledarrayBy = require( '@stdlib/array-filled-by' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ).factory; -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var mapReduceRight = require( './../lib' ); - -function fill( i ) { - var rand = discreteUniform( -10*(i+1), 10*(i+1) ); - return filledarrayBy( 10, 'generic', rand ); -} - -// Create a two-dimensional ndarray (i.e., a matrix): -var x = array( filledarrayBy( 10, 'generic', fill ), { - 'dtype': 'generic', - 'flatten': true -}); - -// Create an explicit unary function: -var f1 = naryFunction( abs, 1 ); - -// Create an explicit binary function: -var f2 = naryFunction( add, 2 ); - -// Compute the sum of absolute values: -var out = mapReduceRight( x, 0, f1, f2 ); - -console.log( 'x:' ); -console.log( x.data ); - -console.log( 'sum: %d', out ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index f3614c6..861830b 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; import { typedndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..387a077 --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.2.1-esm/index.mjs";var o="throw";function a(a,m,l,j,f){if(!e(l))throw new TypeError(n("1VL3N",l));if(!e(j))throw new TypeError(n("1VL32",j));if(s(a))return function(r,s,e,t,i){var n,a,m,l,j,f,h,c,p,v,b;if(l=r.length,h=r.shape,n=r.data,c=r.strides,p=r.offset,a=r.order,j=r.accessors[0],f=r.ref,0===h.length)return t.call(i,s,e(j(n,p),0,f),0,f);for(m=s,b=l-1;b>=0;b--)v=d(h,c,p,a,b,o),m=t.call(i,m,e(j(n,v),b,f),b,f);return m}(t(a),m,l,j,f);if(r(a))return function(r,s,e,t,i){var n,d,o,a;for(n=r.data,d=r.accessors[0],o=s,a=n.length-1;a>=0;a--)o=t.call(i,o,e(d(n,a),a,n),a,n);return o}(i(a),m,l,j,f);throw new TypeError(n("1VLBH",a))}export{a as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..f8ef5f4 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/ndarray.js","../lib/main.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind';\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64';\n* import Complex64 from '@stdlib/complex-float32';\n* import realf from '@stdlib/complex-realf';\n* import imagf from '@stdlib/complex-imagf';\n* import cceil from '@stdlib/math-base-special-cceil';\n* import cadd from '@stdlib/math-base-ops-cadd';\n* import naryFunction from '@stdlib/utils-nary-function';\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isFunction from '@stdlib/assert-is-function';\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object';\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndarrayFcn from './ndarray.js';\nimport arrayFcn from './array.js';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function';\n* import add from '@stdlib/math-base-ops-add';\n* import abs from '@stdlib/math-base-special-abs';\n* import array from '@stdlib/ndarray-array';\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '1VL3N', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '1VL32', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '1VLBH', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["MODE","mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","accessors","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;srBA2BA,IAAIA,EAAO,QC+DX,SAASC,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,GAAKK,EAAeR,GACnB,ODGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,UAAW,GAGnBZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAAGtB,GACtCc,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,CACR,CCnDSkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OC1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,UAAW,GAGnBf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,CACR,CDwBSqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,QAASP,GACvC"} \ No newline at end of file diff --git a/lib/array.js b/lib/array.js deleted file mode 100644 index 69c0a8c..0000000 --- a/lib/array.js +++ /dev/null @@ -1,83 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input array data -* @param {ArrayLikeObject} x.data - input array data -* @param {Array} x.accessors - input array accessors -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf[ idx ]; -* } -* -* // Create the input array object: -* var x = { -* 'data': [ 1, 2, 3, 4 ], -* 'accessors': [ getter ] -* }; -* -* // Compute the sum of squared values: -* var out = mapReduceRight( x, 0, square, sum ); -* // returns 30 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var get; - var acc; - var i; - - // Cache reference to the input data: - xbuf = x.data; - - // Cache the element accessor: - get = x.accessors[ 0 ]; - - // Iterate over each element... - acc = initial; - for ( i = xbuf.length-1; i >= 0; i-- ) { - acc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 522693e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +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. -*/ - -'use strict'; - -/** -* Perform a map-reduce operation against each element in an array while iterating from right to left and return the accumulated result. -* -* @module @stdlib/utils-map-reduce-right -* -* @example -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ - -// 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 4b227fe..0000000 --- a/lib/main.js +++ /dev/null @@ -1,110 +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. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ndarrayFcn = require( './ndarray.js' ); -var arrayFcn = require( './array.js' ); - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided the following arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided the following arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result of applying the mapping function against the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* @param {(ArrayLikeObject|ndarray)} arr - input array -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} [thisArg] - reduction function execution context -* @throws {TypeError} first argument must be an array-like object or an ndarray -* @throws {TypeError} third argument must be a function -* @throws {TypeError} fourth argument must be a function -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { - if ( !isFunction( mapper ) ) { - throw new TypeError( format( '1VL3N', mapper ) ); - } - if ( !isFunction( reducer ) ) { - throw new TypeError( format( '1VL32', reducer ) ); - } - if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like - return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - if ( isArrayLikeObject( arr ) ) { - return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - throw new TypeError( format( '1VLBH', arr ) ); -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/ndarray.js b/lib/ndarray.js deleted file mode 100644 index 06e19a5..0000000 --- a/lib/ndarray.js +++ /dev/null @@ -1,155 +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. -*/ - -'use strict'; - -// MODULES // - -var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); - - -// VARIABLES // - -var MODE = 'throw'; - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input ndarray meta data -* @param {string} x.ref - reference to original input ndarray-like object -* @param {string} x.dtype - data type -* @param {Collection} x.data - data buffer -* @param {NonNegativeInteger} x.length - number of elements -* @param {NonNegativeIntegerArray} x.shape - dimensions -* @param {IntegerArray} x.strides - stride lengths -* @param {NonNegativeInteger} x.offset - index offset -* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) -* @param {Array} x.accessors - accessors for accessing data buffer elements -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var Complex64 = require( '@stdlib/complex-float32' ); -* var realf = require( '@stdlib/complex-realf' ); -* var imagf = require( '@stdlib/complex-imagf' ); -* var cceil = require( '@stdlib/math-base-special-cceil' ); -* var cadd = require( '@stdlib/math-base-ops-cadd' ); -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* -* // Create a data buffer: -* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] ); -* -* // Define the shape of the input array: -* var shape = [ 2, 2 ]; -* -* // Define the array strides: -* var sx = [ 2, 1 ]; -* -* // Define the index offset: -* var ox = 0; -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf.get( idx ); -* } -* -* // Create the input ndarray-like object: -* var x = { -* 'ref': null, -* 'dtype': 'complex64', -* 'data': xbuf, -* 'length': 4, -* 'shape': shape, -* 'strides': sx, -* 'offset': ox, -* 'order': 'row-major', -* 'accessors': [ getter ] -* }; -* x.ref = x; -* -* // Compute the sum: -* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) ); -* -* var re = realf( v ); -* // returns 20.0 -* -* var im = imagf( v ); -* // returns 24.0 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var ordx; - var acc; - var len; - var get; - var ref; - var shx; - var sx; - var ox; - var ix; - var i; - - // Cache the total number of elements over which to iterate: - len = x.length; - - // Cache the input array shape: - shx = x.shape; - - // Cache reference to the input ndarray data buffer: - xbuf = x.data; - - // Cache reference to the stride array: - sx = x.strides; - - // Cache the index of the first indexed element: - ox = x.offset; - - // Cache the array order: - ordx = x.order; - - // Cache the element accessor: - get = x.accessors[ 0 ]; - - // Cache the reference to the original input array: - ref = x.ref; - - // Check for a zero-dimensional array... - if ( shx.length === 0 ) { - return reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len - } - // Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)... - acc = initial; - for ( i = len-1; i >= 0; i-- ) { - ix = vind2bind( shx, sx, ox, ordx, i, MODE ); - acc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/package.json b/package.json index 52245ed..3df9694 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Perform a single-pass map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.", "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/array-base-arraylike2object": "^0.2.1", - "@stdlib/assert-is-array-like-object": "^0.2.1", - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/ndarray-base-ndarraylike2object": "^0.2.1", - "@stdlib/ndarray-base-vind2bind": "^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-base-filled": "^0.2.1", - "@stdlib/array-complex64": "^0.2.1", - "@stdlib/array-filled-by": "^0.2.1", - "@stdlib/array-float64": "^0.2.1", - "@stdlib/complex-float32": "^0.2.1", - "@stdlib/complex-imagf": "^0.2.1", - "@stdlib/complex-realf": "^0.2.1", - "@stdlib/math-base-assert-is-nan": "^0.2.1", - "@stdlib/math-base-ops-add": "^0.2.1", - "@stdlib/math-base-ops-cadd": "^0.2.1", - "@stdlib/math-base-special-abs": "^0.2.1", - "@stdlib/math-base-special-cceil": "^0.2.1", - "@stdlib/math-base-special-pow": "^0.2.1", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-ctor": "^0.2.1", - "@stdlib/random-base-discrete-uniform": "^0.2.1", - "@stdlib/utils-nary-function": "^0.2.1", - "@stdlib/utils-noop": "^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", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..397a7dd --- /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/test.js b/test/test.js deleted file mode 100644 index 2c78efa..0000000 --- a/test/test.js +++ /dev/null @@ -1,637 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var cadd = require( '@stdlib/math-base-ops-cadd' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var cceil = require( '@stdlib/math-base-special-cceil' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var mapReduceRight = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapReduceRight, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a first argument which is either an array-like object or an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( value, 0, noop, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value, {} ); - }; - } -}); - -tape( 'the function performs a map-reduce operation for each element in an array (array-like object)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = [ -1, -2, -3 ]; - expected = 7; - actual = mapReduceRight( arr, 1, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (typed array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - expected = 7.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (complex number array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( cceil, 1 ); - f2 = naryFunction( cadd, 2 ); - - arr = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5 ] ); - expected = new Complex64( 12.0, 15.0 ); - actual = mapReduceRight( arr, new Complex64( 0.0, 0.0 ), f1, f2 ); - - t.strictEqual( realf( actual ), realf( expected ), 'returns expected value' ); - t.strictEqual( imagf( actual ), imagf( expected ), 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = array( [ -1.0, -2.0, -3.0, -4.0 ], { - 'dtype': 'generic' - }); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray; 0-dimensional)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = ndarray( 'generic', [ -10.0 ], [], [ 0 ], 0, 'row-major' ); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (array-like object)', function test( t ) { - var out = mapReduceRight( [], 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (ndarray)', function test( t ) { - var arr; - var out; - - arr = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 0, 2 ], [ 0, 2, 1 ], 0, 'row-major' ); - out = mapReduceRight( arr, 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function supports providing a `this` context (array-like object)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = [ -1.0, -2.0, -3.0 ]; - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function supports providing a `this` context (ndarray)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = array( [ -1.0, -2.0, -3.0 ], { - 'dtype': 'generic' - }); - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = array( [ 1, , , 4 ], { // eslint-disable-line no-sparse-arrays - 'dtype': 'generic' - }); - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); From 219b9baefe114f300f6d50240213e68882bc7b16 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 07:44:51 +0000 Subject: [PATCH 71/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index d95cde3..4b227fe 100644 --- a/lib/main.js +++ b/lib/main.js @@ -25,7 +25,7 @@ var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); var isFunction = require( '@stdlib/assert-is-function' ); var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ndarrayFcn = require( './ndarray.js' ); var arrayFcn = require( './array.js' ); @@ -90,10 +90,10 @@ var arrayFcn = require( './array.js' ); */ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( !isFunction( mapper ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) ); + throw new TypeError( format( '1VL3N', mapper ) ); } if ( !isFunction( reducer ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) ); + throw new TypeError( format( '1VL32', reducer ) ); } if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len @@ -101,7 +101,7 @@ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( isArrayLikeObject( arr ) ) { return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len } - throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) ); + throw new TypeError( format( '1VLBH', arr ) ); } diff --git a/package.json b/package.json index ebb3dc1..52245ed 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-ndarray-like": "^0.2.1", "@stdlib/ndarray-base-ndarraylike2object": "^0.2.1", "@stdlib/ndarray-base-vind2bind": "^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 02444b5041b9e7bf9928112add43717c9f966866 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 13:16:51 +0000 Subject: [PATCH 72/91] Remove files --- index.d.ts | 257 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5104 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 861830b..0000000 --- a/index.d.ts +++ /dev/null @@ -1,257 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; -import { typedndarray } from '@stdlib/types/ndarray'; - -/** -* Callback invoked for each array element. -* -* @returns result -*/ -type Nullary = () => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @returns result -*/ -type Unary = ( value: T ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @returns result -*/ -type Binary = ( value: T, index: number ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Ternary = ( value: T, index: number, arr: typedndarray ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayTernary = ( value: T, index: number, arr: Collection ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Mapper = Nullary | Unary | Binary | Ternary; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayMapper = Nullary | Unary | Binary | ArrayTernary; - -/** -* Function applied against an accumulator. -* -* @returns accumulator value -*/ -type NullaryReducer = ( this: W ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @returns accumulator value -*/ -type UnaryReducer = ( this: W, accumulator: V ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @returns accumulator value -*/ -type BinaryReducer = ( this: W, accumulator: V, value: U ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @returns accumulator value -*/ -type TernaryReducer = ( this: W, accumulator: V, value: U, index: number ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type QuaternaryReducer = ( this: W, accumulator: V, value: U, index: number, arr: typedndarray ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayQuaternaryReducer = ( this: W, accumulator: V, value: U, index: number, arr: Collection ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type Reducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | QuaternaryReducer; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayReducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | ArrayQuaternaryReducer; - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 2 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -declare function mapReduceRight( arr: typedndarray, initial: V, mapper: Mapper, reducer: Reducer, thisArg?: ThisParameterType> ): V; - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -*/ -declare function mapReduceRight( arr: Collection, initial: V, mapper: ArrayMapper, reducer: ArrayReducer, thisArg?: ThisParameterType> ): V; - - -// EXPORTS // - -export = mapReduceRight; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 387a077..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.2.1-esm/index.mjs";var o="throw";function a(a,m,l,j,f){if(!e(l))throw new TypeError(n("1VL3N",l));if(!e(j))throw new TypeError(n("1VL32",j));if(s(a))return function(r,s,e,t,i){var n,a,m,l,j,f,h,c,p,v,b;if(l=r.length,h=r.shape,n=r.data,c=r.strides,p=r.offset,a=r.order,j=r.accessors[0],f=r.ref,0===h.length)return t.call(i,s,e(j(n,p),0,f),0,f);for(m=s,b=l-1;b>=0;b--)v=d(h,c,p,a,b,o),m=t.call(i,m,e(j(n,v),b,f),b,f);return m}(t(a),m,l,j,f);if(r(a))return function(r,s,e,t,i){var n,d,o,a;for(n=r.data,d=r.accessors[0],o=s,a=n.length-1;a>=0;a--)o=t.call(i,o,e(d(n,a),a,n),a,n);return o}(i(a),m,l,j,f);throw new TypeError(n("1VLBH",a))}export{a as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index f8ef5f4..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/ndarray.js","../lib/main.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind';\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64';\n* import Complex64 from '@stdlib/complex-float32';\n* import realf from '@stdlib/complex-realf';\n* import imagf from '@stdlib/complex-imagf';\n* import cceil from '@stdlib/math-base-special-cceil';\n* import cadd from '@stdlib/math-base-ops-cadd';\n* import naryFunction from '@stdlib/utils-nary-function';\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isFunction from '@stdlib/assert-is-function';\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object';\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndarrayFcn from './ndarray.js';\nimport arrayFcn from './array.js';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function';\n* import add from '@stdlib/math-base-ops-add';\n* import abs from '@stdlib/math-base-special-abs';\n* import array from '@stdlib/ndarray-array';\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '1VL3N', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '1VL32', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '1VLBH', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["MODE","mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","accessors","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;srBA2BA,IAAIA,EAAO,QC+DX,SAASC,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,GAAKK,EAAeR,GACnB,ODGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,UAAW,GAGnBZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAAGtB,GACtCc,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,CACR,CCnDSkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OC1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,UAAW,GAGnBf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,CACR,CDwBSqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,QAASP,GACvC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 397a7dd..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 1cf4230522ed2b7f17e043d2a4ed5e95ece3dde7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 13:17:06 +0000 Subject: [PATCH 73/91] 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 | 71 +- SECURITY.md | 5 - benchmark/benchmark.array.js | 98 - benchmark/benchmark.ndarray.js | 109 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 9 - dist/index.js.map | 7 - docs/repl.txt | 65 - docs/types/test.ts | 184 - examples/index.js | 52 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/array.js | 83 - lib/index.js | 65 - lib/main.js | 110 - lib/ndarray.js | 155 - package.json | 77 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 637 --- 46 files changed, 4881 insertions(+), 4953 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.array.js delete mode 100644 benchmark/benchmark.ndarray.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/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/array.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/ndarray.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.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 ee01233..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-04-01T05:22:29.646Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3b4c7b4..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/utils/map-reduce-right) 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 f23359f..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/utils/map-reduce-right) 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 1308146..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: '21 21 * * 4' - - # 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 + + ```
@@ -281,7 +272,7 @@ console.log( 'sum: %d', out ); ## 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]. @@ -344,19 +335,19 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/utils-map-reduce-right/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64 +[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64/tree/esm -[@stdlib/array/complex128]: https://github.com/stdlib-js/array-complex128 +[@stdlib/array/complex128]: https://github.com/stdlib-js/array-complex128/tree/esm -[@stdlib/utils/map-right]: https://github.com/stdlib-js/utils-map-right +[@stdlib/utils/map-right]: https://github.com/stdlib-js/utils-map-right/tree/esm -[@stdlib/utils/map-reduce]: https://github.com/stdlib-js/utils-map-reduce +[@stdlib/utils/map-reduce]: https://github.com/stdlib-js/utils-map-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/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.array.js b/benchmark/benchmark.array.js deleted file mode 100644 index da29c82..0000000 --- a/benchmark/benchmark.array.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = filled( -3.0, len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::array:len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.ndarray.js b/benchmark/benchmark.ndarray.js deleted file mode 100644 index 7806caa..0000000 --- a/benchmark/benchmark.ndarray.js +++ /dev/null @@ -1,109 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var xbuf; - var opts; - var x; - - xbuf = filled( -3.0, len ); - - opts = { - 'dtype': 'generic' - }; - x = array( xbuf, opts ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::ndarray:len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0816c5f..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/utils/map-reduce-right" -%% click B href "https://github.com/stdlib-js/utils-map-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-map-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-map-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-map-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-map-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/map-reduce-right -[production-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-map-reduce-right/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-map-reduce-right/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-map-reduce-right/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 63ea99a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import mapReduceRight from '../docs/types/index'; -export = mapReduceRight; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 3180c8b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,9 +0,0 @@ -"use strict";var g=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var q=g(function(H,m){ -var E=require('@stdlib/ndarray-base-vind2bind/dist'),T="throw";function p(r,e,a,t,s){var i,v,n,u,f,c,l,y,d,b,o;if(u=r.length,l=r.shape,i=r.data,y=r.strides,d=r.offset,v=r.order,f=r.accessors[0],c=r.ref,l.length===0)return t.call(s,e,a(f(i,d),0,c),0,c);for(n=e,o=u-1;o>=0;o--)b=E(l,y,d,v,o,T),n=t.call(s,n,a(f(i,b),o,c),o,c);return n}m.exports=p -});var R=g(function(I,w){ -function x(r,e,a,t,s){var i,v,n,u;for(i=r.data,v=r.accessors[0],n=e,u=i.length-1;u>=0;u--)n=t.call(s,n,a(v(i,u),u,i),u,i);return n}w.exports=x -});var j=g(function(J,F){ -var V=require('@stdlib/assert-is-array-like-object/dist'),L=require('@stdlib/assert-is-ndarray-like/dist'),k=require('@stdlib/assert-is-function/dist'),O=require('@stdlib/ndarray-base-ndarraylike2object/dist'),D=require('@stdlib/array-base-arraylike2object/dist'),h=require('@stdlib/error-tools-fmtprodmsg/dist'),M=q(),z=R();function B(r,e,a,t,s){if(!k(a))throw new TypeError(h('1VL3N',a));if(!k(t))throw new TypeError(h('1VL32',t));if(L(r))return M(O(r),e,a,t,s);if(V(r))return z(D(r),e,a,t,s);throw new TypeError(h('1VLBH',r))}F.exports=B -});var C=j();module.exports=C; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 641859d..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/ndarray.js", "../lib/array.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* var Complex64Array = require( '@stdlib/array-complex64' );\n* var Complex64 = require( '@stdlib/complex-float32' );\n* var realf = require( '@stdlib/complex-realf' );\n* var imagf = require( '@stdlib/complex-imagf' );\n* var cceil = require( '@stdlib/math-base-special-cceil' );\n* var cadd = require( '@stdlib/math-base-ops-cadd' );\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar format = require( '@stdlib/string-format' );\nvar ndarrayFcn = require( './ndarray.js' );\nvar arrayFcn = require( './array.js' );\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/math-base-ops-add' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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* Perform a map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.\n*\n* @module @stdlib/utils-map-reduce-right\n*\n* @example\n* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' );\n*\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, sum );\n* // returns 30\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/math-base-ops-add' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\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,EAAY,QAAS,gCAAiC,EAKtDC,EAAO,QA0EX,SAASC,EAAgBC,EAAGC,EAASC,EAAQC,EAASC,EAAU,CAC/D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMR,EAAE,OAGRW,EAAMX,EAAE,MAGRK,EAAOL,EAAE,KAGTY,EAAKZ,EAAE,QAGPa,EAAKb,EAAE,OAGPM,EAAON,EAAE,MAGTS,EAAMT,EAAE,UAAW,CAAE,EAGrBU,EAAMV,EAAE,IAGHW,EAAI,SAAW,EACnB,OAAOR,EAAQ,KAAMC,EAASH,EAASC,EAAQO,EAAKJ,EAAMQ,CAAG,EAAG,EAAGH,CAAI,EAAG,EAAGA,CAAI,EAIlF,IADAH,EAAMN,EACAc,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKjB,EAAWc,EAAKC,EAAIC,EAAIP,EAAMS,EAAGjB,CAAK,EAC3CS,EAAMJ,EAAQ,KAAMC,EAASG,EAAKL,EAAQO,EAAKJ,EAAMS,CAAG,EAAGC,EAAGL,CAAI,EAAGK,EAAGL,CAAI,EAE7E,OAAOH,CACR,CAKAX,EAAO,QAAUG,IC1JjB,IAAAiB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA2DA,SAASC,EAAgBC,EAAGC,EAASC,EAAQC,EAASC,EAAU,CAC/D,IAAIC,EACAC,EACAC,EACAC,EAUJ,IAPAH,EAAOL,EAAE,KAGTM,EAAMN,EAAE,UAAW,CAAE,EAGrBO,EAAMN,EACAO,EAAIH,EAAK,OAAO,EAAGG,GAAK,EAAGA,IAChCD,EAAMJ,EAAQ,KAAMC,EAASG,EAAKL,EAAQI,EAAKD,EAAMG,CAAE,EAAGA,EAAGH,CAAK,EAAGG,EAAGH,CAAK,EAE9E,OAAOE,CACR,CAKAT,EAAO,QAAUC,IClFjB,IAAAU,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAoB,QAAS,qCAAsC,EACnEC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,4BAA6B,EACnDC,EAAqB,QAAS,yCAA0C,EACxEC,EAAmB,QAAS,qCAAsC,EAClEC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAW,IA6Df,SAASC,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,EAAU,CACjE,GAAK,CAACX,EAAYS,CAAO,EACxB,MAAM,IAAI,UAAWN,EAAQ,oEAAqEM,CAAO,CAAE,EAE5G,GAAK,CAACT,EAAYU,CAAQ,EACzB,MAAM,IAAI,UAAWP,EAAQ,qEAAsEO,CAAQ,CAAE,EAE9G,GAAKX,EAAeQ,CAAI,EACvB,OAAOH,EAAYH,EAAoBM,CAAI,EAAGC,EAASC,EAAQC,EAASC,CAAQ,EAEjF,GAAKb,EAAmBS,CAAI,EAC3B,OAAOF,EAAUH,EAAkBK,CAAI,EAAGC,EAASC,EAAQC,EAASC,CAAQ,EAE7E,MAAM,IAAI,UAAWR,EAAQ,4FAA6FI,CAAI,CAAE,CACjI,CAKAV,EAAO,QAAUS,IClDjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_ndarray", "__commonJSMin", "exports", "module", "vind2bind", "MODE", "mapReduceRight", "x", "initial", "mapper", "reducer", "thisArg", "xbuf", "ordx", "acc", "len", "get", "ref", "shx", "sx", "ox", "ix", "i", "require_array", "__commonJSMin", "exports", "module", "mapReduceRight", "x", "initial", "mapper", "reducer", "thisArg", "xbuf", "get", "acc", "i", "require_main", "__commonJSMin", "exports", "module", "isArrayLikeObject", "isndarrayLike", "isFunction", "ndarraylike2object", "arraylike2object", "format", "ndarrayFcn", "arrayFcn", "mapReduceRight", "arr", "initial", "mapper", "reducer", "thisArg", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b580e87..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, initial, mapper, reducer[, thisArg] ) - Performs a map-reduce operation for each element in an array while iterating - from right to left and returns the accumulated result. - - When invoked, the mapping function is provided three arguments: - - - value: array element. - - index: element index. - - arr: input array. - - When invoked, the reducing function is provided four arguments: - - - accumulator: accumulated value. - - value: result after applying the mapping function to the current array - element. - - index: element index. - - arr: input array. - - If provided an empty array, the function returns the initial value. - - When provided an ndarray, the function performs a single-pass map-reduce - operation over the entire input ndarray (i.e., higher-order ndarray - dimensions are flattened to a single-dimension). - - Parameters - ---------- - arr: ArrayLikeObject|ndarray - Input array. - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - mapper: Function - Mapping function. - - reducer: Function - Reducing function. - - thisArg: any (optional) - Execution context for the reducing function. - - Returns - ------- - out: any - Accumulated result. - - Examples - -------- - // array-like object: - > var f1 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/special/abs}}, 1 ); - > var f2 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/ops/add}}, 2 ); - > var arr = [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0 ]; - > var out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - // ndarray: - > arr = {{alias:@stdlib/ndarray/array}}( arr, { 'shape': [ 2, 3 ] } ); - > out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 3fcccbb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,184 +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. -*/ - -import array = require( '@stdlib/ndarray-array' ); -import mapReduceRight = require( './index' ); - -/** -* Mapping function. -* -* @param value - array element -* @returns result -*/ -function mapper( value: number ): number { - return value; -} - -/** -* Reducing function. -* -* @param acc - accumulated value -* @param v - array element -* @returns result -*/ -function reducer( acc: number, value: number ): number { - return acc + value; -} - - -// TESTS // - -// The function returns the accumulated value when provided a collection... -{ - mapReduceRight( [ 0, 1, 1, NaN, 2 ], 0, mapper, reducer ); // $ExpectType number - mapReduceRight( [ -1, 1, 2 ], 100, mapper, reducer ); // $ExpectType number - mapReduceRight( [ -1, 1, 2 ], 0, mapper, reducer, {} ); // $ExpectType number -} - -// The function returns the accumulated value when provided an ndarray... -{ - const arr = array( [ 1, 2, 3, 4, 5, 6 ] ); - - mapReduceRight( arr, 0, mapper, reducer ); // $ExpectType number - mapReduceRight( arr, 100, mapper, reducer ); // $ExpectType number - mapReduceRight( arr, 0, mapper, reducer, {} ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not a collection or ndarray... -{ - mapReduceRight( 2, 0, mapper, reducer ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer ); // $ExpectError - - mapReduceRight( 2, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr1, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr2, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const arr1 = [ 1, 2, 3 ]; - - mapReduceRight(); // $ExpectError - mapReduceRight( arr1 ); // $ExpectError - mapReduceRight( arr1, 0 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ); // $ExpectError - mapReduceRight( arr1, 0, mapper, reducer, {}, 3 ); // $ExpectError - - const arr2 = array( [ 1, 2, 3 ] ); - - mapReduceRight(); // $ExpectError - mapReduceRight( arr2 ); // $ExpectError - mapReduceRight( arr2, 0 ); // $ExpectError - mapReduceRight( arr2, 0, mapper ); // $ExpectError - mapReduceRight( arr2, 0, mapper, reducer, {}, 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 7474059..0000000 --- a/examples/index.js +++ /dev/null @@ -1,52 +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. -*/ - -'use strict'; - -var filledarrayBy = require( '@stdlib/array-filled-by' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ).factory; -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var mapReduceRight = require( './../lib' ); - -function fill( i ) { - var rand = discreteUniform( -10*(i+1), 10*(i+1) ); - return filledarrayBy( 10, 'generic', rand ); -} - -// Create a two-dimensional ndarray (i.e., a matrix): -var x = array( filledarrayBy( 10, 'generic', fill ), { - 'dtype': 'generic', - 'flatten': true -}); - -// Create an explicit unary function: -var f1 = naryFunction( abs, 1 ); - -// Create an explicit binary function: -var f2 = naryFunction( add, 2 ); - -// Compute the sum of absolute values: -var out = mapReduceRight( x, 0, f1, f2 ); - -console.log( 'x:' ); -console.log( x.data ); - -console.log( 'sum: %d', out ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index f3614c6..861830b 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; import { typedndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..387a077 --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.2.1-esm/index.mjs";var o="throw";function a(a,m,l,j,f){if(!e(l))throw new TypeError(n("1VL3N",l));if(!e(j))throw new TypeError(n("1VL32",j));if(s(a))return function(r,s,e,t,i){var n,a,m,l,j,f,h,c,p,v,b;if(l=r.length,h=r.shape,n=r.data,c=r.strides,p=r.offset,a=r.order,j=r.accessors[0],f=r.ref,0===h.length)return t.call(i,s,e(j(n,p),0,f),0,f);for(m=s,b=l-1;b>=0;b--)v=d(h,c,p,a,b,o),m=t.call(i,m,e(j(n,v),b,f),b,f);return m}(t(a),m,l,j,f);if(r(a))return function(r,s,e,t,i){var n,d,o,a;for(n=r.data,d=r.accessors[0],o=s,a=n.length-1;a>=0;a--)o=t.call(i,o,e(d(n,a),a,n),a,n);return o}(i(a),m,l,j,f);throw new TypeError(n("1VLBH",a))}export{a as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..f8ef5f4 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/ndarray.js","../lib/main.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind';\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64';\n* import Complex64 from '@stdlib/complex-float32';\n* import realf from '@stdlib/complex-realf';\n* import imagf from '@stdlib/complex-imagf';\n* import cceil from '@stdlib/math-base-special-cceil';\n* import cadd from '@stdlib/math-base-ops-cadd';\n* import naryFunction from '@stdlib/utils-nary-function';\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isFunction from '@stdlib/assert-is-function';\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object';\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndarrayFcn from './ndarray.js';\nimport arrayFcn from './array.js';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function';\n* import add from '@stdlib/math-base-ops-add';\n* import abs from '@stdlib/math-base-special-abs';\n* import array from '@stdlib/ndarray-array';\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '1VL3N', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '1VL32', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '1VLBH', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["MODE","mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","accessors","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;srBA2BA,IAAIA,EAAO,QC+DX,SAASC,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,GAAKK,EAAeR,GACnB,ODGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,UAAW,GAGnBZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAAGtB,GACtCc,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,CACR,CCnDSkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OC1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,UAAW,GAGnBf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,CACR,CDwBSqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,QAASP,GACvC"} \ No newline at end of file diff --git a/lib/array.js b/lib/array.js deleted file mode 100644 index 69c0a8c..0000000 --- a/lib/array.js +++ /dev/null @@ -1,83 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input array data -* @param {ArrayLikeObject} x.data - input array data -* @param {Array} x.accessors - input array accessors -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf[ idx ]; -* } -* -* // Create the input array object: -* var x = { -* 'data': [ 1, 2, 3, 4 ], -* 'accessors': [ getter ] -* }; -* -* // Compute the sum of squared values: -* var out = mapReduceRight( x, 0, square, sum ); -* // returns 30 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var get; - var acc; - var i; - - // Cache reference to the input data: - xbuf = x.data; - - // Cache the element accessor: - get = x.accessors[ 0 ]; - - // Iterate over each element... - acc = initial; - for ( i = xbuf.length-1; i >= 0; i-- ) { - acc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 522693e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +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. -*/ - -'use strict'; - -/** -* Perform a map-reduce operation against each element in an array while iterating from right to left and return the accumulated result. -* -* @module @stdlib/utils-map-reduce-right -* -* @example -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ - -// 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 4b227fe..0000000 --- a/lib/main.js +++ /dev/null @@ -1,110 +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. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ndarrayFcn = require( './ndarray.js' ); -var arrayFcn = require( './array.js' ); - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided the following arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided the following arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result of applying the mapping function against the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* @param {(ArrayLikeObject|ndarray)} arr - input array -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} [thisArg] - reduction function execution context -* @throws {TypeError} first argument must be an array-like object or an ndarray -* @throws {TypeError} third argument must be a function -* @throws {TypeError} fourth argument must be a function -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { - if ( !isFunction( mapper ) ) { - throw new TypeError( format( '1VL3N', mapper ) ); - } - if ( !isFunction( reducer ) ) { - throw new TypeError( format( '1VL32', reducer ) ); - } - if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like - return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - if ( isArrayLikeObject( arr ) ) { - return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - throw new TypeError( format( '1VLBH', arr ) ); -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/ndarray.js b/lib/ndarray.js deleted file mode 100644 index 06e19a5..0000000 --- a/lib/ndarray.js +++ /dev/null @@ -1,155 +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. -*/ - -'use strict'; - -// MODULES // - -var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); - - -// VARIABLES // - -var MODE = 'throw'; - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input ndarray meta data -* @param {string} x.ref - reference to original input ndarray-like object -* @param {string} x.dtype - data type -* @param {Collection} x.data - data buffer -* @param {NonNegativeInteger} x.length - number of elements -* @param {NonNegativeIntegerArray} x.shape - dimensions -* @param {IntegerArray} x.strides - stride lengths -* @param {NonNegativeInteger} x.offset - index offset -* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) -* @param {Array} x.accessors - accessors for accessing data buffer elements -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var Complex64 = require( '@stdlib/complex-float32' ); -* var realf = require( '@stdlib/complex-realf' ); -* var imagf = require( '@stdlib/complex-imagf' ); -* var cceil = require( '@stdlib/math-base-special-cceil' ); -* var cadd = require( '@stdlib/math-base-ops-cadd' ); -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* -* // Create a data buffer: -* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] ); -* -* // Define the shape of the input array: -* var shape = [ 2, 2 ]; -* -* // Define the array strides: -* var sx = [ 2, 1 ]; -* -* // Define the index offset: -* var ox = 0; -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf.get( idx ); -* } -* -* // Create the input ndarray-like object: -* var x = { -* 'ref': null, -* 'dtype': 'complex64', -* 'data': xbuf, -* 'length': 4, -* 'shape': shape, -* 'strides': sx, -* 'offset': ox, -* 'order': 'row-major', -* 'accessors': [ getter ] -* }; -* x.ref = x; -* -* // Compute the sum: -* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) ); -* -* var re = realf( v ); -* // returns 20.0 -* -* var im = imagf( v ); -* // returns 24.0 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var ordx; - var acc; - var len; - var get; - var ref; - var shx; - var sx; - var ox; - var ix; - var i; - - // Cache the total number of elements over which to iterate: - len = x.length; - - // Cache the input array shape: - shx = x.shape; - - // Cache reference to the input ndarray data buffer: - xbuf = x.data; - - // Cache reference to the stride array: - sx = x.strides; - - // Cache the index of the first indexed element: - ox = x.offset; - - // Cache the array order: - ordx = x.order; - - // Cache the element accessor: - get = x.accessors[ 0 ]; - - // Cache the reference to the original input array: - ref = x.ref; - - // Check for a zero-dimensional array... - if ( shx.length === 0 ) { - return reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len - } - // Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)... - acc = initial; - for ( i = len-1; i >= 0; i-- ) { - ix = vind2bind( shx, sx, ox, ordx, i, MODE ); - acc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/package.json b/package.json index 52245ed..3df9694 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Perform a single-pass map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.", "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/array-base-arraylike2object": "^0.2.1", - "@stdlib/assert-is-array-like-object": "^0.2.1", - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/ndarray-base-ndarraylike2object": "^0.2.1", - "@stdlib/ndarray-base-vind2bind": "^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-base-filled": "^0.2.1", - "@stdlib/array-complex64": "^0.2.1", - "@stdlib/array-filled-by": "^0.2.1", - "@stdlib/array-float64": "^0.2.1", - "@stdlib/complex-float32": "^0.2.1", - "@stdlib/complex-imagf": "^0.2.1", - "@stdlib/complex-realf": "^0.2.1", - "@stdlib/math-base-assert-is-nan": "^0.2.1", - "@stdlib/math-base-ops-add": "^0.2.1", - "@stdlib/math-base-ops-cadd": "^0.2.1", - "@stdlib/math-base-special-abs": "^0.2.1", - "@stdlib/math-base-special-cceil": "^0.2.1", - "@stdlib/math-base-special-pow": "^0.2.1", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-ctor": "^0.2.1", - "@stdlib/random-base-discrete-uniform": "^0.2.1", - "@stdlib/utils-nary-function": "^0.2.1", - "@stdlib/utils-noop": "^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", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..397a7dd --- /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/test.js b/test/test.js deleted file mode 100644 index 2c78efa..0000000 --- a/test/test.js +++ /dev/null @@ -1,637 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var cadd = require( '@stdlib/math-base-ops-cadd' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var cceil = require( '@stdlib/math-base-special-cceil' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var mapReduceRight = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapReduceRight, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a first argument which is either an array-like object or an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( value, 0, noop, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value, {} ); - }; - } -}); - -tape( 'the function performs a map-reduce operation for each element in an array (array-like object)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = [ -1, -2, -3 ]; - expected = 7; - actual = mapReduceRight( arr, 1, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (typed array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - expected = 7.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (complex number array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( cceil, 1 ); - f2 = naryFunction( cadd, 2 ); - - arr = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5 ] ); - expected = new Complex64( 12.0, 15.0 ); - actual = mapReduceRight( arr, new Complex64( 0.0, 0.0 ), f1, f2 ); - - t.strictEqual( realf( actual ), realf( expected ), 'returns expected value' ); - t.strictEqual( imagf( actual ), imagf( expected ), 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = array( [ -1.0, -2.0, -3.0, -4.0 ], { - 'dtype': 'generic' - }); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray; 0-dimensional)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = ndarray( 'generic', [ -10.0 ], [], [ 0 ], 0, 'row-major' ); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (array-like object)', function test( t ) { - var out = mapReduceRight( [], 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (ndarray)', function test( t ) { - var arr; - var out; - - arr = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 0, 2 ], [ 0, 2, 1 ], 0, 'row-major' ); - out = mapReduceRight( arr, 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function supports providing a `this` context (array-like object)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = [ -1.0, -2.0, -3.0 ]; - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function supports providing a `this` context (ndarray)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = array( [ -1.0, -2.0, -3.0 ], { - 'dtype': 'generic' - }); - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = array( [ 1, , , 4 ], { // eslint-disable-line no-sparse-arrays - 'dtype': 'generic' - }); - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); From 08ec01856e34d80c1ec8ee89b8178d0da782868d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 03:58:09 +0000 Subject: [PATCH 74/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index d95cde3..4b227fe 100644 --- a/lib/main.js +++ b/lib/main.js @@ -25,7 +25,7 @@ var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); var isFunction = require( '@stdlib/assert-is-function' ); var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ndarrayFcn = require( './ndarray.js' ); var arrayFcn = require( './array.js' ); @@ -90,10 +90,10 @@ var arrayFcn = require( './array.js' ); */ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( !isFunction( mapper ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) ); + throw new TypeError( format( '1VL3N', mapper ) ); } if ( !isFunction( reducer ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) ); + throw new TypeError( format( '1VL32', reducer ) ); } if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len @@ -101,7 +101,7 @@ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( isArrayLikeObject( arr ) ) { return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len } - throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) ); + throw new TypeError( format( '1VLBH', arr ) ); } diff --git a/package.json b/package.json index ebb3dc1..52245ed 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-ndarray-like": "^0.2.1", "@stdlib/ndarray-base-ndarraylike2object": "^0.2.1", "@stdlib/ndarray-base-vind2bind": "^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 7c0cce38e706a3bab923fbce264f4b6902893c04 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 09:28:16 +0000 Subject: [PATCH 75/91] Remove files --- index.d.ts | 257 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5104 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 861830b..0000000 --- a/index.d.ts +++ /dev/null @@ -1,257 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; -import { typedndarray } from '@stdlib/types/ndarray'; - -/** -* Callback invoked for each array element. -* -* @returns result -*/ -type Nullary = () => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @returns result -*/ -type Unary = ( value: T ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @returns result -*/ -type Binary = ( value: T, index: number ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Ternary = ( value: T, index: number, arr: typedndarray ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayTernary = ( value: T, index: number, arr: Collection ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Mapper = Nullary | Unary | Binary | Ternary; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayMapper = Nullary | Unary | Binary | ArrayTernary; - -/** -* Function applied against an accumulator. -* -* @returns accumulator value -*/ -type NullaryReducer = ( this: W ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @returns accumulator value -*/ -type UnaryReducer = ( this: W, accumulator: V ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @returns accumulator value -*/ -type BinaryReducer = ( this: W, accumulator: V, value: U ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @returns accumulator value -*/ -type TernaryReducer = ( this: W, accumulator: V, value: U, index: number ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type QuaternaryReducer = ( this: W, accumulator: V, value: U, index: number, arr: typedndarray ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayQuaternaryReducer = ( this: W, accumulator: V, value: U, index: number, arr: Collection ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type Reducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | QuaternaryReducer; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayReducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | ArrayQuaternaryReducer; - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 2 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -declare function mapReduceRight( arr: typedndarray, initial: V, mapper: Mapper, reducer: Reducer, thisArg?: ThisParameterType> ): V; - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -*/ -declare function mapReduceRight( arr: Collection, initial: V, mapper: ArrayMapper, reducer: ArrayReducer, thisArg?: ThisParameterType> ): V; - - -// EXPORTS // - -export = mapReduceRight; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 387a077..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.2.1-esm/index.mjs";var o="throw";function a(a,m,l,j,f){if(!e(l))throw new TypeError(n("1VL3N",l));if(!e(j))throw new TypeError(n("1VL32",j));if(s(a))return function(r,s,e,t,i){var n,a,m,l,j,f,h,c,p,v,b;if(l=r.length,h=r.shape,n=r.data,c=r.strides,p=r.offset,a=r.order,j=r.accessors[0],f=r.ref,0===h.length)return t.call(i,s,e(j(n,p),0,f),0,f);for(m=s,b=l-1;b>=0;b--)v=d(h,c,p,a,b,o),m=t.call(i,m,e(j(n,v),b,f),b,f);return m}(t(a),m,l,j,f);if(r(a))return function(r,s,e,t,i){var n,d,o,a;for(n=r.data,d=r.accessors[0],o=s,a=n.length-1;a>=0;a--)o=t.call(i,o,e(d(n,a),a,n),a,n);return o}(i(a),m,l,j,f);throw new TypeError(n("1VLBH",a))}export{a as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index f8ef5f4..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/ndarray.js","../lib/main.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind';\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64';\n* import Complex64 from '@stdlib/complex-float32';\n* import realf from '@stdlib/complex-realf';\n* import imagf from '@stdlib/complex-imagf';\n* import cceil from '@stdlib/math-base-special-cceil';\n* import cadd from '@stdlib/math-base-ops-cadd';\n* import naryFunction from '@stdlib/utils-nary-function';\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isFunction from '@stdlib/assert-is-function';\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object';\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndarrayFcn from './ndarray.js';\nimport arrayFcn from './array.js';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function';\n* import add from '@stdlib/math-base-ops-add';\n* import abs from '@stdlib/math-base-special-abs';\n* import array from '@stdlib/ndarray-array';\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '1VL3N', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '1VL32', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '1VLBH', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["MODE","mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","accessors","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;srBA2BA,IAAIA,EAAO,QC+DX,SAASC,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,GAAKK,EAAeR,GACnB,ODGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,UAAW,GAGnBZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAAGtB,GACtCc,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,CACR,CCnDSkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OC1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,UAAW,GAGnBf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,CACR,CDwBSqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,QAASP,GACvC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 397a7dd..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 1b9f4ce59284ccfe89cdad5503daa457d8d7896a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 09:28:33 +0000 Subject: [PATCH 76/91] 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 | 71 +- SECURITY.md | 5 - benchmark/benchmark.array.js | 98 - benchmark/benchmark.ndarray.js | 109 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 9 - dist/index.js.map | 7 - docs/repl.txt | 65 - docs/types/test.ts | 184 - examples/index.js | 52 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/array.js | 83 - lib/index.js | 65 - lib/main.js | 110 - lib/ndarray.js | 155 - package.json | 77 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 637 --- 45 files changed, 4881 insertions(+), 4954 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.array.js delete mode 100644 benchmark/benchmark.ndarray.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/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/array.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/ndarray.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.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 3b4c7b4..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/utils/map-reduce-right) 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 f23359f..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/utils/map-reduce-right) 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 1308146..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: '21 21 * * 4' - - # 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 + + ```
@@ -281,7 +272,7 @@ console.log( 'sum: %d', out ); ## 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]. @@ -344,19 +335,19 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/utils-map-reduce-right/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64 +[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64/tree/esm -[@stdlib/array/complex128]: https://github.com/stdlib-js/array-complex128 +[@stdlib/array/complex128]: https://github.com/stdlib-js/array-complex128/tree/esm -[@stdlib/utils/map-right]: https://github.com/stdlib-js/utils-map-right +[@stdlib/utils/map-right]: https://github.com/stdlib-js/utils-map-right/tree/esm -[@stdlib/utils/map-reduce]: https://github.com/stdlib-js/utils-map-reduce +[@stdlib/utils/map-reduce]: https://github.com/stdlib-js/utils-map-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/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.array.js b/benchmark/benchmark.array.js deleted file mode 100644 index da29c82..0000000 --- a/benchmark/benchmark.array.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = filled( -3.0, len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::array:len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.ndarray.js b/benchmark/benchmark.ndarray.js deleted file mode 100644 index 7806caa..0000000 --- a/benchmark/benchmark.ndarray.js +++ /dev/null @@ -1,109 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var xbuf; - var opts; - var x; - - xbuf = filled( -3.0, len ); - - opts = { - 'dtype': 'generic' - }; - x = array( xbuf, opts ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::ndarray:len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0816c5f..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/utils/map-reduce-right" -%% click B href "https://github.com/stdlib-js/utils-map-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-map-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-map-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-map-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-map-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/map-reduce-right -[production-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-map-reduce-right/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-map-reduce-right/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-map-reduce-right/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 63ea99a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import mapReduceRight from '../docs/types/index'; -export = mapReduceRight; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 3180c8b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,9 +0,0 @@ -"use strict";var g=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var q=g(function(H,m){ -var E=require('@stdlib/ndarray-base-vind2bind/dist'),T="throw";function p(r,e,a,t,s){var i,v,n,u,f,c,l,y,d,b,o;if(u=r.length,l=r.shape,i=r.data,y=r.strides,d=r.offset,v=r.order,f=r.accessors[0],c=r.ref,l.length===0)return t.call(s,e,a(f(i,d),0,c),0,c);for(n=e,o=u-1;o>=0;o--)b=E(l,y,d,v,o,T),n=t.call(s,n,a(f(i,b),o,c),o,c);return n}m.exports=p -});var R=g(function(I,w){ -function x(r,e,a,t,s){var i,v,n,u;for(i=r.data,v=r.accessors[0],n=e,u=i.length-1;u>=0;u--)n=t.call(s,n,a(v(i,u),u,i),u,i);return n}w.exports=x -});var j=g(function(J,F){ -var V=require('@stdlib/assert-is-array-like-object/dist'),L=require('@stdlib/assert-is-ndarray-like/dist'),k=require('@stdlib/assert-is-function/dist'),O=require('@stdlib/ndarray-base-ndarraylike2object/dist'),D=require('@stdlib/array-base-arraylike2object/dist'),h=require('@stdlib/error-tools-fmtprodmsg/dist'),M=q(),z=R();function B(r,e,a,t,s){if(!k(a))throw new TypeError(h('1VL3N',a));if(!k(t))throw new TypeError(h('1VL32',t));if(L(r))return M(O(r),e,a,t,s);if(V(r))return z(D(r),e,a,t,s);throw new TypeError(h('1VLBH',r))}F.exports=B -});var C=j();module.exports=C; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 641859d..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/ndarray.js", "../lib/array.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* var Complex64Array = require( '@stdlib/array-complex64' );\n* var Complex64 = require( '@stdlib/complex-float32' );\n* var realf = require( '@stdlib/complex-realf' );\n* var imagf = require( '@stdlib/complex-imagf' );\n* var cceil = require( '@stdlib/math-base-special-cceil' );\n* var cadd = require( '@stdlib/math-base-ops-cadd' );\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar format = require( '@stdlib/string-format' );\nvar ndarrayFcn = require( './ndarray.js' );\nvar arrayFcn = require( './array.js' );\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/math-base-ops-add' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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* Perform a map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.\n*\n* @module @stdlib/utils-map-reduce-right\n*\n* @example\n* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' );\n*\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, sum );\n* // returns 30\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/math-base-ops-add' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\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,EAAY,QAAS,gCAAiC,EAKtDC,EAAO,QA0EX,SAASC,EAAgBC,EAAGC,EAASC,EAAQC,EAASC,EAAU,CAC/D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMR,EAAE,OAGRW,EAAMX,EAAE,MAGRK,EAAOL,EAAE,KAGTY,EAAKZ,EAAE,QAGPa,EAAKb,EAAE,OAGPM,EAAON,EAAE,MAGTS,EAAMT,EAAE,UAAW,CAAE,EAGrBU,EAAMV,EAAE,IAGHW,EAAI,SAAW,EACnB,OAAOR,EAAQ,KAAMC,EAASH,EAASC,EAAQO,EAAKJ,EAAMQ,CAAG,EAAG,EAAGH,CAAI,EAAG,EAAGA,CAAI,EAIlF,IADAH,EAAMN,EACAc,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKjB,EAAWc,EAAKC,EAAIC,EAAIP,EAAMS,EAAGjB,CAAK,EAC3CS,EAAMJ,EAAQ,KAAMC,EAASG,EAAKL,EAAQO,EAAKJ,EAAMS,CAAG,EAAGC,EAAGL,CAAI,EAAGK,EAAGL,CAAI,EAE7E,OAAOH,CACR,CAKAX,EAAO,QAAUG,IC1JjB,IAAAiB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA2DA,SAASC,EAAgBC,EAAGC,EAASC,EAAQC,EAASC,EAAU,CAC/D,IAAIC,EACAC,EACAC,EACAC,EAUJ,IAPAH,EAAOL,EAAE,KAGTM,EAAMN,EAAE,UAAW,CAAE,EAGrBO,EAAMN,EACAO,EAAIH,EAAK,OAAO,EAAGG,GAAK,EAAGA,IAChCD,EAAMJ,EAAQ,KAAMC,EAASG,EAAKL,EAAQI,EAAKD,EAAMG,CAAE,EAAGA,EAAGH,CAAK,EAAGG,EAAGH,CAAK,EAE9E,OAAOE,CACR,CAKAT,EAAO,QAAUC,IClFjB,IAAAU,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAoB,QAAS,qCAAsC,EACnEC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,4BAA6B,EACnDC,EAAqB,QAAS,yCAA0C,EACxEC,EAAmB,QAAS,qCAAsC,EAClEC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAW,IA6Df,SAASC,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,EAAU,CACjE,GAAK,CAACX,EAAYS,CAAO,EACxB,MAAM,IAAI,UAAWN,EAAQ,oEAAqEM,CAAO,CAAE,EAE5G,GAAK,CAACT,EAAYU,CAAQ,EACzB,MAAM,IAAI,UAAWP,EAAQ,qEAAsEO,CAAQ,CAAE,EAE9G,GAAKX,EAAeQ,CAAI,EACvB,OAAOH,EAAYH,EAAoBM,CAAI,EAAGC,EAASC,EAAQC,EAASC,CAAQ,EAEjF,GAAKb,EAAmBS,CAAI,EAC3B,OAAOF,EAAUH,EAAkBK,CAAI,EAAGC,EAASC,EAAQC,EAASC,CAAQ,EAE7E,MAAM,IAAI,UAAWR,EAAQ,4FAA6FI,CAAI,CAAE,CACjI,CAKAV,EAAO,QAAUS,IClDjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_ndarray", "__commonJSMin", "exports", "module", "vind2bind", "MODE", "mapReduceRight", "x", "initial", "mapper", "reducer", "thisArg", "xbuf", "ordx", "acc", "len", "get", "ref", "shx", "sx", "ox", "ix", "i", "require_array", "__commonJSMin", "exports", "module", "mapReduceRight", "x", "initial", "mapper", "reducer", "thisArg", "xbuf", "get", "acc", "i", "require_main", "__commonJSMin", "exports", "module", "isArrayLikeObject", "isndarrayLike", "isFunction", "ndarraylike2object", "arraylike2object", "format", "ndarrayFcn", "arrayFcn", "mapReduceRight", "arr", "initial", "mapper", "reducer", "thisArg", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b580e87..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, initial, mapper, reducer[, thisArg] ) - Performs a map-reduce operation for each element in an array while iterating - from right to left and returns the accumulated result. - - When invoked, the mapping function is provided three arguments: - - - value: array element. - - index: element index. - - arr: input array. - - When invoked, the reducing function is provided four arguments: - - - accumulator: accumulated value. - - value: result after applying the mapping function to the current array - element. - - index: element index. - - arr: input array. - - If provided an empty array, the function returns the initial value. - - When provided an ndarray, the function performs a single-pass map-reduce - operation over the entire input ndarray (i.e., higher-order ndarray - dimensions are flattened to a single-dimension). - - Parameters - ---------- - arr: ArrayLikeObject|ndarray - Input array. - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - mapper: Function - Mapping function. - - reducer: Function - Reducing function. - - thisArg: any (optional) - Execution context for the reducing function. - - Returns - ------- - out: any - Accumulated result. - - Examples - -------- - // array-like object: - > var f1 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/special/abs}}, 1 ); - > var f2 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/ops/add}}, 2 ); - > var arr = [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0 ]; - > var out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - // ndarray: - > arr = {{alias:@stdlib/ndarray/array}}( arr, { 'shape': [ 2, 3 ] } ); - > out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 3fcccbb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,184 +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. -*/ - -import array = require( '@stdlib/ndarray-array' ); -import mapReduceRight = require( './index' ); - -/** -* Mapping function. -* -* @param value - array element -* @returns result -*/ -function mapper( value: number ): number { - return value; -} - -/** -* Reducing function. -* -* @param acc - accumulated value -* @param v - array element -* @returns result -*/ -function reducer( acc: number, value: number ): number { - return acc + value; -} - - -// TESTS // - -// The function returns the accumulated value when provided a collection... -{ - mapReduceRight( [ 0, 1, 1, NaN, 2 ], 0, mapper, reducer ); // $ExpectType number - mapReduceRight( [ -1, 1, 2 ], 100, mapper, reducer ); // $ExpectType number - mapReduceRight( [ -1, 1, 2 ], 0, mapper, reducer, {} ); // $ExpectType number -} - -// The function returns the accumulated value when provided an ndarray... -{ - const arr = array( [ 1, 2, 3, 4, 5, 6 ] ); - - mapReduceRight( arr, 0, mapper, reducer ); // $ExpectType number - mapReduceRight( arr, 100, mapper, reducer ); // $ExpectType number - mapReduceRight( arr, 0, mapper, reducer, {} ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not a collection or ndarray... -{ - mapReduceRight( 2, 0, mapper, reducer ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer ); // $ExpectError - - mapReduceRight( 2, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr1, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr2, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const arr1 = [ 1, 2, 3 ]; - - mapReduceRight(); // $ExpectError - mapReduceRight( arr1 ); // $ExpectError - mapReduceRight( arr1, 0 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ); // $ExpectError - mapReduceRight( arr1, 0, mapper, reducer, {}, 3 ); // $ExpectError - - const arr2 = array( [ 1, 2, 3 ] ); - - mapReduceRight(); // $ExpectError - mapReduceRight( arr2 ); // $ExpectError - mapReduceRight( arr2, 0 ); // $ExpectError - mapReduceRight( arr2, 0, mapper ); // $ExpectError - mapReduceRight( arr2, 0, mapper, reducer, {}, 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 7474059..0000000 --- a/examples/index.js +++ /dev/null @@ -1,52 +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. -*/ - -'use strict'; - -var filledarrayBy = require( '@stdlib/array-filled-by' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ).factory; -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var mapReduceRight = require( './../lib' ); - -function fill( i ) { - var rand = discreteUniform( -10*(i+1), 10*(i+1) ); - return filledarrayBy( 10, 'generic', rand ); -} - -// Create a two-dimensional ndarray (i.e., a matrix): -var x = array( filledarrayBy( 10, 'generic', fill ), { - 'dtype': 'generic', - 'flatten': true -}); - -// Create an explicit unary function: -var f1 = naryFunction( abs, 1 ); - -// Create an explicit binary function: -var f2 = naryFunction( add, 2 ); - -// Compute the sum of absolute values: -var out = mapReduceRight( x, 0, f1, f2 ); - -console.log( 'x:' ); -console.log( x.data ); - -console.log( 'sum: %d', out ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index f3614c6..861830b 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; import { typedndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..387a077 --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.2.1-esm/index.mjs";var o="throw";function a(a,m,l,j,f){if(!e(l))throw new TypeError(n("1VL3N",l));if(!e(j))throw new TypeError(n("1VL32",j));if(s(a))return function(r,s,e,t,i){var n,a,m,l,j,f,h,c,p,v,b;if(l=r.length,h=r.shape,n=r.data,c=r.strides,p=r.offset,a=r.order,j=r.accessors[0],f=r.ref,0===h.length)return t.call(i,s,e(j(n,p),0,f),0,f);for(m=s,b=l-1;b>=0;b--)v=d(h,c,p,a,b,o),m=t.call(i,m,e(j(n,v),b,f),b,f);return m}(t(a),m,l,j,f);if(r(a))return function(r,s,e,t,i){var n,d,o,a;for(n=r.data,d=r.accessors[0],o=s,a=n.length-1;a>=0;a--)o=t.call(i,o,e(d(n,a),a,n),a,n);return o}(i(a),m,l,j,f);throw new TypeError(n("1VLBH",a))}export{a as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..f8ef5f4 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/ndarray.js","../lib/main.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind';\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64';\n* import Complex64 from '@stdlib/complex-float32';\n* import realf from '@stdlib/complex-realf';\n* import imagf from '@stdlib/complex-imagf';\n* import cceil from '@stdlib/math-base-special-cceil';\n* import cadd from '@stdlib/math-base-ops-cadd';\n* import naryFunction from '@stdlib/utils-nary-function';\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isFunction from '@stdlib/assert-is-function';\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object';\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndarrayFcn from './ndarray.js';\nimport arrayFcn from './array.js';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function';\n* import add from '@stdlib/math-base-ops-add';\n* import abs from '@stdlib/math-base-special-abs';\n* import array from '@stdlib/ndarray-array';\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '1VL3N', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '1VL32', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '1VLBH', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["MODE","mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","accessors","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;srBA2BA,IAAIA,EAAO,QC+DX,SAASC,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,GAAKK,EAAeR,GACnB,ODGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,UAAW,GAGnBZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAAGtB,GACtCc,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,CACR,CCnDSkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OC1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,UAAW,GAGnBf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,CACR,CDwBSqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,QAASP,GACvC"} \ No newline at end of file diff --git a/lib/array.js b/lib/array.js deleted file mode 100644 index 69c0a8c..0000000 --- a/lib/array.js +++ /dev/null @@ -1,83 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input array data -* @param {ArrayLikeObject} x.data - input array data -* @param {Array} x.accessors - input array accessors -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf[ idx ]; -* } -* -* // Create the input array object: -* var x = { -* 'data': [ 1, 2, 3, 4 ], -* 'accessors': [ getter ] -* }; -* -* // Compute the sum of squared values: -* var out = mapReduceRight( x, 0, square, sum ); -* // returns 30 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var get; - var acc; - var i; - - // Cache reference to the input data: - xbuf = x.data; - - // Cache the element accessor: - get = x.accessors[ 0 ]; - - // Iterate over each element... - acc = initial; - for ( i = xbuf.length-1; i >= 0; i-- ) { - acc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 522693e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +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. -*/ - -'use strict'; - -/** -* Perform a map-reduce operation against each element in an array while iterating from right to left and return the accumulated result. -* -* @module @stdlib/utils-map-reduce-right -* -* @example -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ - -// 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 4b227fe..0000000 --- a/lib/main.js +++ /dev/null @@ -1,110 +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. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ndarrayFcn = require( './ndarray.js' ); -var arrayFcn = require( './array.js' ); - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided the following arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided the following arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result of applying the mapping function against the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* @param {(ArrayLikeObject|ndarray)} arr - input array -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} [thisArg] - reduction function execution context -* @throws {TypeError} first argument must be an array-like object or an ndarray -* @throws {TypeError} third argument must be a function -* @throws {TypeError} fourth argument must be a function -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { - if ( !isFunction( mapper ) ) { - throw new TypeError( format( '1VL3N', mapper ) ); - } - if ( !isFunction( reducer ) ) { - throw new TypeError( format( '1VL32', reducer ) ); - } - if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like - return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - if ( isArrayLikeObject( arr ) ) { - return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - throw new TypeError( format( '1VLBH', arr ) ); -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/ndarray.js b/lib/ndarray.js deleted file mode 100644 index 06e19a5..0000000 --- a/lib/ndarray.js +++ /dev/null @@ -1,155 +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. -*/ - -'use strict'; - -// MODULES // - -var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); - - -// VARIABLES // - -var MODE = 'throw'; - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input ndarray meta data -* @param {string} x.ref - reference to original input ndarray-like object -* @param {string} x.dtype - data type -* @param {Collection} x.data - data buffer -* @param {NonNegativeInteger} x.length - number of elements -* @param {NonNegativeIntegerArray} x.shape - dimensions -* @param {IntegerArray} x.strides - stride lengths -* @param {NonNegativeInteger} x.offset - index offset -* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) -* @param {Array} x.accessors - accessors for accessing data buffer elements -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var Complex64 = require( '@stdlib/complex-float32' ); -* var realf = require( '@stdlib/complex-realf' ); -* var imagf = require( '@stdlib/complex-imagf' ); -* var cceil = require( '@stdlib/math-base-special-cceil' ); -* var cadd = require( '@stdlib/math-base-ops-cadd' ); -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* -* // Create a data buffer: -* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] ); -* -* // Define the shape of the input array: -* var shape = [ 2, 2 ]; -* -* // Define the array strides: -* var sx = [ 2, 1 ]; -* -* // Define the index offset: -* var ox = 0; -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf.get( idx ); -* } -* -* // Create the input ndarray-like object: -* var x = { -* 'ref': null, -* 'dtype': 'complex64', -* 'data': xbuf, -* 'length': 4, -* 'shape': shape, -* 'strides': sx, -* 'offset': ox, -* 'order': 'row-major', -* 'accessors': [ getter ] -* }; -* x.ref = x; -* -* // Compute the sum: -* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) ); -* -* var re = realf( v ); -* // returns 20.0 -* -* var im = imagf( v ); -* // returns 24.0 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var ordx; - var acc; - var len; - var get; - var ref; - var shx; - var sx; - var ox; - var ix; - var i; - - // Cache the total number of elements over which to iterate: - len = x.length; - - // Cache the input array shape: - shx = x.shape; - - // Cache reference to the input ndarray data buffer: - xbuf = x.data; - - // Cache reference to the stride array: - sx = x.strides; - - // Cache the index of the first indexed element: - ox = x.offset; - - // Cache the array order: - ordx = x.order; - - // Cache the element accessor: - get = x.accessors[ 0 ]; - - // Cache the reference to the original input array: - ref = x.ref; - - // Check for a zero-dimensional array... - if ( shx.length === 0 ) { - return reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len - } - // Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)... - acc = initial; - for ( i = len-1; i >= 0; i-- ) { - ix = vind2bind( shx, sx, ox, ordx, i, MODE ); - acc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/package.json b/package.json index 52245ed..3df9694 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Perform a single-pass map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.", "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/array-base-arraylike2object": "^0.2.1", - "@stdlib/assert-is-array-like-object": "^0.2.1", - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/ndarray-base-ndarraylike2object": "^0.2.1", - "@stdlib/ndarray-base-vind2bind": "^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-base-filled": "^0.2.1", - "@stdlib/array-complex64": "^0.2.1", - "@stdlib/array-filled-by": "^0.2.1", - "@stdlib/array-float64": "^0.2.1", - "@stdlib/complex-float32": "^0.2.1", - "@stdlib/complex-imagf": "^0.2.1", - "@stdlib/complex-realf": "^0.2.1", - "@stdlib/math-base-assert-is-nan": "^0.2.1", - "@stdlib/math-base-ops-add": "^0.2.1", - "@stdlib/math-base-ops-cadd": "^0.2.1", - "@stdlib/math-base-special-abs": "^0.2.1", - "@stdlib/math-base-special-cceil": "^0.2.1", - "@stdlib/math-base-special-pow": "^0.2.1", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-ctor": "^0.2.1", - "@stdlib/random-base-discrete-uniform": "^0.2.1", - "@stdlib/utils-nary-function": "^0.2.1", - "@stdlib/utils-noop": "^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", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..397a7dd --- /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/test.js b/test/test.js deleted file mode 100644 index 2c78efa..0000000 --- a/test/test.js +++ /dev/null @@ -1,637 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var cadd = require( '@stdlib/math-base-ops-cadd' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var cceil = require( '@stdlib/math-base-special-cceil' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Complex64 = require( '@stdlib/complex-float32' ); -var realf = require( '@stdlib/complex-realf' ); -var imagf = require( '@stdlib/complex-imagf' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var mapReduceRight = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapReduceRight, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a first argument which is either an array-like object or an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( value, 0, noop, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value, {} ); - }; - } -}); - -tape( 'the function performs a map-reduce operation for each element in an array (array-like object)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = [ -1, -2, -3 ]; - expected = 7; - actual = mapReduceRight( arr, 1, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (typed array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - expected = 7.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (complex number array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( cceil, 1 ); - f2 = naryFunction( cadd, 2 ); - - arr = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5 ] ); - expected = new Complex64( 12.0, 15.0 ); - actual = mapReduceRight( arr, new Complex64( 0.0, 0.0 ), f1, f2 ); - - t.strictEqual( realf( actual ), realf( expected ), 'returns expected value' ); - t.strictEqual( imagf( actual ), imagf( expected ), 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = array( [ -1.0, -2.0, -3.0, -4.0 ], { - 'dtype': 'generic' - }); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray; 0-dimensional)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = ndarray( 'generic', [ -10.0 ], [], [ 0 ], 0, 'row-major' ); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (array-like object)', function test( t ) { - var out = mapReduceRight( [], 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (ndarray)', function test( t ) { - var arr; - var out; - - arr = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 0, 2 ], [ 0, 2, 1 ], 0, 'row-major' ); - out = mapReduceRight( arr, 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function supports providing a `this` context (array-like object)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = [ -1.0, -2.0, -3.0 ]; - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function supports providing a `this` context (ndarray)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = array( [ -1.0, -2.0, -3.0 ], { - 'dtype': 'generic' - }); - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = array( [ 1, , , 4 ], { // eslint-disable-line no-sparse-arrays - 'dtype': 'generic' - }); - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); From 167bd9c0c96fc2d458722b077416ccea13654dce Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 18 Jul 2024 01:38:50 +0000 Subject: [PATCH 77/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index d95cde3..4b227fe 100644 --- a/lib/main.js +++ b/lib/main.js @@ -25,7 +25,7 @@ var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); var isFunction = require( '@stdlib/assert-is-function' ); var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ndarrayFcn = require( './ndarray.js' ); var arrayFcn = require( './array.js' ); @@ -90,10 +90,10 @@ var arrayFcn = require( './array.js' ); */ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( !isFunction( mapper ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) ); + throw new TypeError( format( '1VL3N', mapper ) ); } if ( !isFunction( reducer ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) ); + throw new TypeError( format( '1VL32', reducer ) ); } if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len @@ -101,7 +101,7 @@ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( isArrayLikeObject( arr ) ) { return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len } - throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) ); + throw new TypeError( format( '1VLBH', arr ) ); } diff --git a/package.json b/package.json index a95d225..1145138 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-ndarray-like": "^0.2.1", "@stdlib/ndarray-base-ndarraylike2object": "^0.2.1", "@stdlib/ndarray-base-vind2bind": "^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 4aa7c05870066aa39d50a41ba517a8fd5ffee487 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 18 Jul 2024 01:47:34 +0000 Subject: [PATCH 78/91] Remove files --- index.d.ts | 257 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5104 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 861830b..0000000 --- a/index.d.ts +++ /dev/null @@ -1,257 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; -import { typedndarray } from '@stdlib/types/ndarray'; - -/** -* Callback invoked for each array element. -* -* @returns result -*/ -type Nullary = () => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @returns result -*/ -type Unary = ( value: T ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @returns result -*/ -type Binary = ( value: T, index: number ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Ternary = ( value: T, index: number, arr: typedndarray ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayTernary = ( value: T, index: number, arr: Collection ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Mapper = Nullary | Unary | Binary | Ternary; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayMapper = Nullary | Unary | Binary | ArrayTernary; - -/** -* Function applied against an accumulator. -* -* @returns accumulator value -*/ -type NullaryReducer = ( this: W ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @returns accumulator value -*/ -type UnaryReducer = ( this: W, accumulator: V ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @returns accumulator value -*/ -type BinaryReducer = ( this: W, accumulator: V, value: U ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @returns accumulator value -*/ -type TernaryReducer = ( this: W, accumulator: V, value: U, index: number ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type QuaternaryReducer = ( this: W, accumulator: V, value: U, index: number, arr: typedndarray ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayQuaternaryReducer = ( this: W, accumulator: V, value: U, index: number, arr: Collection ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type Reducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | QuaternaryReducer; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayReducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | ArrayQuaternaryReducer; - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 2 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -declare function mapReduceRight( arr: typedndarray, initial: V, mapper: Mapper, reducer: Reducer, thisArg?: ThisParameterType> ): V; - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -*/ -declare function mapReduceRight( arr: Collection, initial: V, mapper: ArrayMapper, reducer: ArrayReducer, thisArg?: ThisParameterType> ): V; - - -// EXPORTS // - -export = mapReduceRight; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 387a077..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.2.1-esm/index.mjs";var o="throw";function a(a,m,l,j,f){if(!e(l))throw new TypeError(n("1VL3N",l));if(!e(j))throw new TypeError(n("1VL32",j));if(s(a))return function(r,s,e,t,i){var n,a,m,l,j,f,h,c,p,v,b;if(l=r.length,h=r.shape,n=r.data,c=r.strides,p=r.offset,a=r.order,j=r.accessors[0],f=r.ref,0===h.length)return t.call(i,s,e(j(n,p),0,f),0,f);for(m=s,b=l-1;b>=0;b--)v=d(h,c,p,a,b,o),m=t.call(i,m,e(j(n,v),b,f),b,f);return m}(t(a),m,l,j,f);if(r(a))return function(r,s,e,t,i){var n,d,o,a;for(n=r.data,d=r.accessors[0],o=s,a=n.length-1;a>=0;a--)o=t.call(i,o,e(d(n,a),a,n),a,n);return o}(i(a),m,l,j,f);throw new TypeError(n("1VLBH",a))}export{a as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index f8ef5f4..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/ndarray.js","../lib/main.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind';\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64';\n* import Complex64 from '@stdlib/complex-float32';\n* import realf from '@stdlib/complex-realf';\n* import imagf from '@stdlib/complex-imagf';\n* import cceil from '@stdlib/math-base-special-cceil';\n* import cadd from '@stdlib/math-base-ops-cadd';\n* import naryFunction from '@stdlib/utils-nary-function';\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isFunction from '@stdlib/assert-is-function';\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object';\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndarrayFcn from './ndarray.js';\nimport arrayFcn from './array.js';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function';\n* import add from '@stdlib/math-base-ops-add';\n* import abs from '@stdlib/math-base-special-abs';\n* import array from '@stdlib/ndarray-array';\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '1VL3N', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '1VL32', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '1VLBH', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["MODE","mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","accessors","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;srBA2BA,IAAIA,EAAO,QC+DX,SAASC,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,GAAKK,EAAeR,GACnB,ODGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,UAAW,GAGnBZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAAGtB,GACtCc,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,CACR,CCnDSkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OC1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,UAAW,GAGnBf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,CACR,CDwBSqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,QAASP,GACvC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 397a7dd..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From a25b3f03a0dacb56cc1f5d54e52ab63a0326da4d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 18 Jul 2024 01:48:16 +0000 Subject: [PATCH 79/91] 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 | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 112 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 71 +- SECURITY.md | 5 - benchmark/benchmark.array.js | 98 - benchmark/benchmark.ndarray.js | 109 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 9 - dist/index.js.map | 7 - docs/repl.txt | 65 - docs/types/test.ts | 184 - examples/index.js | 52 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/array.js | 83 - lib/index.js | 65 - lib/main.js | 110 - lib/ndarray.js | 155 - package.json | 77 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 637 --- 45 files changed, 4881 insertions(+), 5072 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.array.js delete mode 100644 benchmark/benchmark.ndarray.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/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/array.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/ndarray.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.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 3b4c7b4..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/utils/map-reduce-right) 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 f23359f..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/utils/map-reduce-right) 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 1308146..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: '21 21 * * 4' - - # 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 + + ```
@@ -281,7 +272,7 @@ console.log( 'sum: %d', out ); ## 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]. @@ -344,19 +335,19 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/utils-map-reduce-right/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64 +[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64/tree/esm -[@stdlib/array/complex128]: https://github.com/stdlib-js/array-complex128 +[@stdlib/array/complex128]: https://github.com/stdlib-js/array-complex128/tree/esm -[@stdlib/utils/map-right]: https://github.com/stdlib-js/utils-map-right +[@stdlib/utils/map-right]: https://github.com/stdlib-js/utils-map-right/tree/esm -[@stdlib/utils/map-reduce]: https://github.com/stdlib-js/utils-map-reduce +[@stdlib/utils/map-reduce]: https://github.com/stdlib-js/utils-map-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/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.array.js b/benchmark/benchmark.array.js deleted file mode 100644 index da29c82..0000000 --- a/benchmark/benchmark.array.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = filled( -3.0, len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::array:len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.ndarray.js b/benchmark/benchmark.ndarray.js deleted file mode 100644 index 7806caa..0000000 --- a/benchmark/benchmark.ndarray.js +++ /dev/null @@ -1,109 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var xbuf; - var opts; - var x; - - xbuf = filled( -3.0, len ); - - opts = { - 'dtype': 'generic' - }; - x = array( xbuf, opts ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::ndarray:len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0816c5f..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/utils/map-reduce-right" -%% click B href "https://github.com/stdlib-js/utils-map-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-map-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-map-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-map-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-map-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/map-reduce-right -[production-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-map-reduce-right/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-map-reduce-right/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-map-reduce-right/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 63ea99a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import mapReduceRight from '../docs/types/index'; -export = mapReduceRight; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 3180c8b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,9 +0,0 @@ -"use strict";var g=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var q=g(function(H,m){ -var E=require('@stdlib/ndarray-base-vind2bind/dist'),T="throw";function p(r,e,a,t,s){var i,v,n,u,f,c,l,y,d,b,o;if(u=r.length,l=r.shape,i=r.data,y=r.strides,d=r.offset,v=r.order,f=r.accessors[0],c=r.ref,l.length===0)return t.call(s,e,a(f(i,d),0,c),0,c);for(n=e,o=u-1;o>=0;o--)b=E(l,y,d,v,o,T),n=t.call(s,n,a(f(i,b),o,c),o,c);return n}m.exports=p -});var R=g(function(I,w){ -function x(r,e,a,t,s){var i,v,n,u;for(i=r.data,v=r.accessors[0],n=e,u=i.length-1;u>=0;u--)n=t.call(s,n,a(v(i,u),u,i),u,i);return n}w.exports=x -});var j=g(function(J,F){ -var V=require('@stdlib/assert-is-array-like-object/dist'),L=require('@stdlib/assert-is-ndarray-like/dist'),k=require('@stdlib/assert-is-function/dist'),O=require('@stdlib/ndarray-base-ndarraylike2object/dist'),D=require('@stdlib/array-base-arraylike2object/dist'),h=require('@stdlib/error-tools-fmtprodmsg/dist'),M=q(),z=R();function B(r,e,a,t,s){if(!k(a))throw new TypeError(h('1VL3N',a));if(!k(t))throw new TypeError(h('1VL32',t));if(L(r))return M(O(r),e,a,t,s);if(V(r))return z(D(r),e,a,t,s);throw new TypeError(h('1VLBH',r))}F.exports=B -});var C=j();module.exports=C; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 17c2d18..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/ndarray.js", "../lib/array.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* var Complex64Array = require( '@stdlib/array-complex64' );\n* var Complex64 = require( '@stdlib/complex-float32-ctor' );\n* var realf = require( '@stdlib/complex-float32-real' );\n* var imagf = require( '@stdlib/complex-float32-imag' );\n* var cceil = require( '@stdlib/math-base-special-cceil' );\n* var cadd = require( '@stdlib/complex-float64-base-add' );\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar format = require( '@stdlib/string-format' );\nvar ndarrayFcn = require( './ndarray.js' );\nvar arrayFcn = require( './array.js' );\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/math-base-ops-add' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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* Perform a map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.\n*\n* @module @stdlib/utils-map-reduce-right\n*\n* @example\n* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' );\n*\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, sum );\n* // returns 30\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/math-base-ops-add' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\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,EAAY,QAAS,gCAAiC,EAKtDC,EAAO,QA0EX,SAASC,EAAgBC,EAAGC,EAASC,EAAQC,EAASC,EAAU,CAC/D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMR,EAAE,OAGRW,EAAMX,EAAE,MAGRK,EAAOL,EAAE,KAGTY,EAAKZ,EAAE,QAGPa,EAAKb,EAAE,OAGPM,EAAON,EAAE,MAGTS,EAAMT,EAAE,UAAW,CAAE,EAGrBU,EAAMV,EAAE,IAGHW,EAAI,SAAW,EACnB,OAAOR,EAAQ,KAAMC,EAASH,EAASC,EAAQO,EAAKJ,EAAMQ,CAAG,EAAG,EAAGH,CAAI,EAAG,EAAGA,CAAI,EAIlF,IADAH,EAAMN,EACAc,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKjB,EAAWc,EAAKC,EAAIC,EAAIP,EAAMS,EAAGjB,CAAK,EAC3CS,EAAMJ,EAAQ,KAAMC,EAASG,EAAKL,EAAQO,EAAKJ,EAAMS,CAAG,EAAGC,EAAGL,CAAI,EAAGK,EAAGL,CAAI,EAE7E,OAAOH,CACR,CAKAX,EAAO,QAAUG,IC1JjB,IAAAiB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA2DA,SAASC,EAAgBC,EAAGC,EAASC,EAAQC,EAASC,EAAU,CAC/D,IAAIC,EACAC,EACAC,EACAC,EAUJ,IAPAH,EAAOL,EAAE,KAGTM,EAAMN,EAAE,UAAW,CAAE,EAGrBO,EAAMN,EACAO,EAAIH,EAAK,OAAO,EAAGG,GAAK,EAAGA,IAChCD,EAAMJ,EAAQ,KAAMC,EAASG,EAAKL,EAAQI,EAAKD,EAAMG,CAAE,EAAGA,EAAGH,CAAK,EAAGG,EAAGH,CAAK,EAE9E,OAAOE,CACR,CAKAT,EAAO,QAAUC,IClFjB,IAAAU,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAoB,QAAS,qCAAsC,EACnEC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,4BAA6B,EACnDC,EAAqB,QAAS,yCAA0C,EACxEC,EAAmB,QAAS,qCAAsC,EAClEC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAW,IA6Df,SAASC,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,EAAU,CACjE,GAAK,CAACX,EAAYS,CAAO,EACxB,MAAM,IAAI,UAAWN,EAAQ,oEAAqEM,CAAO,CAAE,EAE5G,GAAK,CAACT,EAAYU,CAAQ,EACzB,MAAM,IAAI,UAAWP,EAAQ,qEAAsEO,CAAQ,CAAE,EAE9G,GAAKX,EAAeQ,CAAI,EACvB,OAAOH,EAAYH,EAAoBM,CAAI,EAAGC,EAASC,EAAQC,EAASC,CAAQ,EAEjF,GAAKb,EAAmBS,CAAI,EAC3B,OAAOF,EAAUH,EAAkBK,CAAI,EAAGC,EAASC,EAAQC,EAASC,CAAQ,EAE7E,MAAM,IAAI,UAAWR,EAAQ,4FAA6FI,CAAI,CAAE,CACjI,CAKAV,EAAO,QAAUS,IClDjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_ndarray", "__commonJSMin", "exports", "module", "vind2bind", "MODE", "mapReduceRight", "x", "initial", "mapper", "reducer", "thisArg", "xbuf", "ordx", "acc", "len", "get", "ref", "shx", "sx", "ox", "ix", "i", "require_array", "__commonJSMin", "exports", "module", "mapReduceRight", "x", "initial", "mapper", "reducer", "thisArg", "xbuf", "get", "acc", "i", "require_main", "__commonJSMin", "exports", "module", "isArrayLikeObject", "isndarrayLike", "isFunction", "ndarraylike2object", "arraylike2object", "format", "ndarrayFcn", "arrayFcn", "mapReduceRight", "arr", "initial", "mapper", "reducer", "thisArg", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b580e87..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, initial, mapper, reducer[, thisArg] ) - Performs a map-reduce operation for each element in an array while iterating - from right to left and returns the accumulated result. - - When invoked, the mapping function is provided three arguments: - - - value: array element. - - index: element index. - - arr: input array. - - When invoked, the reducing function is provided four arguments: - - - accumulator: accumulated value. - - value: result after applying the mapping function to the current array - element. - - index: element index. - - arr: input array. - - If provided an empty array, the function returns the initial value. - - When provided an ndarray, the function performs a single-pass map-reduce - operation over the entire input ndarray (i.e., higher-order ndarray - dimensions are flattened to a single-dimension). - - Parameters - ---------- - arr: ArrayLikeObject|ndarray - Input array. - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - mapper: Function - Mapping function. - - reducer: Function - Reducing function. - - thisArg: any (optional) - Execution context for the reducing function. - - Returns - ------- - out: any - Accumulated result. - - Examples - -------- - // array-like object: - > var f1 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/special/abs}}, 1 ); - > var f2 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/ops/add}}, 2 ); - > var arr = [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0 ]; - > var out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - // ndarray: - > arr = {{alias:@stdlib/ndarray/array}}( arr, { 'shape': [ 2, 3 ] } ); - > out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 3fcccbb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,184 +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. -*/ - -import array = require( '@stdlib/ndarray-array' ); -import mapReduceRight = require( './index' ); - -/** -* Mapping function. -* -* @param value - array element -* @returns result -*/ -function mapper( value: number ): number { - return value; -} - -/** -* Reducing function. -* -* @param acc - accumulated value -* @param v - array element -* @returns result -*/ -function reducer( acc: number, value: number ): number { - return acc + value; -} - - -// TESTS // - -// The function returns the accumulated value when provided a collection... -{ - mapReduceRight( [ 0, 1, 1, NaN, 2 ], 0, mapper, reducer ); // $ExpectType number - mapReduceRight( [ -1, 1, 2 ], 100, mapper, reducer ); // $ExpectType number - mapReduceRight( [ -1, 1, 2 ], 0, mapper, reducer, {} ); // $ExpectType number -} - -// The function returns the accumulated value when provided an ndarray... -{ - const arr = array( [ 1, 2, 3, 4, 5, 6 ] ); - - mapReduceRight( arr, 0, mapper, reducer ); // $ExpectType number - mapReduceRight( arr, 100, mapper, reducer ); // $ExpectType number - mapReduceRight( arr, 0, mapper, reducer, {} ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not a collection or ndarray... -{ - mapReduceRight( 2, 0, mapper, reducer ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer ); // $ExpectError - - mapReduceRight( 2, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr1, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr2, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const arr1 = [ 1, 2, 3 ]; - - mapReduceRight(); // $ExpectError - mapReduceRight( arr1 ); // $ExpectError - mapReduceRight( arr1, 0 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ); // $ExpectError - mapReduceRight( arr1, 0, mapper, reducer, {}, 3 ); // $ExpectError - - const arr2 = array( [ 1, 2, 3 ] ); - - mapReduceRight(); // $ExpectError - mapReduceRight( arr2 ); // $ExpectError - mapReduceRight( arr2, 0 ); // $ExpectError - mapReduceRight( arr2, 0, mapper ); // $ExpectError - mapReduceRight( arr2, 0, mapper, reducer, {}, 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 7474059..0000000 --- a/examples/index.js +++ /dev/null @@ -1,52 +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. -*/ - -'use strict'; - -var filledarrayBy = require( '@stdlib/array-filled-by' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ).factory; -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var mapReduceRight = require( './../lib' ); - -function fill( i ) { - var rand = discreteUniform( -10*(i+1), 10*(i+1) ); - return filledarrayBy( 10, 'generic', rand ); -} - -// Create a two-dimensional ndarray (i.e., a matrix): -var x = array( filledarrayBy( 10, 'generic', fill ), { - 'dtype': 'generic', - 'flatten': true -}); - -// Create an explicit unary function: -var f1 = naryFunction( abs, 1 ); - -// Create an explicit binary function: -var f2 = naryFunction( add, 2 ); - -// Compute the sum of absolute values: -var out = mapReduceRight( x, 0, f1, f2 ); - -console.log( 'x:' ); -console.log( x.data ); - -console.log( 'sum: %d', out ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index f3614c6..861830b 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; import { typedndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..387a077 --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.2.1-esm/index.mjs";var o="throw";function a(a,m,l,j,f){if(!e(l))throw new TypeError(n("1VL3N",l));if(!e(j))throw new TypeError(n("1VL32",j));if(s(a))return function(r,s,e,t,i){var n,a,m,l,j,f,h,c,p,v,b;if(l=r.length,h=r.shape,n=r.data,c=r.strides,p=r.offset,a=r.order,j=r.accessors[0],f=r.ref,0===h.length)return t.call(i,s,e(j(n,p),0,f),0,f);for(m=s,b=l-1;b>=0;b--)v=d(h,c,p,a,b,o),m=t.call(i,m,e(j(n,v),b,f),b,f);return m}(t(a),m,l,j,f);if(r(a))return function(r,s,e,t,i){var n,d,o,a;for(n=r.data,d=r.accessors[0],o=s,a=n.length-1;a>=0;a--)o=t.call(i,o,e(d(n,a),a,n),a,n);return o}(i(a),m,l,j,f);throw new TypeError(n("1VLBH",a))}export{a as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..0897b2b --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/ndarray.js","../lib/main.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind';\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64';\n* import Complex64 from '@stdlib/complex-float32-ctor';\n* import realf from '@stdlib/complex-float32-real';\n* import imagf from '@stdlib/complex-float32-imag';\n* import cceil from '@stdlib/math-base-special-cceil';\n* import cadd from '@stdlib/complex-float64-base-add';\n* import naryFunction from '@stdlib/utils-nary-function';\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isFunction from '@stdlib/assert-is-function';\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object';\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndarrayFcn from './ndarray.js';\nimport arrayFcn from './array.js';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function';\n* import add from '@stdlib/math-base-ops-add';\n* import abs from '@stdlib/math-base-special-abs';\n* import array from '@stdlib/ndarray-array';\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '1VL3N', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '1VL32', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '1VLBH', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["MODE","mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","accessors","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;srBA2BA,IAAIA,EAAO,QC+DX,SAASC,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,GAAKK,EAAeR,GACnB,ODGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,UAAW,GAGnBZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAAGtB,GACtCc,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,CACR,CCnDSkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OC1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,UAAW,GAGnBf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,CACR,CDwBSqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,QAASP,GACvC"} \ No newline at end of file diff --git a/lib/array.js b/lib/array.js deleted file mode 100644 index 69c0a8c..0000000 --- a/lib/array.js +++ /dev/null @@ -1,83 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input array data -* @param {ArrayLikeObject} x.data - input array data -* @param {Array} x.accessors - input array accessors -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf[ idx ]; -* } -* -* // Create the input array object: -* var x = { -* 'data': [ 1, 2, 3, 4 ], -* 'accessors': [ getter ] -* }; -* -* // Compute the sum of squared values: -* var out = mapReduceRight( x, 0, square, sum ); -* // returns 30 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var get; - var acc; - var i; - - // Cache reference to the input data: - xbuf = x.data; - - // Cache the element accessor: - get = x.accessors[ 0 ]; - - // Iterate over each element... - acc = initial; - for ( i = xbuf.length-1; i >= 0; i-- ) { - acc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 522693e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +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. -*/ - -'use strict'; - -/** -* Perform a map-reduce operation against each element in an array while iterating from right to left and return the accumulated result. -* -* @module @stdlib/utils-map-reduce-right -* -* @example -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ - -// 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 4b227fe..0000000 --- a/lib/main.js +++ /dev/null @@ -1,110 +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. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ndarrayFcn = require( './ndarray.js' ); -var arrayFcn = require( './array.js' ); - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided the following arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided the following arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result of applying the mapping function against the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* @param {(ArrayLikeObject|ndarray)} arr - input array -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} [thisArg] - reduction function execution context -* @throws {TypeError} first argument must be an array-like object or an ndarray -* @throws {TypeError} third argument must be a function -* @throws {TypeError} fourth argument must be a function -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { - if ( !isFunction( mapper ) ) { - throw new TypeError( format( '1VL3N', mapper ) ); - } - if ( !isFunction( reducer ) ) { - throw new TypeError( format( '1VL32', reducer ) ); - } - if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like - return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - if ( isArrayLikeObject( arr ) ) { - return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - throw new TypeError( format( '1VLBH', arr ) ); -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/ndarray.js b/lib/ndarray.js deleted file mode 100644 index bcf9eb1..0000000 --- a/lib/ndarray.js +++ /dev/null @@ -1,155 +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. -*/ - -'use strict'; - -// MODULES // - -var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); - - -// VARIABLES // - -var MODE = 'throw'; - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input ndarray meta data -* @param {string} x.ref - reference to original input ndarray-like object -* @param {string} x.dtype - data type -* @param {Collection} x.data - data buffer -* @param {NonNegativeInteger} x.length - number of elements -* @param {NonNegativeIntegerArray} x.shape - dimensions -* @param {IntegerArray} x.strides - stride lengths -* @param {NonNegativeInteger} x.offset - index offset -* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) -* @param {Array} x.accessors - accessors for accessing data buffer elements -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var Complex64 = require( '@stdlib/complex-float32-ctor' ); -* var realf = require( '@stdlib/complex-float32-real' ); -* var imagf = require( '@stdlib/complex-float32-imag' ); -* var cceil = require( '@stdlib/math-base-special-cceil' ); -* var cadd = require( '@stdlib/complex-float64-base-add' ); -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* -* // Create a data buffer: -* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] ); -* -* // Define the shape of the input array: -* var shape = [ 2, 2 ]; -* -* // Define the array strides: -* var sx = [ 2, 1 ]; -* -* // Define the index offset: -* var ox = 0; -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf.get( idx ); -* } -* -* // Create the input ndarray-like object: -* var x = { -* 'ref': null, -* 'dtype': 'complex64', -* 'data': xbuf, -* 'length': 4, -* 'shape': shape, -* 'strides': sx, -* 'offset': ox, -* 'order': 'row-major', -* 'accessors': [ getter ] -* }; -* x.ref = x; -* -* // Compute the sum: -* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) ); -* -* var re = realf( v ); -* // returns 20.0 -* -* var im = imagf( v ); -* // returns 24.0 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var ordx; - var acc; - var len; - var get; - var ref; - var shx; - var sx; - var ox; - var ix; - var i; - - // Cache the total number of elements over which to iterate: - len = x.length; - - // Cache the input array shape: - shx = x.shape; - - // Cache reference to the input ndarray data buffer: - xbuf = x.data; - - // Cache reference to the stride array: - sx = x.strides; - - // Cache the index of the first indexed element: - ox = x.offset; - - // Cache the array order: - ordx = x.order; - - // Cache the element accessor: - get = x.accessors[ 0 ]; - - // Cache the reference to the original input array: - ref = x.ref; - - // Check for a zero-dimensional array... - if ( shx.length === 0 ) { - return reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len - } - // Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)... - acc = initial; - for ( i = len-1; i >= 0; i-- ) { - ix = vind2bind( shx, sx, ox, ordx, i, MODE ); - acc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/package.json b/package.json index 1145138..3df9694 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Perform a single-pass map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.", "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/array-base-arraylike2object": "^0.2.1", - "@stdlib/assert-is-array-like-object": "^0.2.1", - "@stdlib/assert-is-function": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/ndarray-base-ndarraylike2object": "^0.2.1", - "@stdlib/ndarray-base-vind2bind": "^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-base-filled": "^0.2.1", - "@stdlib/array-complex64": "^0.2.1", - "@stdlib/array-filled-by": "^0.2.1", - "@stdlib/array-float64": "^0.2.1", - "@stdlib/complex-float32-ctor": "^0.0.1", - "@stdlib/complex-float32-imag": "^0.1.0", - "@stdlib/complex-float32-real": "^0.1.0", - "@stdlib/complex-float64-base-add": "github:stdlib-js/complex-float64-base-add#main", - "@stdlib/math-base-assert-is-nan": "^0.2.1", - "@stdlib/math-base-ops-add": "^0.2.1", - "@stdlib/math-base-special-abs": "^0.2.1", - "@stdlib/math-base-special-cceil": "^0.2.1", - "@stdlib/math-base-special-pow": "^0.2.1", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-ctor": "^0.2.1", - "@stdlib/random-base-discrete-uniform": "^0.2.1", - "@stdlib/utils-nary-function": "^0.2.1", - "@stdlib/utils-noop": "^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", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..047b857 --- /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/test.js b/test/test.js deleted file mode 100644 index 9280dce..0000000 --- a/test/test.js +++ /dev/null @@ -1,637 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var cadd = require( '@stdlib/complex-float64-base-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var cceil = require( '@stdlib/math-base-special-cceil' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var realf = require( '@stdlib/complex-float32-real' ); -var imagf = require( '@stdlib/complex-float32-imag' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var mapReduceRight = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapReduceRight, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a first argument which is either an array-like object or an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( value, 0, noop, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value, {} ); - }; - } -}); - -tape( 'the function performs a map-reduce operation for each element in an array (array-like object)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = [ -1, -2, -3 ]; - expected = 7; - actual = mapReduceRight( arr, 1, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (typed array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - expected = 7.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (complex number array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( cceil, 1 ); - f2 = naryFunction( cadd, 2 ); - - arr = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5 ] ); - expected = new Complex64( 12.0, 15.0 ); - actual = mapReduceRight( arr, new Complex64( 0.0, 0.0 ), f1, f2 ); - - t.strictEqual( realf( actual ), realf( expected ), 'returns expected value' ); - t.strictEqual( imagf( actual ), imagf( expected ), 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = array( [ -1.0, -2.0, -3.0, -4.0 ], { - 'dtype': 'generic' - }); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray; 0-dimensional)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = ndarray( 'generic', [ -10.0 ], [], [ 0 ], 0, 'row-major' ); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (array-like object)', function test( t ) { - var out = mapReduceRight( [], 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (ndarray)', function test( t ) { - var arr; - var out; - - arr = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 0, 2 ], [ 0, 2, 1 ], 0, 'row-major' ); - out = mapReduceRight( arr, 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function supports providing a `this` context (array-like object)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = [ -1.0, -2.0, -3.0 ]; - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function supports providing a `this` context (ndarray)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = array( [ -1.0, -2.0, -3.0 ], { - 'dtype': 'generic' - }); - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = array( [ 1, , , 4 ], { // eslint-disable-line no-sparse-arrays - 'dtype': 'generic' - }); - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); From 79d18a95d45f6349de5762c65d2bf237d1a9475b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 29 Sep 2024 02:47:41 +0000 Subject: [PATCH 80/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index d95cde3..4b227fe 100644 --- a/lib/main.js +++ b/lib/main.js @@ -25,7 +25,7 @@ var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); var isFunction = require( '@stdlib/assert-is-function' ); var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ndarrayFcn = require( './ndarray.js' ); var arrayFcn = require( './array.js' ); @@ -90,10 +90,10 @@ var arrayFcn = require( './array.js' ); */ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( !isFunction( mapper ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) ); + throw new TypeError( format( '1VL3N', mapper ) ); } if ( !isFunction( reducer ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) ); + throw new TypeError( format( '1VL32', reducer ) ); } if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len @@ -101,7 +101,7 @@ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( isArrayLikeObject( arr ) ) { return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len } - throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) ); + throw new TypeError( format( '1VLBH', arr ) ); } diff --git a/package.json b/package.json index 6b1774d..e64fb59 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-ndarray-like": "^0.2.2", "@stdlib/ndarray-base-ndarraylike2object": "^0.2.2", "@stdlib/ndarray-base-vind2bind": "^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 7cdb8b5b5199fa733488a4a43746b9d0cf620c91 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 29 Sep 2024 02:55:52 +0000 Subject: [PATCH 81/91] Remove files --- index.d.ts | 257 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5104 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 861830b..0000000 --- a/index.d.ts +++ /dev/null @@ -1,257 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; -import { typedndarray } from '@stdlib/types/ndarray'; - -/** -* Callback invoked for each array element. -* -* @returns result -*/ -type Nullary = () => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @returns result -*/ -type Unary = ( value: T ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @returns result -*/ -type Binary = ( value: T, index: number ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Ternary = ( value: T, index: number, arr: typedndarray ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayTernary = ( value: T, index: number, arr: Collection ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Mapper = Nullary | Unary | Binary | Ternary; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayMapper = Nullary | Unary | Binary | ArrayTernary; - -/** -* Function applied against an accumulator. -* -* @returns accumulator value -*/ -type NullaryReducer = ( this: W ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @returns accumulator value -*/ -type UnaryReducer = ( this: W, accumulator: V ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @returns accumulator value -*/ -type BinaryReducer = ( this: W, accumulator: V, value: U ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @returns accumulator value -*/ -type TernaryReducer = ( this: W, accumulator: V, value: U, index: number ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type QuaternaryReducer = ( this: W, accumulator: V, value: U, index: number, arr: typedndarray ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayQuaternaryReducer = ( this: W, accumulator: V, value: U, index: number, arr: Collection ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type Reducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | QuaternaryReducer; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayReducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | ArrayQuaternaryReducer; - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 2 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -declare function mapReduceRight( arr: typedndarray, initial: V, mapper: Mapper, reducer: Reducer, thisArg?: ThisParameterType> ): V; - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -*/ -declare function mapReduceRight( arr: Collection, initial: V, mapper: ArrayMapper, reducer: ArrayReducer, thisArg?: ThisParameterType> ): V; - - -// EXPORTS // - -export = mapReduceRight; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 387a077..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.2.1-esm/index.mjs";var o="throw";function a(a,m,l,j,f){if(!e(l))throw new TypeError(n("1VL3N",l));if(!e(j))throw new TypeError(n("1VL32",j));if(s(a))return function(r,s,e,t,i){var n,a,m,l,j,f,h,c,p,v,b;if(l=r.length,h=r.shape,n=r.data,c=r.strides,p=r.offset,a=r.order,j=r.accessors[0],f=r.ref,0===h.length)return t.call(i,s,e(j(n,p),0,f),0,f);for(m=s,b=l-1;b>=0;b--)v=d(h,c,p,a,b,o),m=t.call(i,m,e(j(n,v),b,f),b,f);return m}(t(a),m,l,j,f);if(r(a))return function(r,s,e,t,i){var n,d,o,a;for(n=r.data,d=r.accessors[0],o=s,a=n.length-1;a>=0;a--)o=t.call(i,o,e(d(n,a),a,n),a,n);return o}(i(a),m,l,j,f);throw new TypeError(n("1VLBH",a))}export{a as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 0897b2b..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/ndarray.js","../lib/main.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind';\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64';\n* import Complex64 from '@stdlib/complex-float32-ctor';\n* import realf from '@stdlib/complex-float32-real';\n* import imagf from '@stdlib/complex-float32-imag';\n* import cceil from '@stdlib/math-base-special-cceil';\n* import cadd from '@stdlib/complex-float64-base-add';\n* import naryFunction from '@stdlib/utils-nary-function';\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isFunction from '@stdlib/assert-is-function';\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object';\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndarrayFcn from './ndarray.js';\nimport arrayFcn from './array.js';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function';\n* import add from '@stdlib/math-base-ops-add';\n* import abs from '@stdlib/math-base-special-abs';\n* import array from '@stdlib/ndarray-array';\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '1VL3N', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '1VL32', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '1VLBH', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["MODE","mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","accessors","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;srBA2BA,IAAIA,EAAO,QC+DX,SAASC,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,GAAKK,EAAeR,GACnB,ODGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,UAAW,GAGnBZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAAGtB,GACtCc,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,CACR,CCnDSkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OC1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,UAAW,GAGnBf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,CACR,CDwBSqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,QAASP,GACvC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 047b857..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 6e037e8e3ee64aa3dbdffa63d4d29c04f41343e2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 29 Sep 2024 02:56:20 +0000 Subject: [PATCH 82/91] 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 | 167 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 71 +- SECURITY.md | 5 - benchmark/benchmark.array.js | 98 - benchmark/benchmark.ndarray.js | 109 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 9 - dist/index.js.map | 7 - docs/repl.txt | 65 - docs/types/test.ts | 184 - examples/index.js | 52 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/array.js | 83 - lib/index.js | 65 - lib/main.js | 110 - lib/ndarray.js | 155 - package.json | 77 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 637 --- 45 files changed, 4881 insertions(+), 5129 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.array.js delete mode 100644 benchmark/benchmark.ndarray.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/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/array.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/ndarray.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.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 3b4c7b4..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/utils/map-reduce-right) 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 f23359f..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/utils/map-reduce-right) 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 1308146..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: '21 21 * * 4' - - # 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 + + ```
@@ -281,7 +272,7 @@ console.log( 'sum: %d', out ); ## 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]. @@ -344,19 +335,19 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/utils-map-reduce-right/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64 +[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64/tree/esm -[@stdlib/array/complex128]: https://github.com/stdlib-js/array-complex128 +[@stdlib/array/complex128]: https://github.com/stdlib-js/array-complex128/tree/esm -[@stdlib/utils/map-right]: https://github.com/stdlib-js/utils-map-right +[@stdlib/utils/map-right]: https://github.com/stdlib-js/utils-map-right/tree/esm -[@stdlib/utils/map-reduce]: https://github.com/stdlib-js/utils-map-reduce +[@stdlib/utils/map-reduce]: https://github.com/stdlib-js/utils-map-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/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.array.js b/benchmark/benchmark.array.js deleted file mode 100644 index da29c82..0000000 --- a/benchmark/benchmark.array.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = filled( -3.0, len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::array:len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.ndarray.js b/benchmark/benchmark.ndarray.js deleted file mode 100644 index 7806caa..0000000 --- a/benchmark/benchmark.ndarray.js +++ /dev/null @@ -1,109 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var xbuf; - var opts; - var x; - - xbuf = filled( -3.0, len ); - - opts = { - 'dtype': 'generic' - }; - x = array( xbuf, opts ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::ndarray:len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0816c5f..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/utils/map-reduce-right" -%% click B href "https://github.com/stdlib-js/utils-map-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-map-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-map-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-map-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-map-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/map-reduce-right -[production-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-map-reduce-right/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-map-reduce-right/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-map-reduce-right/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 63ea99a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import mapReduceRight from '../docs/types/index'; -export = mapReduceRight; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 3180c8b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,9 +0,0 @@ -"use strict";var g=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var q=g(function(H,m){ -var E=require('@stdlib/ndarray-base-vind2bind/dist'),T="throw";function p(r,e,a,t,s){var i,v,n,u,f,c,l,y,d,b,o;if(u=r.length,l=r.shape,i=r.data,y=r.strides,d=r.offset,v=r.order,f=r.accessors[0],c=r.ref,l.length===0)return t.call(s,e,a(f(i,d),0,c),0,c);for(n=e,o=u-1;o>=0;o--)b=E(l,y,d,v,o,T),n=t.call(s,n,a(f(i,b),o,c),o,c);return n}m.exports=p -});var R=g(function(I,w){ -function x(r,e,a,t,s){var i,v,n,u;for(i=r.data,v=r.accessors[0],n=e,u=i.length-1;u>=0;u--)n=t.call(s,n,a(v(i,u),u,i),u,i);return n}w.exports=x -});var j=g(function(J,F){ -var V=require('@stdlib/assert-is-array-like-object/dist'),L=require('@stdlib/assert-is-ndarray-like/dist'),k=require('@stdlib/assert-is-function/dist'),O=require('@stdlib/ndarray-base-ndarraylike2object/dist'),D=require('@stdlib/array-base-arraylike2object/dist'),h=require('@stdlib/error-tools-fmtprodmsg/dist'),M=q(),z=R();function B(r,e,a,t,s){if(!k(a))throw new TypeError(h('1VL3N',a));if(!k(t))throw new TypeError(h('1VL32',t));if(L(r))return M(O(r),e,a,t,s);if(V(r))return z(D(r),e,a,t,s);throw new TypeError(h('1VLBH',r))}F.exports=B -});var C=j();module.exports=C; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 17c2d18..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/ndarray.js", "../lib/array.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* var Complex64Array = require( '@stdlib/array-complex64' );\n* var Complex64 = require( '@stdlib/complex-float32-ctor' );\n* var realf = require( '@stdlib/complex-float32-real' );\n* var imagf = require( '@stdlib/complex-float32-imag' );\n* var cceil = require( '@stdlib/math-base-special-cceil' );\n* var cadd = require( '@stdlib/complex-float64-base-add' );\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar format = require( '@stdlib/string-format' );\nvar ndarrayFcn = require( './ndarray.js' );\nvar arrayFcn = require( './array.js' );\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/math-base-ops-add' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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* Perform a map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.\n*\n* @module @stdlib/utils-map-reduce-right\n*\n* @example\n* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' );\n*\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, sum );\n* // returns 30\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/math-base-ops-add' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\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,EAAY,QAAS,gCAAiC,EAKtDC,EAAO,QA0EX,SAASC,EAAgBC,EAAGC,EAASC,EAAQC,EAASC,EAAU,CAC/D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMR,EAAE,OAGRW,EAAMX,EAAE,MAGRK,EAAOL,EAAE,KAGTY,EAAKZ,EAAE,QAGPa,EAAKb,EAAE,OAGPM,EAAON,EAAE,MAGTS,EAAMT,EAAE,UAAW,CAAE,EAGrBU,EAAMV,EAAE,IAGHW,EAAI,SAAW,EACnB,OAAOR,EAAQ,KAAMC,EAASH,EAASC,EAAQO,EAAKJ,EAAMQ,CAAG,EAAG,EAAGH,CAAI,EAAG,EAAGA,CAAI,EAIlF,IADAH,EAAMN,EACAc,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKjB,EAAWc,EAAKC,EAAIC,EAAIP,EAAMS,EAAGjB,CAAK,EAC3CS,EAAMJ,EAAQ,KAAMC,EAASG,EAAKL,EAAQO,EAAKJ,EAAMS,CAAG,EAAGC,EAAGL,CAAI,EAAGK,EAAGL,CAAI,EAE7E,OAAOH,CACR,CAKAX,EAAO,QAAUG,IC1JjB,IAAAiB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA2DA,SAASC,EAAgBC,EAAGC,EAASC,EAAQC,EAASC,EAAU,CAC/D,IAAIC,EACAC,EACAC,EACAC,EAUJ,IAPAH,EAAOL,EAAE,KAGTM,EAAMN,EAAE,UAAW,CAAE,EAGrBO,EAAMN,EACAO,EAAIH,EAAK,OAAO,EAAGG,GAAK,EAAGA,IAChCD,EAAMJ,EAAQ,KAAMC,EAASG,EAAKL,EAAQI,EAAKD,EAAMG,CAAE,EAAGA,EAAGH,CAAK,EAAGG,EAAGH,CAAK,EAE9E,OAAOE,CACR,CAKAT,EAAO,QAAUC,IClFjB,IAAAU,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAoB,QAAS,qCAAsC,EACnEC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,4BAA6B,EACnDC,EAAqB,QAAS,yCAA0C,EACxEC,EAAmB,QAAS,qCAAsC,EAClEC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAW,IA6Df,SAASC,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,EAAU,CACjE,GAAK,CAACX,EAAYS,CAAO,EACxB,MAAM,IAAI,UAAWN,EAAQ,oEAAqEM,CAAO,CAAE,EAE5G,GAAK,CAACT,EAAYU,CAAQ,EACzB,MAAM,IAAI,UAAWP,EAAQ,qEAAsEO,CAAQ,CAAE,EAE9G,GAAKX,EAAeQ,CAAI,EACvB,OAAOH,EAAYH,EAAoBM,CAAI,EAAGC,EAASC,EAAQC,EAASC,CAAQ,EAEjF,GAAKb,EAAmBS,CAAI,EAC3B,OAAOF,EAAUH,EAAkBK,CAAI,EAAGC,EAASC,EAAQC,EAASC,CAAQ,EAE7E,MAAM,IAAI,UAAWR,EAAQ,4FAA6FI,CAAI,CAAE,CACjI,CAKAV,EAAO,QAAUS,IClDjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_ndarray", "__commonJSMin", "exports", "module", "vind2bind", "MODE", "mapReduceRight", "x", "initial", "mapper", "reducer", "thisArg", "xbuf", "ordx", "acc", "len", "get", "ref", "shx", "sx", "ox", "ix", "i", "require_array", "__commonJSMin", "exports", "module", "mapReduceRight", "x", "initial", "mapper", "reducer", "thisArg", "xbuf", "get", "acc", "i", "require_main", "__commonJSMin", "exports", "module", "isArrayLikeObject", "isndarrayLike", "isFunction", "ndarraylike2object", "arraylike2object", "format", "ndarrayFcn", "arrayFcn", "mapReduceRight", "arr", "initial", "mapper", "reducer", "thisArg", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b580e87..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, initial, mapper, reducer[, thisArg] ) - Performs a map-reduce operation for each element in an array while iterating - from right to left and returns the accumulated result. - - When invoked, the mapping function is provided three arguments: - - - value: array element. - - index: element index. - - arr: input array. - - When invoked, the reducing function is provided four arguments: - - - accumulator: accumulated value. - - value: result after applying the mapping function to the current array - element. - - index: element index. - - arr: input array. - - If provided an empty array, the function returns the initial value. - - When provided an ndarray, the function performs a single-pass map-reduce - operation over the entire input ndarray (i.e., higher-order ndarray - dimensions are flattened to a single-dimension). - - Parameters - ---------- - arr: ArrayLikeObject|ndarray - Input array. - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - mapper: Function - Mapping function. - - reducer: Function - Reducing function. - - thisArg: any (optional) - Execution context for the reducing function. - - Returns - ------- - out: any - Accumulated result. - - Examples - -------- - // array-like object: - > var f1 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/special/abs}}, 1 ); - > var f2 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/ops/add}}, 2 ); - > var arr = [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0 ]; - > var out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - // ndarray: - > arr = {{alias:@stdlib/ndarray/array}}( arr, { 'shape': [ 2, 3 ] } ); - > out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 58a6cae..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,184 +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. -*/ - -import array = require( '@stdlib/ndarray-array' ); -import mapReduceRight = require( './index' ); - -/** -* Mapping function. -* -* @param value - array element -* @returns result -*/ -function mapper( value: number ): number { - return value; -} - -/** -* Reducing function. -* -* @param acc - accumulated value -* @param value - array element -* @returns result -*/ -function reducer( acc: number, value: number ): number { - return acc + value; -} - - -// TESTS // - -// The function returns the accumulated value when provided a collection... -{ - mapReduceRight( [ 0, 1, 1, NaN, 2 ], 0, mapper, reducer ); // $ExpectType number - mapReduceRight( [ -1, 1, 2 ], 100, mapper, reducer ); // $ExpectType number - mapReduceRight( [ -1, 1, 2 ], 0, mapper, reducer, {} ); // $ExpectType number -} - -// The function returns the accumulated value when provided an ndarray... -{ - const arr = array( [ 1, 2, 3, 4, 5, 6 ] ); - - mapReduceRight( arr, 0, mapper, reducer ); // $ExpectType number - mapReduceRight( arr, 100, mapper, reducer ); // $ExpectType number - mapReduceRight( arr, 0, mapper, reducer, {} ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not a collection or ndarray... -{ - mapReduceRight( 2, 0, mapper, reducer ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer ); // $ExpectError - - mapReduceRight( 2, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr1, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr2, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const arr1 = [ 1, 2, 3 ]; - - mapReduceRight(); // $ExpectError - mapReduceRight( arr1 ); // $ExpectError - mapReduceRight( arr1, 0 ); // $ExpectError - mapReduceRight( arr1, 0, mapper ); // $ExpectError - mapReduceRight( arr1, 0, mapper, reducer, {}, 3 ); // $ExpectError - - const arr2 = array( [ 1, 2, 3 ] ); - - mapReduceRight(); // $ExpectError - mapReduceRight( arr2 ); // $ExpectError - mapReduceRight( arr2, 0 ); // $ExpectError - mapReduceRight( arr2, 0, mapper ); // $ExpectError - mapReduceRight( arr2, 0, mapper, reducer, {}, 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 7474059..0000000 --- a/examples/index.js +++ /dev/null @@ -1,52 +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. -*/ - -'use strict'; - -var filledarrayBy = require( '@stdlib/array-filled-by' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ).factory; -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var mapReduceRight = require( './../lib' ); - -function fill( i ) { - var rand = discreteUniform( -10*(i+1), 10*(i+1) ); - return filledarrayBy( 10, 'generic', rand ); -} - -// Create a two-dimensional ndarray (i.e., a matrix): -var x = array( filledarrayBy( 10, 'generic', fill ), { - 'dtype': 'generic', - 'flatten': true -}); - -// Create an explicit unary function: -var f1 = naryFunction( abs, 1 ); - -// Create an explicit binary function: -var f2 = naryFunction( add, 2 ); - -// Compute the sum of absolute values: -var out = mapReduceRight( x, 0, f1, f2 ); - -console.log( 'x:' ); -console.log( x.data ); - -console.log( 'sum: %d', out ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index f3614c6..861830b 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; import { typedndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..f0681eb --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.2.2-esm/index.mjs";var o="throw";function a(a,m,l,j,f){if(!e(l))throw new TypeError(n("1VL3N",l));if(!e(j))throw new TypeError(n("1VL32",j));if(s(a))return function(r,s,e,t,i){var n,a,m,l,j,f,h,c,p,v,b;if(l=r.length,h=r.shape,n=r.data,c=r.strides,p=r.offset,a=r.order,j=r.accessors[0],f=r.ref,0===h.length)return t.call(i,s,e(j(n,p),0,f),0,f);for(m=s,b=l-1;b>=0;b--)v=d(h,c,p,a,b,o),m=t.call(i,m,e(j(n,v),b,f),b,f);return m}(t(a),m,l,j,f);if(r(a))return function(r,s,e,t,i){var n,d,o,a;for(n=r.data,d=r.accessors[0],o=s,a=n.length-1;a>=0;a--)o=t.call(i,o,e(d(n,a),a,n),a,n);return o}(i(a),m,l,j,f);throw new TypeError(n("1VLBH",a))}export{a as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..0897b2b --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/ndarray.js","../lib/main.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind';\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64';\n* import Complex64 from '@stdlib/complex-float32-ctor';\n* import realf from '@stdlib/complex-float32-real';\n* import imagf from '@stdlib/complex-float32-imag';\n* import cceil from '@stdlib/math-base-special-cceil';\n* import cadd from '@stdlib/complex-float64-base-add';\n* import naryFunction from '@stdlib/utils-nary-function';\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isFunction from '@stdlib/assert-is-function';\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object';\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndarrayFcn from './ndarray.js';\nimport arrayFcn from './array.js';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function';\n* import add from '@stdlib/math-base-ops-add';\n* import abs from '@stdlib/math-base-special-abs';\n* import array from '@stdlib/ndarray-array';\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '1VL3N', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '1VL32', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '1VLBH', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["MODE","mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","accessors","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;srBA2BA,IAAIA,EAAO,QC+DX,SAASC,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,GAAKK,EAAeR,GACnB,ODGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,UAAW,GAGnBZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAAGtB,GACtCc,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,CACR,CCnDSkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OC1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,UAAW,GAGnBf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,CACR,CDwBSqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,QAASP,GACvC"} \ No newline at end of file diff --git a/lib/array.js b/lib/array.js deleted file mode 100644 index 69c0a8c..0000000 --- a/lib/array.js +++ /dev/null @@ -1,83 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input array data -* @param {ArrayLikeObject} x.data - input array data -* @param {Array} x.accessors - input array accessors -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf[ idx ]; -* } -* -* // Create the input array object: -* var x = { -* 'data': [ 1, 2, 3, 4 ], -* 'accessors': [ getter ] -* }; -* -* // Compute the sum of squared values: -* var out = mapReduceRight( x, 0, square, sum ); -* // returns 30 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var get; - var acc; - var i; - - // Cache reference to the input data: - xbuf = x.data; - - // Cache the element accessor: - get = x.accessors[ 0 ]; - - // Iterate over each element... - acc = initial; - for ( i = xbuf.length-1; i >= 0; i-- ) { - acc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 522693e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +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. -*/ - -'use strict'; - -/** -* Perform a map-reduce operation against each element in an array while iterating from right to left and return the accumulated result. -* -* @module @stdlib/utils-map-reduce-right -* -* @example -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ - -// 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 4b227fe..0000000 --- a/lib/main.js +++ /dev/null @@ -1,110 +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. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ndarrayFcn = require( './ndarray.js' ); -var arrayFcn = require( './array.js' ); - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided the following arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided the following arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result of applying the mapping function against the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* @param {(ArrayLikeObject|ndarray)} arr - input array -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} [thisArg] - reduction function execution context -* @throws {TypeError} first argument must be an array-like object or an ndarray -* @throws {TypeError} third argument must be a function -* @throws {TypeError} fourth argument must be a function -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { - if ( !isFunction( mapper ) ) { - throw new TypeError( format( '1VL3N', mapper ) ); - } - if ( !isFunction( reducer ) ) { - throw new TypeError( format( '1VL32', reducer ) ); - } - if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like - return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - if ( isArrayLikeObject( arr ) ) { - return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - throw new TypeError( format( '1VLBH', arr ) ); -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/ndarray.js b/lib/ndarray.js deleted file mode 100644 index bcf9eb1..0000000 --- a/lib/ndarray.js +++ /dev/null @@ -1,155 +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. -*/ - -'use strict'; - -// MODULES // - -var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); - - -// VARIABLES // - -var MODE = 'throw'; - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input ndarray meta data -* @param {string} x.ref - reference to original input ndarray-like object -* @param {string} x.dtype - data type -* @param {Collection} x.data - data buffer -* @param {NonNegativeInteger} x.length - number of elements -* @param {NonNegativeIntegerArray} x.shape - dimensions -* @param {IntegerArray} x.strides - stride lengths -* @param {NonNegativeInteger} x.offset - index offset -* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) -* @param {Array} x.accessors - accessors for accessing data buffer elements -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var Complex64 = require( '@stdlib/complex-float32-ctor' ); -* var realf = require( '@stdlib/complex-float32-real' ); -* var imagf = require( '@stdlib/complex-float32-imag' ); -* var cceil = require( '@stdlib/math-base-special-cceil' ); -* var cadd = require( '@stdlib/complex-float64-base-add' ); -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* -* // Create a data buffer: -* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] ); -* -* // Define the shape of the input array: -* var shape = [ 2, 2 ]; -* -* // Define the array strides: -* var sx = [ 2, 1 ]; -* -* // Define the index offset: -* var ox = 0; -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf.get( idx ); -* } -* -* // Create the input ndarray-like object: -* var x = { -* 'ref': null, -* 'dtype': 'complex64', -* 'data': xbuf, -* 'length': 4, -* 'shape': shape, -* 'strides': sx, -* 'offset': ox, -* 'order': 'row-major', -* 'accessors': [ getter ] -* }; -* x.ref = x; -* -* // Compute the sum: -* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) ); -* -* var re = realf( v ); -* // returns 20.0 -* -* var im = imagf( v ); -* // returns 24.0 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var ordx; - var acc; - var len; - var get; - var ref; - var shx; - var sx; - var ox; - var ix; - var i; - - // Cache the total number of elements over which to iterate: - len = x.length; - - // Cache the input array shape: - shx = x.shape; - - // Cache reference to the input ndarray data buffer: - xbuf = x.data; - - // Cache reference to the stride array: - sx = x.strides; - - // Cache the index of the first indexed element: - ox = x.offset; - - // Cache the array order: - ordx = x.order; - - // Cache the element accessor: - get = x.accessors[ 0 ]; - - // Cache the reference to the original input array: - ref = x.ref; - - // Check for a zero-dimensional array... - if ( shx.length === 0 ) { - return reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len - } - // Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)... - acc = initial; - for ( i = len-1; i >= 0; i-- ) { - ix = vind2bind( shx, sx, ox, ordx, i, MODE ); - acc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/package.json b/package.json index e64fb59..3df9694 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Perform a single-pass map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.", "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/array-base-arraylike2object": "^0.2.1", - "@stdlib/assert-is-array-like-object": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-base-ndarraylike2object": "^0.2.2", - "@stdlib/ndarray-base-vind2bind": "^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-base-filled": "^0.2.2", - "@stdlib/array-complex64": "^0.3.0", - "@stdlib/array-filled-by": "^0.2.1", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/complex-float32-ctor": "^0.0.2", - "@stdlib/complex-float32-imag": "^0.1.1", - "@stdlib/complex-float32-real": "^0.1.1", - "@stdlib/complex-float64-base-add": "^0.1.0", - "@stdlib/math-base-assert-is-nan": "^0.2.2", - "@stdlib/math-base-ops-add": "^0.2.2", - "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/math-base-special-cceil": "^0.2.2", - "@stdlib/math-base-special-pow": "^0.3.0", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/random-base-discrete-uniform": "^0.2.1", - "@stdlib/utils-nary-function": "^0.2.2", - "@stdlib/utils-noop": "^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", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..b7d0354 --- /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/test.js b/test/test.js deleted file mode 100644 index 9280dce..0000000 --- a/test/test.js +++ /dev/null @@ -1,637 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var cadd = require( '@stdlib/complex-float64-base-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var cceil = require( '@stdlib/math-base-special-cceil' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var realf = require( '@stdlib/complex-float32-real' ); -var imagf = require( '@stdlib/complex-float32-imag' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var mapReduceRight = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapReduceRight, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a first argument which is either an array-like object or an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( value, 0, noop, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value, {} ); - }; - } -}); - -tape( 'the function performs a map-reduce operation for each element in an array (array-like object)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = [ -1, -2, -3 ]; - expected = 7; - actual = mapReduceRight( arr, 1, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (typed array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - expected = 7.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (complex number array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( cceil, 1 ); - f2 = naryFunction( cadd, 2 ); - - arr = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5 ] ); - expected = new Complex64( 12.0, 15.0 ); - actual = mapReduceRight( arr, new Complex64( 0.0, 0.0 ), f1, f2 ); - - t.strictEqual( realf( actual ), realf( expected ), 'returns expected value' ); - t.strictEqual( imagf( actual ), imagf( expected ), 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = array( [ -1.0, -2.0, -3.0, -4.0 ], { - 'dtype': 'generic' - }); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray; 0-dimensional)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = ndarray( 'generic', [ -10.0 ], [], [ 0 ], 0, 'row-major' ); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (array-like object)', function test( t ) { - var out = mapReduceRight( [], 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (ndarray)', function test( t ) { - var arr; - var out; - - arr = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 0, 2 ], [ 0, 2, 1 ], 0, 'row-major' ); - out = mapReduceRight( arr, 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function supports providing a `this` context (array-like object)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = [ -1.0, -2.0, -3.0 ]; - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function supports providing a `this` context (ndarray)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = array( [ -1.0, -2.0, -3.0 ], { - 'dtype': 'generic' - }); - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = array( [ 1, , , 4 ], { // eslint-disable-line no-sparse-arrays - 'dtype': 'generic' - }); - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); From 474c3c70a8772cc3578c72e8cbd0d8865a962e54 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Dec 2024 02:35:20 +0000 Subject: [PATCH 83/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index d95cde3..4b227fe 100644 --- a/lib/main.js +++ b/lib/main.js @@ -25,7 +25,7 @@ var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); var isFunction = require( '@stdlib/assert-is-function' ); var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ndarrayFcn = require( './ndarray.js' ); var arrayFcn = require( './array.js' ); @@ -90,10 +90,10 @@ var arrayFcn = require( './array.js' ); */ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( !isFunction( mapper ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) ); + throw new TypeError( format( '1VL3N', mapper ) ); } if ( !isFunction( reducer ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) ); + throw new TypeError( format( '1VL32', reducer ) ); } if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len @@ -101,7 +101,7 @@ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( isArrayLikeObject( arr ) ) { return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len } - throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) ); + throw new TypeError( format( '1VLBH', arr ) ); } diff --git a/package.json b/package.json index 5932b68..35a3b9c 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-ndarray-like": "^0.2.2", "@stdlib/ndarray-base-ndarraylike2object": "^0.2.2", "@stdlib/ndarray-base-vind2bind": "^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 a47b9bc4308dab7efe6e70ad77b0b9fa2ca68cc5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Dec 2024 03:21:20 +0000 Subject: [PATCH 84/91] Remove files --- index.d.ts | 257 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5104 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 861830b..0000000 --- a/index.d.ts +++ /dev/null @@ -1,257 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; -import { typedndarray } from '@stdlib/types/ndarray'; - -/** -* Callback invoked for each array element. -* -* @returns result -*/ -type Nullary = () => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @returns result -*/ -type Unary = ( value: T ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @returns result -*/ -type Binary = ( value: T, index: number ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Ternary = ( value: T, index: number, arr: typedndarray ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayTernary = ( value: T, index: number, arr: Collection ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Mapper = Nullary | Unary | Binary | Ternary; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayMapper = Nullary | Unary | Binary | ArrayTernary; - -/** -* Function applied against an accumulator. -* -* @returns accumulator value -*/ -type NullaryReducer = ( this: W ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @returns accumulator value -*/ -type UnaryReducer = ( this: W, accumulator: V ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @returns accumulator value -*/ -type BinaryReducer = ( this: W, accumulator: V, value: U ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @returns accumulator value -*/ -type TernaryReducer = ( this: W, accumulator: V, value: U, index: number ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type QuaternaryReducer = ( this: W, accumulator: V, value: U, index: number, arr: typedndarray ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayQuaternaryReducer = ( this: W, accumulator: V, value: U, index: number, arr: Collection ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type Reducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | QuaternaryReducer; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayReducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | ArrayQuaternaryReducer; - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 2 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -declare function mapReduceRight( arr: typedndarray, initial: V, mapper: Mapper, reducer: Reducer, thisArg?: ThisParameterType> ): V; - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -*/ -declare function mapReduceRight( arr: Collection, initial: V, mapper: ArrayMapper, reducer: ArrayReducer, thisArg?: ThisParameterType> ): V; - - -// EXPORTS // - -export = mapReduceRight; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index f0681eb..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.2.2-esm/index.mjs";var o="throw";function a(a,m,l,j,f){if(!e(l))throw new TypeError(n("1VL3N",l));if(!e(j))throw new TypeError(n("1VL32",j));if(s(a))return function(r,s,e,t,i){var n,a,m,l,j,f,h,c,p,v,b;if(l=r.length,h=r.shape,n=r.data,c=r.strides,p=r.offset,a=r.order,j=r.accessors[0],f=r.ref,0===h.length)return t.call(i,s,e(j(n,p),0,f),0,f);for(m=s,b=l-1;b>=0;b--)v=d(h,c,p,a,b,o),m=t.call(i,m,e(j(n,v),b,f),b,f);return m}(t(a),m,l,j,f);if(r(a))return function(r,s,e,t,i){var n,d,o,a;for(n=r.data,d=r.accessors[0],o=s,a=n.length-1;a>=0;a--)o=t.call(i,o,e(d(n,a),a,n),a,n);return o}(i(a),m,l,j,f);throw new TypeError(n("1VLBH",a))}export{a as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 0897b2b..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/ndarray.js","../lib/main.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind';\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64';\n* import Complex64 from '@stdlib/complex-float32-ctor';\n* import realf from '@stdlib/complex-float32-real';\n* import imagf from '@stdlib/complex-float32-imag';\n* import cceil from '@stdlib/math-base-special-cceil';\n* import cadd from '@stdlib/complex-float64-base-add';\n* import naryFunction from '@stdlib/utils-nary-function';\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isFunction from '@stdlib/assert-is-function';\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object';\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndarrayFcn from './ndarray.js';\nimport arrayFcn from './array.js';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function';\n* import add from '@stdlib/math-base-ops-add';\n* import abs from '@stdlib/math-base-special-abs';\n* import array from '@stdlib/ndarray-array';\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '1VL3N', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '1VL32', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '1VLBH', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["MODE","mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","accessors","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;srBA2BA,IAAIA,EAAO,QC+DX,SAASC,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,GAAKK,EAAeR,GACnB,ODGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,UAAW,GAGnBZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAAGtB,GACtCc,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,CACR,CCnDSkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OC1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,UAAW,GAGnBf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,CACR,CDwBSqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,QAASP,GACvC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index b7d0354..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 23cd148470ff071af29de95022cacf22d6019b4f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 30 Dec 2024 03:22:00 +0000 Subject: [PATCH 85/91] 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 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 167 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 71 +- SECURITY.md | 5 - benchmark/benchmark.array.js | 98 - benchmark/benchmark.ndarray.js | 109 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 9 - dist/index.js.map | 7 - docs/repl.txt | 65 - docs/types/test.ts | 184 - examples/index.js | 52 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/array.js | 83 - lib/index.js | 65 - lib/main.js | 110 - lib/ndarray.js | 155 - package.json | 77 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 637 --- 47 files changed, 4881 insertions(+), 5235 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.array.js delete mode 100644 benchmark/benchmark.ndarray.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/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/array.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/ndarray.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0779e8a..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 = 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 5dfccf0..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-12-30T02:19:48.404Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 3b4c7b4..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/utils/map-reduce-right) 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 f23359f..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/utils/map-reduce-right) 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 1308146..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: '21 21 * * 4' - - # 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 + + ```
@@ -281,7 +272,7 @@ console.log( 'sum: %d', out ); ## 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]. @@ -344,19 +335,19 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/utils-map-reduce-right/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64 +[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64/tree/esm -[@stdlib/array/complex128]: https://github.com/stdlib-js/array-complex128 +[@stdlib/array/complex128]: https://github.com/stdlib-js/array-complex128/tree/esm -[@stdlib/utils/map-right]: https://github.com/stdlib-js/utils-map-right +[@stdlib/utils/map-right]: https://github.com/stdlib-js/utils-map-right/tree/esm -[@stdlib/utils/map-reduce]: https://github.com/stdlib-js/utils-map-reduce +[@stdlib/utils/map-reduce]: https://github.com/stdlib-js/utils-map-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/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.array.js b/benchmark/benchmark.array.js deleted file mode 100644 index da29c82..0000000 --- a/benchmark/benchmark.array.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = filled( -3.0, len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::array:len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.ndarray.js b/benchmark/benchmark.ndarray.js deleted file mode 100644 index 7806caa..0000000 --- a/benchmark/benchmark.ndarray.js +++ /dev/null @@ -1,109 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var xbuf; - var opts; - var x; - - xbuf = filled( -3.0, len ); - - opts = { - 'dtype': 'generic' - }; - x = array( xbuf, opts ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::ndarray:len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0816c5f..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/utils/map-reduce-right" -%% click B href "https://github.com/stdlib-js/utils-map-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-map-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-map-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-map-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-map-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/map-reduce-right -[production-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-map-reduce-right/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-map-reduce-right/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-map-reduce-right/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 63ea99a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import mapReduceRight from '../docs/types/index'; -export = mapReduceRight; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 3180c8b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,9 +0,0 @@ -"use strict";var g=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var q=g(function(H,m){ -var E=require('@stdlib/ndarray-base-vind2bind/dist'),T="throw";function p(r,e,a,t,s){var i,v,n,u,f,c,l,y,d,b,o;if(u=r.length,l=r.shape,i=r.data,y=r.strides,d=r.offset,v=r.order,f=r.accessors[0],c=r.ref,l.length===0)return t.call(s,e,a(f(i,d),0,c),0,c);for(n=e,o=u-1;o>=0;o--)b=E(l,y,d,v,o,T),n=t.call(s,n,a(f(i,b),o,c),o,c);return n}m.exports=p -});var R=g(function(I,w){ -function x(r,e,a,t,s){var i,v,n,u;for(i=r.data,v=r.accessors[0],n=e,u=i.length-1;u>=0;u--)n=t.call(s,n,a(v(i,u),u,i),u,i);return n}w.exports=x -});var j=g(function(J,F){ -var V=require('@stdlib/assert-is-array-like-object/dist'),L=require('@stdlib/assert-is-ndarray-like/dist'),k=require('@stdlib/assert-is-function/dist'),O=require('@stdlib/ndarray-base-ndarraylike2object/dist'),D=require('@stdlib/array-base-arraylike2object/dist'),h=require('@stdlib/error-tools-fmtprodmsg/dist'),M=q(),z=R();function B(r,e,a,t,s){if(!k(a))throw new TypeError(h('1VL3N',a));if(!k(t))throw new TypeError(h('1VL32',t));if(L(r))return M(O(r),e,a,t,s);if(V(r))return z(D(r),e,a,t,s);throw new TypeError(h('1VLBH',r))}F.exports=B -});var C=j();module.exports=C; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 17c2d18..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/ndarray.js", "../lib/array.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* var Complex64Array = require( '@stdlib/array-complex64' );\n* var Complex64 = require( '@stdlib/complex-float32-ctor' );\n* var realf = require( '@stdlib/complex-float32-real' );\n* var imagf = require( '@stdlib/complex-float32-imag' );\n* var cceil = require( '@stdlib/math-base-special-cceil' );\n* var cadd = require( '@stdlib/complex-float64-base-add' );\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar format = require( '@stdlib/string-format' );\nvar ndarrayFcn = require( './ndarray.js' );\nvar arrayFcn = require( './array.js' );\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/math-base-ops-add' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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* Perform a map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.\n*\n* @module @stdlib/utils-map-reduce-right\n*\n* @example\n* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' );\n*\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, sum );\n* // returns 30\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/math-base-ops-add' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\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,EAAY,QAAS,gCAAiC,EAKtDC,EAAO,QA0EX,SAASC,EAAgBC,EAAGC,EAASC,EAAQC,EAASC,EAAU,CAC/D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMR,EAAE,OAGRW,EAAMX,EAAE,MAGRK,EAAOL,EAAE,KAGTY,EAAKZ,EAAE,QAGPa,EAAKb,EAAE,OAGPM,EAAON,EAAE,MAGTS,EAAMT,EAAE,UAAW,CAAE,EAGrBU,EAAMV,EAAE,IAGHW,EAAI,SAAW,EACnB,OAAOR,EAAQ,KAAMC,EAASH,EAASC,EAAQO,EAAKJ,EAAMQ,CAAG,EAAG,EAAGH,CAAI,EAAG,EAAGA,CAAI,EAIlF,IADAH,EAAMN,EACAc,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKjB,EAAWc,EAAKC,EAAIC,EAAIP,EAAMS,EAAGjB,CAAK,EAC3CS,EAAMJ,EAAQ,KAAMC,EAASG,EAAKL,EAAQO,EAAKJ,EAAMS,CAAG,EAAGC,EAAGL,CAAI,EAAGK,EAAGL,CAAI,EAE7E,OAAOH,CACR,CAKAX,EAAO,QAAUG,IC1JjB,IAAAiB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA2DA,SAASC,EAAgBC,EAAGC,EAASC,EAAQC,EAASC,EAAU,CAC/D,IAAIC,EACAC,EACAC,EACAC,EAUJ,IAPAH,EAAOL,EAAE,KAGTM,EAAMN,EAAE,UAAW,CAAE,EAGrBO,EAAMN,EACAO,EAAIH,EAAK,OAAO,EAAGG,GAAK,EAAGA,IAChCD,EAAMJ,EAAQ,KAAMC,EAASG,EAAKL,EAAQI,EAAKD,EAAMG,CAAE,EAAGA,EAAGH,CAAK,EAAGG,EAAGH,CAAK,EAE9E,OAAOE,CACR,CAKAT,EAAO,QAAUC,IClFjB,IAAAU,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAoB,QAAS,qCAAsC,EACnEC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,4BAA6B,EACnDC,EAAqB,QAAS,yCAA0C,EACxEC,EAAmB,QAAS,qCAAsC,EAClEC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAW,IA6Df,SAASC,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,EAAU,CACjE,GAAK,CAACX,EAAYS,CAAO,EACxB,MAAM,IAAI,UAAWN,EAAQ,oEAAqEM,CAAO,CAAE,EAE5G,GAAK,CAACT,EAAYU,CAAQ,EACzB,MAAM,IAAI,UAAWP,EAAQ,qEAAsEO,CAAQ,CAAE,EAE9G,GAAKX,EAAeQ,CAAI,EACvB,OAAOH,EAAYH,EAAoBM,CAAI,EAAGC,EAASC,EAAQC,EAASC,CAAQ,EAEjF,GAAKb,EAAmBS,CAAI,EAC3B,OAAOF,EAAUH,EAAkBK,CAAI,EAAGC,EAASC,EAAQC,EAASC,CAAQ,EAE7E,MAAM,IAAI,UAAWR,EAAQ,4FAA6FI,CAAI,CAAE,CACjI,CAKAV,EAAO,QAAUS,IClDjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_ndarray", "__commonJSMin", "exports", "module", "vind2bind", "MODE", "mapReduceRight", "x", "initial", "mapper", "reducer", "thisArg", "xbuf", "ordx", "acc", "len", "get", "ref", "shx", "sx", "ox", "ix", "i", "require_array", "__commonJSMin", "exports", "module", "mapReduceRight", "x", "initial", "mapper", "reducer", "thisArg", "xbuf", "get", "acc", "i", "require_main", "__commonJSMin", "exports", "module", "isArrayLikeObject", "isndarrayLike", "isFunction", "ndarraylike2object", "arraylike2object", "format", "ndarrayFcn", "arrayFcn", "mapReduceRight", "arr", "initial", "mapper", "reducer", "thisArg", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index b580e87..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, initial, mapper, reducer[, thisArg] ) - Performs a map-reduce operation for each element in an array while iterating - from right to left and returns the accumulated result. - - When invoked, the mapping function is provided three arguments: - - - value: array element. - - index: element index. - - arr: input array. - - When invoked, the reducing function is provided four arguments: - - - accumulator: accumulated value. - - value: result after applying the mapping function to the current array - element. - - index: element index. - - arr: input array. - - If provided an empty array, the function returns the initial value. - - When provided an ndarray, the function performs a single-pass map-reduce - operation over the entire input ndarray (i.e., higher-order ndarray - dimensions are flattened to a single-dimension). - - Parameters - ---------- - arr: ArrayLikeObject|ndarray - Input array. - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - mapper: Function - Mapping function. - - reducer: Function - Reducing function. - - thisArg: any (optional) - Execution context for the reducing function. - - Returns - ------- - out: any - Accumulated result. - - Examples - -------- - // array-like object: - > var f1 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/special/abs}}, 1 ); - > var f2 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/ops/add}}, 2 ); - > var arr = [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0 ]; - > var out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - // ndarray: - > arr = {{alias:@stdlib/ndarray/array}}( arr, { 'shape': [ 2, 3 ] } ); - > out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 58a6cae..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,184 +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. -*/ - -import array = require( '@stdlib/ndarray-array' ); -import mapReduceRight = require( './index' ); - -/** -* Mapping function. -* -* @param value - array element -* @returns result -*/ -function mapper( value: number ): number { - return value; -} - -/** -* Reducing function. -* -* @param acc - accumulated value -* @param value - array element -* @returns result -*/ -function reducer( acc: number, value: number ): number { - return acc + value; -} - - -// TESTS // - -// The function returns the accumulated value when provided a collection... -{ - mapReduceRight( [ 0, 1, 1, NaN, 2 ], 0, mapper, reducer ); // $ExpectType number - mapReduceRight( [ -1, 1, 2 ], 100, mapper, reducer ); // $ExpectType number - mapReduceRight( [ -1, 1, 2 ], 0, mapper, reducer, {} ); // $ExpectType number -} - -// The function returns the accumulated value when provided an ndarray... -{ - const arr = array( [ 1, 2, 3, 4, 5, 6 ] ); - - mapReduceRight( arr, 0, mapper, reducer ); // $ExpectType number - mapReduceRight( arr, 100, mapper, reducer ); // $ExpectType number - mapReduceRight( arr, 0, mapper, reducer, {} ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not a collection or ndarray... -{ - mapReduceRight( 2, 0, mapper, reducer ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer ); // $ExpectError - - mapReduceRight( 2, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr1, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr2, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const arr1 = [ 1, 2, 3 ]; - - mapReduceRight(); // $ExpectError - mapReduceRight( arr1 ); // $ExpectError - mapReduceRight( arr1, 0 ); // $ExpectError - mapReduceRight( arr1, 0, mapper ); // $ExpectError - mapReduceRight( arr1, 0, mapper, reducer, {}, 3 ); // $ExpectError - - const arr2 = array( [ 1, 2, 3 ] ); - - mapReduceRight(); // $ExpectError - mapReduceRight( arr2 ); // $ExpectError - mapReduceRight( arr2, 0 ); // $ExpectError - mapReduceRight( arr2, 0, mapper ); // $ExpectError - mapReduceRight( arr2, 0, mapper, reducer, {}, 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 7474059..0000000 --- a/examples/index.js +++ /dev/null @@ -1,52 +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. -*/ - -'use strict'; - -var filledarrayBy = require( '@stdlib/array-filled-by' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ).factory; -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var mapReduceRight = require( './../lib' ); - -function fill( i ) { - var rand = discreteUniform( -10*(i+1), 10*(i+1) ); - return filledarrayBy( 10, 'generic', rand ); -} - -// Create a two-dimensional ndarray (i.e., a matrix): -var x = array( filledarrayBy( 10, 'generic', fill ), { - 'dtype': 'generic', - 'flatten': true -}); - -// Create an explicit unary function: -var f1 = naryFunction( abs, 1 ); - -// Create an explicit binary function: -var f2 = naryFunction( add, 2 ); - -// Compute the sum of absolute values: -var out = mapReduceRight( x, 0, f1, f2 ); - -console.log( 'x:' ); -console.log( x.data ); - -console.log( 'sum: %d', out ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index f3614c6..861830b 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; import { typedndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..f0681eb --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.2.2-esm/index.mjs";var o="throw";function a(a,m,l,j,f){if(!e(l))throw new TypeError(n("1VL3N",l));if(!e(j))throw new TypeError(n("1VL32",j));if(s(a))return function(r,s,e,t,i){var n,a,m,l,j,f,h,c,p,v,b;if(l=r.length,h=r.shape,n=r.data,c=r.strides,p=r.offset,a=r.order,j=r.accessors[0],f=r.ref,0===h.length)return t.call(i,s,e(j(n,p),0,f),0,f);for(m=s,b=l-1;b>=0;b--)v=d(h,c,p,a,b,o),m=t.call(i,m,e(j(n,v),b,f),b,f);return m}(t(a),m,l,j,f);if(r(a))return function(r,s,e,t,i){var n,d,o,a;for(n=r.data,d=r.accessors[0],o=s,a=n.length-1;a>=0;a--)o=t.call(i,o,e(d(n,a),a,n),a,n);return o}(i(a),m,l,j,f);throw new TypeError(n("1VLBH",a))}export{a as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..0897b2b --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/ndarray.js","../lib/main.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind';\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64';\n* import Complex64 from '@stdlib/complex-float32-ctor';\n* import realf from '@stdlib/complex-float32-real';\n* import imagf from '@stdlib/complex-float32-imag';\n* import cceil from '@stdlib/math-base-special-cceil';\n* import cadd from '@stdlib/complex-float64-base-add';\n* import naryFunction from '@stdlib/utils-nary-function';\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isFunction from '@stdlib/assert-is-function';\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object';\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndarrayFcn from './ndarray.js';\nimport arrayFcn from './array.js';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function';\n* import add from '@stdlib/math-base-ops-add';\n* import abs from '@stdlib/math-base-special-abs';\n* import array from '@stdlib/ndarray-array';\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '1VL3N', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '1VL32', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '1VLBH', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["MODE","mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","accessors","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;srBA2BA,IAAIA,EAAO,QC+DX,SAASC,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,GAAKK,EAAeR,GACnB,ODGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,UAAW,GAGnBZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAAGtB,GACtCc,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,CACR,CCnDSkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OC1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,UAAW,GAGnBf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,CACR,CDwBSqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,QAASP,GACvC"} \ No newline at end of file diff --git a/lib/array.js b/lib/array.js deleted file mode 100644 index 69c0a8c..0000000 --- a/lib/array.js +++ /dev/null @@ -1,83 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input array data -* @param {ArrayLikeObject} x.data - input array data -* @param {Array} x.accessors - input array accessors -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf[ idx ]; -* } -* -* // Create the input array object: -* var x = { -* 'data': [ 1, 2, 3, 4 ], -* 'accessors': [ getter ] -* }; -* -* // Compute the sum of squared values: -* var out = mapReduceRight( x, 0, square, sum ); -* // returns 30 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var get; - var acc; - var i; - - // Cache reference to the input data: - xbuf = x.data; - - // Cache the element accessor: - get = x.accessors[ 0 ]; - - // Iterate over each element... - acc = initial; - for ( i = xbuf.length-1; i >= 0; i-- ) { - acc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 522693e..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +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. -*/ - -'use strict'; - -/** -* Perform a map-reduce operation against each element in an array while iterating from right to left and return the accumulated result. -* -* @module @stdlib/utils-map-reduce-right -* -* @example -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ - -// 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 4b227fe..0000000 --- a/lib/main.js +++ /dev/null @@ -1,110 +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. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ndarrayFcn = require( './ndarray.js' ); -var arrayFcn = require( './array.js' ); - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided the following arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided the following arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result of applying the mapping function against the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* @param {(ArrayLikeObject|ndarray)} arr - input array -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} [thisArg] - reduction function execution context -* @throws {TypeError} first argument must be an array-like object or an ndarray -* @throws {TypeError} third argument must be a function -* @throws {TypeError} fourth argument must be a function -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { - if ( !isFunction( mapper ) ) { - throw new TypeError( format( '1VL3N', mapper ) ); - } - if ( !isFunction( reducer ) ) { - throw new TypeError( format( '1VL32', reducer ) ); - } - if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like - return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - if ( isArrayLikeObject( arr ) ) { - return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - throw new TypeError( format( '1VLBH', arr ) ); -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/ndarray.js b/lib/ndarray.js deleted file mode 100644 index bcf9eb1..0000000 --- a/lib/ndarray.js +++ /dev/null @@ -1,155 +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. -*/ - -'use strict'; - -// MODULES // - -var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); - - -// VARIABLES // - -var MODE = 'throw'; - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input ndarray meta data -* @param {string} x.ref - reference to original input ndarray-like object -* @param {string} x.dtype - data type -* @param {Collection} x.data - data buffer -* @param {NonNegativeInteger} x.length - number of elements -* @param {NonNegativeIntegerArray} x.shape - dimensions -* @param {IntegerArray} x.strides - stride lengths -* @param {NonNegativeInteger} x.offset - index offset -* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) -* @param {Array} x.accessors - accessors for accessing data buffer elements -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var Complex64 = require( '@stdlib/complex-float32-ctor' ); -* var realf = require( '@stdlib/complex-float32-real' ); -* var imagf = require( '@stdlib/complex-float32-imag' ); -* var cceil = require( '@stdlib/math-base-special-cceil' ); -* var cadd = require( '@stdlib/complex-float64-base-add' ); -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* -* // Create a data buffer: -* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] ); -* -* // Define the shape of the input array: -* var shape = [ 2, 2 ]; -* -* // Define the array strides: -* var sx = [ 2, 1 ]; -* -* // Define the index offset: -* var ox = 0; -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf.get( idx ); -* } -* -* // Create the input ndarray-like object: -* var x = { -* 'ref': null, -* 'dtype': 'complex64', -* 'data': xbuf, -* 'length': 4, -* 'shape': shape, -* 'strides': sx, -* 'offset': ox, -* 'order': 'row-major', -* 'accessors': [ getter ] -* }; -* x.ref = x; -* -* // Compute the sum: -* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) ); -* -* var re = realf( v ); -* // returns 20.0 -* -* var im = imagf( v ); -* // returns 24.0 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var ordx; - var acc; - var len; - var get; - var ref; - var shx; - var sx; - var ox; - var ix; - var i; - - // Cache the total number of elements over which to iterate: - len = x.length; - - // Cache the input array shape: - shx = x.shape; - - // Cache reference to the input ndarray data buffer: - xbuf = x.data; - - // Cache reference to the stride array: - sx = x.strides; - - // Cache the index of the first indexed element: - ox = x.offset; - - // Cache the array order: - ordx = x.order; - - // Cache the element accessor: - get = x.accessors[ 0 ]; - - // Cache the reference to the original input array: - ref = x.ref; - - // Check for a zero-dimensional array... - if ( shx.length === 0 ) { - return reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len - } - // Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)... - acc = initial; - for ( i = len-1; i >= 0; i-- ) { - ix = vind2bind( shx, sx, ox, ordx, i, MODE ); - acc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/package.json b/package.json index 35a3b9c..3df9694 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Perform a single-pass map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.", "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/array-base-arraylike2object": "^0.2.1", - "@stdlib/assert-is-array-like-object": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-base-ndarraylike2object": "^0.2.2", - "@stdlib/ndarray-base-vind2bind": "^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-base-filled": "^0.2.2", - "@stdlib/array-complex64": "^0.3.0", - "@stdlib/array-filled-by": "^0.2.1", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/complex-float32-ctor": "^0.0.2", - "@stdlib/complex-float32-imag": "^0.1.1", - "@stdlib/complex-float32-real": "^0.1.1", - "@stdlib/complex-float64-base-add": "^0.1.0", - "@stdlib/math-base-assert-is-nan": "^0.2.2", - "@stdlib/math-base-ops-add": "^0.2.2", - "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/math-base-special-cceil": "^0.2.2", - "@stdlib/math-base-special-pow": "^0.3.0", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/random-base-discrete-uniform": "^0.2.1", - "@stdlib/utils-nary-function": "^0.2.2", - "@stdlib/utils-noop": "^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", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..b7d0354 --- /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/test.js b/test/test.js deleted file mode 100644 index 9280dce..0000000 --- a/test/test.js +++ /dev/null @@ -1,637 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/math-base-ops-add' ); -var cadd = require( '@stdlib/complex-float64-base-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var cceil = require( '@stdlib/math-base-special-cceil' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var realf = require( '@stdlib/complex-float32-real' ); -var imagf = require( '@stdlib/complex-float32-imag' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var mapReduceRight = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapReduceRight, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a first argument which is either an array-like object or an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( value, 0, noop, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value, {} ); - }; - } -}); - -tape( 'the function performs a map-reduce operation for each element in an array (array-like object)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = [ -1, -2, -3 ]; - expected = 7; - actual = mapReduceRight( arr, 1, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (typed array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - expected = 7.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (complex number array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( cceil, 1 ); - f2 = naryFunction( cadd, 2 ); - - arr = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5 ] ); - expected = new Complex64( 12.0, 15.0 ); - actual = mapReduceRight( arr, new Complex64( 0.0, 0.0 ), f1, f2 ); - - t.strictEqual( realf( actual ), realf( expected ), 'returns expected value' ); - t.strictEqual( imagf( actual ), imagf( expected ), 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = array( [ -1.0, -2.0, -3.0, -4.0 ], { - 'dtype': 'generic' - }); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray; 0-dimensional)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = ndarray( 'generic', [ -10.0 ], [], [ 0 ], 0, 'row-major' ); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (array-like object)', function test( t ) { - var out = mapReduceRight( [], 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (ndarray)', function test( t ) { - var arr; - var out; - - arr = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 0, 2 ], [ 0, 2, 1 ], 0, 'row-major' ); - out = mapReduceRight( arr, 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function supports providing a `this` context (array-like object)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = [ -1.0, -2.0, -3.0 ]; - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function supports providing a `this` context (ndarray)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = array( [ -1.0, -2.0, -3.0 ], { - 'dtype': 'generic' - }); - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = array( [ 1, , , 4 ], { // eslint-disable-line no-sparse-arrays - 'dtype': 'generic' - }); - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); From 1cf1a42355b275689a223b855b34812053d4d33a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 7 Apr 2025 00:35:40 +0000 Subject: [PATCH 86/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index c281dc6..c7692a8 100644 --- a/lib/main.js +++ b/lib/main.js @@ -25,7 +25,7 @@ var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); var isFunction = require( '@stdlib/assert-is-function' ); var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ndarrayFcn = require( './ndarray.js' ); var arrayFcn = require( './array.js' ); @@ -90,10 +90,10 @@ var arrayFcn = require( './array.js' ); */ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( !isFunction( mapper ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) ); + throw new TypeError( format( '1VL3N', mapper ) ); } if ( !isFunction( reducer ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) ); + throw new TypeError( format( '1VL32', reducer ) ); } if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len @@ -101,7 +101,7 @@ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( isArrayLikeObject( arr ) ) { return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len } - throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) ); + throw new TypeError( format( '1VLBH', arr ) ); } diff --git a/package.json b/package.json index bd01cf6..d39f6e2 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-ndarray-like": "^0.2.2", "@stdlib/ndarray-base-ndarraylike2object": "^0.2.2", "@stdlib/ndarray-base-vind2bind": "^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 267dc86b1fb1bec31d6bc32a713acad1248d4028 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 7 Apr 2025 00:42:21 +0000 Subject: [PATCH 87/91] Remove files --- index.d.ts | 257 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5104 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 861830b..0000000 --- a/index.d.ts +++ /dev/null @@ -1,257 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; -import { typedndarray } from '@stdlib/types/ndarray'; - -/** -* Callback invoked for each array element. -* -* @returns result -*/ -type Nullary = () => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @returns result -*/ -type Unary = ( value: T ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @returns result -*/ -type Binary = ( value: T, index: number ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Ternary = ( value: T, index: number, arr: typedndarray ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayTernary = ( value: T, index: number, arr: Collection ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Mapper = Nullary | Unary | Binary | Ternary; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayMapper = Nullary | Unary | Binary | ArrayTernary; - -/** -* Function applied against an accumulator. -* -* @returns accumulator value -*/ -type NullaryReducer = ( this: W ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @returns accumulator value -*/ -type UnaryReducer = ( this: W, accumulator: V ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @returns accumulator value -*/ -type BinaryReducer = ( this: W, accumulator: V, value: U ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @returns accumulator value -*/ -type TernaryReducer = ( this: W, accumulator: V, value: U, index: number ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type QuaternaryReducer = ( this: W, accumulator: V, value: U, index: number, arr: typedndarray ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayQuaternaryReducer = ( this: W, accumulator: V, value: U, index: number, arr: Collection ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type Reducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | QuaternaryReducer; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayReducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | ArrayQuaternaryReducer; - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var add = require( '@stdlib/math-base-ops-add' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 2 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -declare function mapReduceRight( arr: typedndarray, initial: V, mapper: Mapper, reducer: Reducer, thisArg?: ThisParameterType> ): V; - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -*/ -declare function mapReduceRight( arr: Collection, initial: V, mapper: ArrayMapper, reducer: ArrayReducer, thisArg?: ThisParameterType> ): V; - - -// EXPORTS // - -export = mapReduceRight; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index f0681eb..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.2.2-esm/index.mjs";var o="throw";function a(a,m,l,j,f){if(!e(l))throw new TypeError(n("1VL3N",l));if(!e(j))throw new TypeError(n("1VL32",j));if(s(a))return function(r,s,e,t,i){var n,a,m,l,j,f,h,c,p,v,b;if(l=r.length,h=r.shape,n=r.data,c=r.strides,p=r.offset,a=r.order,j=r.accessors[0],f=r.ref,0===h.length)return t.call(i,s,e(j(n,p),0,f),0,f);for(m=s,b=l-1;b>=0;b--)v=d(h,c,p,a,b,o),m=t.call(i,m,e(j(n,v),b,f),b,f);return m}(t(a),m,l,j,f);if(r(a))return function(r,s,e,t,i){var n,d,o,a;for(n=r.data,d=r.accessors[0],o=s,a=n.length-1;a>=0;a--)o=t.call(i,o,e(d(n,a),a,n),a,n);return o}(i(a),m,l,j,f);throw new TypeError(n("1VLBH",a))}export{a as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 0897b2b..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/ndarray.js","../lib/main.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind';\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64';\n* import Complex64 from '@stdlib/complex-float32-ctor';\n* import realf from '@stdlib/complex-float32-real';\n* import imagf from '@stdlib/complex-float32-imag';\n* import cceil from '@stdlib/math-base-special-cceil';\n* import cadd from '@stdlib/complex-float64-base-add';\n* import naryFunction from '@stdlib/utils-nary-function';\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isFunction from '@stdlib/assert-is-function';\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object';\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndarrayFcn from './ndarray.js';\nimport arrayFcn from './array.js';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function';\n* import add from '@stdlib/math-base-ops-add';\n* import abs from '@stdlib/math-base-special-abs';\n* import array from '@stdlib/ndarray-array';\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '1VL3N', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '1VL32', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '1VLBH', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["MODE","mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","accessors","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;srBA2BA,IAAIA,EAAO,QC+DX,SAASC,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,GAAKK,EAAeR,GACnB,ODGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,UAAW,GAGnBZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAAGtB,GACtCc,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,CACR,CCnDSkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OC1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,UAAW,GAGnBf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,CACR,CDwBSqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,QAASP,GACvC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index b7d0354..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 5573bce86231f627e8b5f8cd91cb17e01ab3613a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 7 Apr 2025 00:42:53 +0000 Subject: [PATCH 88/91] 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 | 169 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 71 +- SECURITY.md | 5 - benchmark/benchmark.array.js | 98 - benchmark/benchmark.ndarray.js | 109 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 9 - dist/index.js.map | 7 - docs/repl.txt | 65 - docs/types/test.ts | 184 - examples/index.js | 52 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/array.js | 83 - lib/index.js | 65 - lib/main.js | 110 - lib/ndarray.js | 155 - package.json | 77 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 637 --- 47 files changed, 4881 insertions(+), 5240 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.array.js delete mode 100644 benchmark/benchmark.ndarray.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/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/array.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/ndarray.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.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 fce2a22..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-04-07T00:34:05.128Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6267240..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/utils/map-reduce-right) 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 f23359f..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/utils/map-reduce-right) 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 1308146..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: '21 21 * * 4' - - # 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 + + ```
@@ -281,7 +272,7 @@ console.log( 'sum: %d', out ); ## 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]. @@ -344,19 +335,19 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/utils-map-reduce-right/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64 +[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64/tree/esm -[@stdlib/array/complex128]: https://github.com/stdlib-js/array-complex128 +[@stdlib/array/complex128]: https://github.com/stdlib-js/array-complex128/tree/esm -[@stdlib/utils/map-right]: https://github.com/stdlib-js/utils-map-right +[@stdlib/utils/map-right]: https://github.com/stdlib-js/utils-map-right/tree/esm -[@stdlib/utils/map-reduce]: https://github.com/stdlib-js/utils-map-reduce +[@stdlib/utils/map-reduce]: https://github.com/stdlib-js/utils-map-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/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.array.js b/benchmark/benchmark.array.js deleted file mode 100644 index 0dca22a..0000000 --- a/benchmark/benchmark.array.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/number-float64-base-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = filled( -3.0, len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::array:len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.ndarray.js b/benchmark/benchmark.ndarray.js deleted file mode 100644 index 68f754c..0000000 --- a/benchmark/benchmark.ndarray.js +++ /dev/null @@ -1,109 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/number-float64-base-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var xbuf; - var opts; - var x; - - xbuf = filled( -3.0, len ); - - opts = { - 'dtype': 'generic' - }; - x = array( xbuf, opts ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::ndarray:len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0816c5f..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/utils/map-reduce-right" -%% click B href "https://github.com/stdlib-js/utils-map-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-map-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-map-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-map-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-map-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/map-reduce-right -[production-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-map-reduce-right/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-map-reduce-right/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-map-reduce-right/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 63ea99a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import mapReduceRight from '../docs/types/index'; -export = mapReduceRight; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 3180c8b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,9 +0,0 @@ -"use strict";var g=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var q=g(function(H,m){ -var E=require('@stdlib/ndarray-base-vind2bind/dist'),T="throw";function p(r,e,a,t,s){var i,v,n,u,f,c,l,y,d,b,o;if(u=r.length,l=r.shape,i=r.data,y=r.strides,d=r.offset,v=r.order,f=r.accessors[0],c=r.ref,l.length===0)return t.call(s,e,a(f(i,d),0,c),0,c);for(n=e,o=u-1;o>=0;o--)b=E(l,y,d,v,o,T),n=t.call(s,n,a(f(i,b),o,c),o,c);return n}m.exports=p -});var R=g(function(I,w){ -function x(r,e,a,t,s){var i,v,n,u;for(i=r.data,v=r.accessors[0],n=e,u=i.length-1;u>=0;u--)n=t.call(s,n,a(v(i,u),u,i),u,i);return n}w.exports=x -});var j=g(function(J,F){ -var V=require('@stdlib/assert-is-array-like-object/dist'),L=require('@stdlib/assert-is-ndarray-like/dist'),k=require('@stdlib/assert-is-function/dist'),O=require('@stdlib/ndarray-base-ndarraylike2object/dist'),D=require('@stdlib/array-base-arraylike2object/dist'),h=require('@stdlib/error-tools-fmtprodmsg/dist'),M=q(),z=R();function B(r,e,a,t,s){if(!k(a))throw new TypeError(h('1VL3N',a));if(!k(t))throw new TypeError(h('1VL32',t));if(L(r))return M(O(r),e,a,t,s);if(V(r))return z(D(r),e,a,t,s);throw new TypeError(h('1VLBH',r))}F.exports=B -});var C=j();module.exports=C; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 5ea9971..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/ndarray.js", "../lib/array.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* var Complex64Array = require( '@stdlib/array-complex64' );\n* var Complex64 = require( '@stdlib/complex-float32-ctor' );\n* var realf = require( '@stdlib/complex-float32-real' );\n* var imagf = require( '@stdlib/complex-float32-imag' );\n* var cceil = require( '@stdlib/math-base-special-cceil' );\n* var cadd = require( '@stdlib/complex-float64-base-add' );\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar format = require( '@stdlib/string-format' );\nvar ndarrayFcn = require( './ndarray.js' );\nvar arrayFcn = require( './array.js' );\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/number-float64-base-add' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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* Perform a map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.\n*\n* @module @stdlib/utils-map-reduce-right\n*\n* @example\n* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' );\n*\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, sum );\n* // returns 30\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/number-float64-base-add' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\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,EAAY,QAAS,gCAAiC,EAKtDC,EAAO,QA0EX,SAASC,EAAgBC,EAAGC,EAASC,EAAQC,EAASC,EAAU,CAC/D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMR,EAAE,OAGRW,EAAMX,EAAE,MAGRK,EAAOL,EAAE,KAGTY,EAAKZ,EAAE,QAGPa,EAAKb,EAAE,OAGPM,EAAON,EAAE,MAGTS,EAAMT,EAAE,UAAW,CAAE,EAGrBU,EAAMV,EAAE,IAGHW,EAAI,SAAW,EACnB,OAAOR,EAAQ,KAAMC,EAASH,EAASC,EAAQO,EAAKJ,EAAMQ,CAAG,EAAG,EAAGH,CAAI,EAAG,EAAGA,CAAI,EAIlF,IADAH,EAAMN,EACAc,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKjB,EAAWc,EAAKC,EAAIC,EAAIP,EAAMS,EAAGjB,CAAK,EAC3CS,EAAMJ,EAAQ,KAAMC,EAASG,EAAKL,EAAQO,EAAKJ,EAAMS,CAAG,EAAGC,EAAGL,CAAI,EAAGK,EAAGL,CAAI,EAE7E,OAAOH,CACR,CAKAX,EAAO,QAAUG,IC1JjB,IAAAiB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA2DA,SAASC,EAAgBC,EAAGC,EAASC,EAAQC,EAASC,EAAU,CAC/D,IAAIC,EACAC,EACAC,EACAC,EAUJ,IAPAH,EAAOL,EAAE,KAGTM,EAAMN,EAAE,UAAW,CAAE,EAGrBO,EAAMN,EACAO,EAAIH,EAAK,OAAO,EAAGG,GAAK,EAAGA,IAChCD,EAAMJ,EAAQ,KAAMC,EAASG,EAAKL,EAAQI,EAAKD,EAAMG,CAAE,EAAGA,EAAGH,CAAK,EAAGG,EAAGH,CAAK,EAE9E,OAAOE,CACR,CAKAT,EAAO,QAAUC,IClFjB,IAAAU,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAoB,QAAS,qCAAsC,EACnEC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,4BAA6B,EACnDC,EAAqB,QAAS,yCAA0C,EACxEC,EAAmB,QAAS,qCAAsC,EAClEC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAW,IA6Df,SAASC,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,EAAU,CACjE,GAAK,CAACX,EAAYS,CAAO,EACxB,MAAM,IAAI,UAAWN,EAAQ,oEAAqEM,CAAO,CAAE,EAE5G,GAAK,CAACT,EAAYU,CAAQ,EACzB,MAAM,IAAI,UAAWP,EAAQ,qEAAsEO,CAAQ,CAAE,EAE9G,GAAKX,EAAeQ,CAAI,EACvB,OAAOH,EAAYH,EAAoBM,CAAI,EAAGC,EAASC,EAAQC,EAASC,CAAQ,EAEjF,GAAKb,EAAmBS,CAAI,EAC3B,OAAOF,EAAUH,EAAkBK,CAAI,EAAGC,EAASC,EAAQC,EAASC,CAAQ,EAE7E,MAAM,IAAI,UAAWR,EAAQ,4FAA6FI,CAAI,CAAE,CACjI,CAKAV,EAAO,QAAUS,IClDjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_ndarray", "__commonJSMin", "exports", "module", "vind2bind", "MODE", "mapReduceRight", "x", "initial", "mapper", "reducer", "thisArg", "xbuf", "ordx", "acc", "len", "get", "ref", "shx", "sx", "ox", "ix", "i", "require_array", "__commonJSMin", "exports", "module", "mapReduceRight", "x", "initial", "mapper", "reducer", "thisArg", "xbuf", "get", "acc", "i", "require_main", "__commonJSMin", "exports", "module", "isArrayLikeObject", "isndarrayLike", "isFunction", "ndarraylike2object", "arraylike2object", "format", "ndarrayFcn", "arrayFcn", "mapReduceRight", "arr", "initial", "mapper", "reducer", "thisArg", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 7501299..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, initial, mapper, reducer[, thisArg] ) - Performs a map-reduce operation for each element in an array while iterating - from right to left and returns the accumulated result. - - When invoked, the mapping function is provided three arguments: - - - value: array element. - - index: element index. - - arr: input array. - - When invoked, the reducing function is provided four arguments: - - - accumulator: accumulated value. - - value: result after applying the mapping function to the current array - element. - - index: element index. - - arr: input array. - - If provided an empty array, the function returns the initial value. - - When provided an ndarray, the function performs a single-pass map-reduce - operation over the entire input ndarray (i.e., higher-order ndarray - dimensions are flattened to a single-dimension). - - Parameters - ---------- - arr: ArrayLikeObject|ndarray - Input array. - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - mapper: Function - Mapping function. - - reducer: Function - Reducing function. - - thisArg: any (optional) - Execution context for the reducing function. - - Returns - ------- - out: any - Accumulated result. - - Examples - -------- - // array-like object: - > var f1 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/special/abs}}, 1 ); - > var f2 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/number/float64/base/add}}, 2 ); - > var arr = [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0 ]; - > var out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - // ndarray: - > arr = {{alias:@stdlib/ndarray/array}}( arr, { 'shape': [ 2, 3 ] } ); - > out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 58a6cae..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,184 +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. -*/ - -import array = require( '@stdlib/ndarray-array' ); -import mapReduceRight = require( './index' ); - -/** -* Mapping function. -* -* @param value - array element -* @returns result -*/ -function mapper( value: number ): number { - return value; -} - -/** -* Reducing function. -* -* @param acc - accumulated value -* @param value - array element -* @returns result -*/ -function reducer( acc: number, value: number ): number { - return acc + value; -} - - -// TESTS // - -// The function returns the accumulated value when provided a collection... -{ - mapReduceRight( [ 0, 1, 1, NaN, 2 ], 0, mapper, reducer ); // $ExpectType number - mapReduceRight( [ -1, 1, 2 ], 100, mapper, reducer ); // $ExpectType number - mapReduceRight( [ -1, 1, 2 ], 0, mapper, reducer, {} ); // $ExpectType number -} - -// The function returns the accumulated value when provided an ndarray... -{ - const arr = array( [ 1, 2, 3, 4, 5, 6 ] ); - - mapReduceRight( arr, 0, mapper, reducer ); // $ExpectType number - mapReduceRight( arr, 100, mapper, reducer ); // $ExpectType number - mapReduceRight( arr, 0, mapper, reducer, {} ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not a collection or ndarray... -{ - mapReduceRight( 2, 0, mapper, reducer ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer ); // $ExpectError - - mapReduceRight( 2, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr1, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr2, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const arr1 = [ 1, 2, 3 ]; - - mapReduceRight(); // $ExpectError - mapReduceRight( arr1 ); // $ExpectError - mapReduceRight( arr1, 0 ); // $ExpectError - mapReduceRight( arr1, 0, mapper ); // $ExpectError - mapReduceRight( arr1, 0, mapper, reducer, {}, 3 ); // $ExpectError - - const arr2 = array( [ 1, 2, 3 ] ); - - mapReduceRight(); // $ExpectError - mapReduceRight( arr2 ); // $ExpectError - mapReduceRight( arr2, 0 ); // $ExpectError - mapReduceRight( arr2, 0, mapper ); // $ExpectError - mapReduceRight( arr2, 0, mapper, reducer, {}, 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 257051e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,52 +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. -*/ - -'use strict'; - -var filledarrayBy = require( '@stdlib/array-filled-by' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ).factory; -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/number-float64-base-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var mapReduceRight = require( './../lib' ); - -function fill( i ) { - var rand = discreteUniform( -10*(i+1), 10*(i+1) ); - return filledarrayBy( 10, 'generic', rand ); -} - -// Create a two-dimensional ndarray (i.e., a matrix): -var x = array( filledarrayBy( 10, 'generic', fill ), { - 'dtype': 'generic', - 'flatten': true -}); - -// Create an explicit unary function: -var f1 = naryFunction( abs, 1 ); - -// Create an explicit binary function: -var f2 = naryFunction( add, 2 ); - -// Compute the sum of absolute values: -var out = mapReduceRight( x, 0, f1, f2 ); - -console.log( 'x:' ); -console.log( x.data ); - -console.log( 'sum: %d', out ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 5dba991..54a2de2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; import { typedndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..f002e6b --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.2.2-esm/index.mjs";var o="throw";function a(a,m,l,j,f){if(!e(l))throw new TypeError(n("1VL3N",l));if(!e(j))throw new TypeError(n("1VL32",j));if(s(a))return function(r,s,e,t,i){var n,a,m,l,j,f,h,c,p,v,b;if(l=r.length,h=r.shape,n=r.data,c=r.strides,p=r.offset,a=r.order,j=r.accessors[0],f=r.ref,0===h.length)return t.call(i,s,e(j(n,p),0,f),0,f);for(m=s,b=l-1;b>=0;b--)v=d(h,c,p,a,b,o),m=t.call(i,m,e(j(n,v),b,f),b,f);return m}(t(a),m,l,j,f);if(r(a))return function(r,s,e,t,i){var n,d,o,a;for(n=r.data,d=r.accessors[0],o=s,a=n.length-1;a>=0;a--)o=t.call(i,o,e(d(n,a),a,n),a,n);return o}(i(a),m,l,j,f);throw new TypeError(n("1VLBH",a))}export{a as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..4888dcc --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/ndarray.js","../lib/main.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind';\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64';\n* import Complex64 from '@stdlib/complex-float32-ctor';\n* import realf from '@stdlib/complex-float32-real';\n* import imagf from '@stdlib/complex-float32-imag';\n* import cceil from '@stdlib/math-base-special-cceil';\n* import cadd from '@stdlib/complex-float64-base-add';\n* import naryFunction from '@stdlib/utils-nary-function';\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isFunction from '@stdlib/assert-is-function';\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object';\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndarrayFcn from './ndarray.js';\nimport arrayFcn from './array.js';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function';\n* import add from '@stdlib/number-float64-base-add';\n* import abs from '@stdlib/math-base-special-abs';\n* import array from '@stdlib/ndarray-array';\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '1VL3N', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '1VL32', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '1VLBH', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["MODE","mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","accessors","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;srBA2BA,IAAIA,EAAO,QC+DX,SAASC,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,GAAKK,EAAeR,GACnB,ODGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,UAAW,GAGnBZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAAGtB,GACtCc,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,CACR,CCnDSkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OC1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,UAAW,GAGnBf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,CACR,CDwBSqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,QAASP,GACvC"} \ No newline at end of file diff --git a/lib/array.js b/lib/array.js deleted file mode 100644 index 69c0a8c..0000000 --- a/lib/array.js +++ /dev/null @@ -1,83 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input array data -* @param {ArrayLikeObject} x.data - input array data -* @param {Array} x.accessors - input array accessors -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf[ idx ]; -* } -* -* // Create the input array object: -* var x = { -* 'data': [ 1, 2, 3, 4 ], -* 'accessors': [ getter ] -* }; -* -* // Compute the sum of squared values: -* var out = mapReduceRight( x, 0, square, sum ); -* // returns 30 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var get; - var acc; - var i; - - // Cache reference to the input data: - xbuf = x.data; - - // Cache the element accessor: - get = x.accessors[ 0 ]; - - // Iterate over each element... - acc = initial; - for ( i = xbuf.length-1; i >= 0; i-- ) { - acc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 3b25355..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +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. -*/ - -'use strict'; - -/** -* Perform a map-reduce operation against each element in an array while iterating from right to left and return the accumulated result. -* -* @module @stdlib/utils-map-reduce-right -* -* @example -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/number-float64-base-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ - -// 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 c7692a8..0000000 --- a/lib/main.js +++ /dev/null @@ -1,110 +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. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ndarrayFcn = require( './ndarray.js' ); -var arrayFcn = require( './array.js' ); - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided the following arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided the following arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result of applying the mapping function against the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* @param {(ArrayLikeObject|ndarray)} arr - input array -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} [thisArg] - reduction function execution context -* @throws {TypeError} first argument must be an array-like object or an ndarray -* @throws {TypeError} third argument must be a function -* @throws {TypeError} fourth argument must be a function -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/number-float64-base-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { - if ( !isFunction( mapper ) ) { - throw new TypeError( format( '1VL3N', mapper ) ); - } - if ( !isFunction( reducer ) ) { - throw new TypeError( format( '1VL32', reducer ) ); - } - if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like - return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - if ( isArrayLikeObject( arr ) ) { - return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - throw new TypeError( format( '1VLBH', arr ) ); -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/ndarray.js b/lib/ndarray.js deleted file mode 100644 index bcf9eb1..0000000 --- a/lib/ndarray.js +++ /dev/null @@ -1,155 +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. -*/ - -'use strict'; - -// MODULES // - -var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); - - -// VARIABLES // - -var MODE = 'throw'; - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input ndarray meta data -* @param {string} x.ref - reference to original input ndarray-like object -* @param {string} x.dtype - data type -* @param {Collection} x.data - data buffer -* @param {NonNegativeInteger} x.length - number of elements -* @param {NonNegativeIntegerArray} x.shape - dimensions -* @param {IntegerArray} x.strides - stride lengths -* @param {NonNegativeInteger} x.offset - index offset -* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) -* @param {Array} x.accessors - accessors for accessing data buffer elements -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var Complex64 = require( '@stdlib/complex-float32-ctor' ); -* var realf = require( '@stdlib/complex-float32-real' ); -* var imagf = require( '@stdlib/complex-float32-imag' ); -* var cceil = require( '@stdlib/math-base-special-cceil' ); -* var cadd = require( '@stdlib/complex-float64-base-add' ); -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* -* // Create a data buffer: -* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] ); -* -* // Define the shape of the input array: -* var shape = [ 2, 2 ]; -* -* // Define the array strides: -* var sx = [ 2, 1 ]; -* -* // Define the index offset: -* var ox = 0; -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf.get( idx ); -* } -* -* // Create the input ndarray-like object: -* var x = { -* 'ref': null, -* 'dtype': 'complex64', -* 'data': xbuf, -* 'length': 4, -* 'shape': shape, -* 'strides': sx, -* 'offset': ox, -* 'order': 'row-major', -* 'accessors': [ getter ] -* }; -* x.ref = x; -* -* // Compute the sum: -* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) ); -* -* var re = realf( v ); -* // returns 20.0 -* -* var im = imagf( v ); -* // returns 24.0 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var ordx; - var acc; - var len; - var get; - var ref; - var shx; - var sx; - var ox; - var ix; - var i; - - // Cache the total number of elements over which to iterate: - len = x.length; - - // Cache the input array shape: - shx = x.shape; - - // Cache reference to the input ndarray data buffer: - xbuf = x.data; - - // Cache reference to the stride array: - sx = x.strides; - - // Cache the index of the first indexed element: - ox = x.offset; - - // Cache the array order: - ordx = x.order; - - // Cache the element accessor: - get = x.accessors[ 0 ]; - - // Cache the reference to the original input array: - ref = x.ref; - - // Check for a zero-dimensional array... - if ( shx.length === 0 ) { - return reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len - } - // Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)... - acc = initial; - for ( i = len-1; i >= 0; i-- ) { - ix = vind2bind( shx, sx, ox, ordx, i, MODE ); - acc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/package.json b/package.json index d39f6e2..3df9694 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Perform a single-pass map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.", "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/array-base-arraylike2object": "^0.2.1", - "@stdlib/assert-is-array-like-object": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-base-ndarraylike2object": "^0.2.2", - "@stdlib/ndarray-base-vind2bind": "^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-base-filled": "^0.2.2", - "@stdlib/array-complex64": "^0.3.0", - "@stdlib/array-filled-by": "^0.2.1", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/complex-float32-ctor": "^0.0.2", - "@stdlib/complex-float32-imag": "^0.1.1", - "@stdlib/complex-float32-real": "^0.1.1", - "@stdlib/complex-float64-base-add": "^0.1.0", - "@stdlib/math-base-assert-is-nan": "^0.2.2", - "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/math-base-special-cceil": "^0.2.2", - "@stdlib/math-base-special-pow": "^0.3.0", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/number-float64-base-add": "github:stdlib-js/number-float64-base-add#main", - "@stdlib/random-base-discrete-uniform": "^0.2.1", - "@stdlib/utils-nary-function": "^0.2.2", - "@stdlib/utils-noop": "^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", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..150aec2 --- /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/test.js b/test/test.js deleted file mode 100644 index 3ac2622..0000000 --- a/test/test.js +++ /dev/null @@ -1,637 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/number-float64-base-add' ); -var cadd = require( '@stdlib/complex-float64-base-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var cceil = require( '@stdlib/math-base-special-cceil' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var realf = require( '@stdlib/complex-float32-real' ); -var imagf = require( '@stdlib/complex-float32-imag' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var mapReduceRight = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapReduceRight, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a first argument which is either an array-like object or an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( value, 0, noop, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value, {} ); - }; - } -}); - -tape( 'the function performs a map-reduce operation for each element in an array (array-like object)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = [ -1, -2, -3 ]; - expected = 7; - actual = mapReduceRight( arr, 1, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (typed array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - expected = 7.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (complex number array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( cceil, 1 ); - f2 = naryFunction( cadd, 2 ); - - arr = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5 ] ); - expected = new Complex64( 12.0, 15.0 ); - actual = mapReduceRight( arr, new Complex64( 0.0, 0.0 ), f1, f2 ); - - t.strictEqual( realf( actual ), realf( expected ), 'returns expected value' ); - t.strictEqual( imagf( actual ), imagf( expected ), 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = array( [ -1.0, -2.0, -3.0, -4.0 ], { - 'dtype': 'generic' - }); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray; 0-dimensional)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = ndarray( 'generic', [ -10.0 ], [], [ 0 ], 0, 'row-major' ); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (array-like object)', function test( t ) { - var out = mapReduceRight( [], 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (ndarray)', function test( t ) { - var arr; - var out; - - arr = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 0, 2 ], [ 0, 2, 1 ], 0, 'row-major' ); - out = mapReduceRight( arr, 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function supports providing a `this` context (array-like object)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = [ -1.0, -2.0, -3.0 ]; - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function supports providing a `this` context (ndarray)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = array( [ -1.0, -2.0, -3.0 ], { - 'dtype': 'generic' - }); - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = array( [ 1, , , 4 ], { // eslint-disable-line no-sparse-arrays - 'dtype': 'generic' - }); - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); From ae76ae0ec6c8c97b3f3cd22fa5f3b9c47d694fd2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 11 Aug 2025 01:42:00 +0000 Subject: [PATCH 89/91] Transform error messages --- lib/main.js | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/main.js b/lib/main.js index c281dc6..c7692a8 100644 --- a/lib/main.js +++ b/lib/main.js @@ -25,7 +25,7 @@ var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); var isFunction = require( '@stdlib/assert-is-function' ); var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var ndarrayFcn = require( './ndarray.js' ); var arrayFcn = require( './array.js' ); @@ -90,10 +90,10 @@ var arrayFcn = require( './array.js' ); */ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( !isFunction( mapper ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) ); + throw new TypeError( format( '1VL3N', mapper ) ); } if ( !isFunction( reducer ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) ); + throw new TypeError( format( '1VL32', reducer ) ); } if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len @@ -101,7 +101,7 @@ function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { if ( isArrayLikeObject( arr ) ) { return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len } - throw new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) ); + throw new TypeError( format( '1VLBH', arr ) ); } diff --git a/package.json b/package.json index bd01cf6..d39f6e2 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@stdlib/assert-is-ndarray-like": "^0.2.2", "@stdlib/ndarray-base-ndarraylike2object": "^0.2.2", "@stdlib/ndarray-base-vind2bind": "^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 a47751a88c6bd36c321f517d32123d86f5af117c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 11 Aug 2025 02:03:00 +0000 Subject: [PATCH 90/91] Remove files --- index.d.ts | 257 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5104 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 54a2de2..0000000 --- a/index.d.ts +++ /dev/null @@ -1,257 +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. -*/ - -// TypeScript Version: 4.1 - -/// - -import { Collection } from '@stdlib/types/array'; -import { typedndarray } from '@stdlib/types/ndarray'; - -/** -* Callback invoked for each array element. -* -* @returns result -*/ -type Nullary = () => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @returns result -*/ -type Unary = ( value: T ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @returns result -*/ -type Binary = ( value: T, index: number ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Ternary = ( value: T, index: number, arr: typedndarray ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayTernary = ( value: T, index: number, arr: Collection ) => U; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type Mapper = Nullary | Unary | Binary | Ternary; - -/** -* Callback invoked for each array element. -* -* @param value - array element -* @param index - element index -* @param arr - array -* @returns result -*/ -type ArrayMapper = Nullary | Unary | Binary | ArrayTernary; - -/** -* Function applied against an accumulator. -* -* @returns accumulator value -*/ -type NullaryReducer = ( this: W ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @returns accumulator value -*/ -type UnaryReducer = ( this: W, accumulator: V ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @returns accumulator value -*/ -type BinaryReducer = ( this: W, accumulator: V, value: U ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @returns accumulator value -*/ -type TernaryReducer = ( this: W, accumulator: V, value: U, index: number ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type QuaternaryReducer = ( this: W, accumulator: V, value: U, index: number, arr: typedndarray ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayQuaternaryReducer = ( this: W, accumulator: V, value: U, index: number, arr: Collection ) => V; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type Reducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | QuaternaryReducer; - -/** -* Function applied against an accumulator. -* -* @param accumulator - accumulated value -* @param value - array element -* @param index - element index -* @param arr - array -* @returns accumulator value -*/ -type ArrayReducer = NullaryReducer | UnaryReducer | BinaryReducer | TernaryReducer | ArrayQuaternaryReducer; - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var add = require( '@stdlib/number-float64-base-add' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 2 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -declare function mapReduceRight( arr: typedndarray, initial: V, mapper: Mapper, reducer: Reducer, thisArg?: ThisParameterType> ): V; - -/** -* Performs a map-reduce operation for each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided four arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided four arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result after applying a mapping function to the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* - If provided an empty array, the function returns the initial value. -* -* @param arr - input array -* @param initial - initial value -* @param mapper - mapping function -* @param reducer - reducing function -* @param thisArg - reducing function execution context -* @returns accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -*/ -declare function mapReduceRight( arr: Collection, initial: V, mapper: ArrayMapper, reducer: ArrayReducer, thisArg?: ThisParameterType> ): V; - - -// EXPORTS // - -export = mapReduceRight; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index f002e6b..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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.2.2-esm/index.mjs";var o="throw";function a(a,m,l,j,f){if(!e(l))throw new TypeError(n("1VL3N",l));if(!e(j))throw new TypeError(n("1VL32",j));if(s(a))return function(r,s,e,t,i){var n,a,m,l,j,f,h,c,p,v,b;if(l=r.length,h=r.shape,n=r.data,c=r.strides,p=r.offset,a=r.order,j=r.accessors[0],f=r.ref,0===h.length)return t.call(i,s,e(j(n,p),0,f),0,f);for(m=s,b=l-1;b>=0;b--)v=d(h,c,p,a,b,o),m=t.call(i,m,e(j(n,v),b,f),b,f);return m}(t(a),m,l,j,f);if(r(a))return function(r,s,e,t,i){var n,d,o,a;for(n=r.data,d=r.accessors[0],o=s,a=n.length-1;a>=0;a--)o=t.call(i,o,e(d(n,a),a,n),a,n);return o}(i(a),m,l,j,f);throw new TypeError(n("1VLBH",a))}export{a as default}; -//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map deleted file mode 100644 index 4888dcc..0000000 --- a/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../lib/ndarray.js","../lib/main.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind';\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64';\n* import Complex64 from '@stdlib/complex-float32-ctor';\n* import realf from '@stdlib/complex-float32-real';\n* import imagf from '@stdlib/complex-float32-imag';\n* import cceil from '@stdlib/math-base-special-cceil';\n* import cadd from '@stdlib/complex-float64-base-add';\n* import naryFunction from '@stdlib/utils-nary-function';\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isFunction from '@stdlib/assert-is-function';\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object';\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndarrayFcn from './ndarray.js';\nimport arrayFcn from './array.js';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function';\n* import add from '@stdlib/number-float64-base-add';\n* import abs from '@stdlib/math-base-special-abs';\n* import array from '@stdlib/ndarray-array';\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '1VL3N', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '1VL32', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '1VLBH', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["MODE","mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","accessors","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;srBA2BA,IAAIA,EAAO,QC+DX,SAASC,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,GAAKK,EAAeR,GACnB,ODGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,UAAW,GAGnBZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAAGtB,GACtCc,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,CACR,CCnDSkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OC1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,UAAW,GAGnBf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,CACR,CDwBSqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,QAASP,GACvC"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 150aec2..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From d9d05ba90b5d10352f6c611d0232ada8804e0a4a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 11 Aug 2025 02:03:29 +0000 Subject: [PATCH 91/91] 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 | 169 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 71 +- SECURITY.md | 5 - benchmark/benchmark.array.js | 98 - benchmark/benchmark.ndarray.js | 109 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 9 - dist/index.js.map | 7 - docs/repl.txt | 65 - docs/types/test.ts | 184 - examples/index.js | 52 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/array.js | 83 - lib/index.js | 65 - lib/main.js | 110 - lib/ndarray.js | 155 - package.json | 77 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 637 --- 47 files changed, 4881 insertions(+), 5240 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.array.js delete mode 100644 benchmark/benchmark.ndarray.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/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/array.js delete mode 100644 lib/index.js delete mode 100644 lib/main.js delete mode 100644 lib/ndarray.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.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 740007f..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-08-11T01:33:05.465Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 6267240..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/utils/map-reduce-right) 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 f23359f..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/utils/map-reduce-right) 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 1308146..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: '21 21 * * 4' - - # 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 + + ```
@@ -281,7 +272,7 @@ console.log( 'sum: %d', out ); ## 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]. @@ -344,19 +335,19 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/utils-map-reduce-right/main/LICENSE -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm -[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64 +[@stdlib/array/complex64]: https://github.com/stdlib-js/array-complex64/tree/esm -[@stdlib/array/complex128]: https://github.com/stdlib-js/array-complex128 +[@stdlib/array/complex128]: https://github.com/stdlib-js/array-complex128/tree/esm -[@stdlib/utils/map-right]: https://github.com/stdlib-js/utils-map-right +[@stdlib/utils/map-right]: https://github.com/stdlib-js/utils-map-right/tree/esm -[@stdlib/utils/map-reduce]: https://github.com/stdlib-js/utils-map-reduce +[@stdlib/utils/map-reduce]: https://github.com/stdlib-js/utils-map-reduce/tree/esm -[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right +[@stdlib/utils/reduce-right]: https://github.com/stdlib-js/utils-reduce-right/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.array.js b/benchmark/benchmark.array.js deleted file mode 100644 index 0dca22a..0000000 --- a/benchmark/benchmark.array.js +++ /dev/null @@ -1,98 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/number-float64-base-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var x = filled( -3.0, len ); - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::array:len='+len, f ); - } -} - -main(); diff --git a/benchmark/benchmark.ndarray.js b/benchmark/benchmark.ndarray.js deleted file mode 100644 index 68f754c..0000000 --- a/benchmark/benchmark.ndarray.js +++ /dev/null @@ -1,109 +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. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var pow = require( '@stdlib/math-base-special-pow' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var filled = require( '@stdlib/array-base-filled' ); -var add = require( '@stdlib/number-float64-base-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var pkg = require( './../package.json' ).name; -var mapReduceRight = require( './../lib' ); - - -// FUNCTIONS // - -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - array length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - var xbuf; - var opts; - var x; - - xbuf = filled( -3.0, len ); - - opts = { - 'dtype': 'generic' - }; - x = array( xbuf, opts ); - - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = mapReduceRight( x, 0.0, abs, add ); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( out ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } -} - - -// MAIN // - -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var len; - var min; - var max; - var f; - var i; - - min = 1; // 10^min - max = 6; // 10^max - - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - - f = createBenchmark( len ); - bench( pkg+'::ndarray:len='+len, f ); - } -} - -main(); diff --git a/branches.md b/branches.md deleted file mode 100644 index 0816c5f..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/utils/map-reduce-right" -%% click B href "https://github.com/stdlib-js/utils-map-reduce-right/tree/main" -%% click C href "https://github.com/stdlib-js/utils-map-reduce-right/tree/production" -%% click D href "https://github.com/stdlib-js/utils-map-reduce-right/tree/esm" -%% click E href "https://github.com/stdlib-js/utils-map-reduce-right/tree/deno" -%% click F href "https://github.com/stdlib-js/utils-map-reduce-right/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/utils/map-reduce-right -[production-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/production -[deno-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/deno -[deno-readme]: https://github.com/stdlib-js/utils-map-reduce-right/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/umd -[umd-readme]: https://github.com/stdlib-js/utils-map-reduce-right/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/utils-map-reduce-right/tree/esm -[esm-readme]: https://github.com/stdlib-js/utils-map-reduce-right/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 63ea99a..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import mapReduceRight from '../docs/types/index'; -export = mapReduceRight; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 3180c8b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,9 +0,0 @@ -"use strict";var g=function(r,e){return function(){return e||r((e={exports:{}}).exports,e),e.exports}};var q=g(function(H,m){ -var E=require('@stdlib/ndarray-base-vind2bind/dist'),T="throw";function p(r,e,a,t,s){var i,v,n,u,f,c,l,y,d,b,o;if(u=r.length,l=r.shape,i=r.data,y=r.strides,d=r.offset,v=r.order,f=r.accessors[0],c=r.ref,l.length===0)return t.call(s,e,a(f(i,d),0,c),0,c);for(n=e,o=u-1;o>=0;o--)b=E(l,y,d,v,o,T),n=t.call(s,n,a(f(i,b),o,c),o,c);return n}m.exports=p -});var R=g(function(I,w){ -function x(r,e,a,t,s){var i,v,n,u;for(i=r.data,v=r.accessors[0],n=e,u=i.length-1;u>=0;u--)n=t.call(s,n,a(v(i,u),u,i),u,i);return n}w.exports=x -});var j=g(function(J,F){ -var V=require('@stdlib/assert-is-array-like-object/dist'),L=require('@stdlib/assert-is-ndarray-like/dist'),k=require('@stdlib/assert-is-function/dist'),O=require('@stdlib/ndarray-base-ndarraylike2object/dist'),D=require('@stdlib/array-base-arraylike2object/dist'),h=require('@stdlib/error-tools-fmtprodmsg/dist'),M=q(),z=R();function B(r,e,a,t,s){if(!k(a))throw new TypeError(h('1VL3N',a));if(!k(t))throw new TypeError(h('1VL32',t));if(L(r))return M(O(r),e,a,t,s);if(V(r))return z(D(r),e,a,t,s);throw new TypeError(h('1VLBH',r))}F.exports=B -});var C=j();module.exports=C; -/** @license Apache-2.0 */ -//# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map deleted file mode 100644 index 5ea9971..0000000 --- a/dist/index.js.map +++ /dev/null @@ -1,7 +0,0 @@ -{ - "version": 3, - "sources": ["../lib/ndarray.js", "../lib/array.js", "../lib/main.js", "../lib/index.js"], - "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar vind2bind = require( '@stdlib/ndarray-base-vind2bind' );\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* var Complex64Array = require( '@stdlib/array-complex64' );\n* var Complex64 = require( '@stdlib/complex-float32-ctor' );\n* var realf = require( '@stdlib/complex-float32-real' );\n* var imagf = require( '@stdlib/complex-float32-imag' );\n* var cceil = require( '@stdlib/math-base-special-cceil' );\n* var cadd = require( '@stdlib/complex-float64-base-add' );\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' );\nvar isndarrayLike = require( '@stdlib/assert-is-ndarray-like' );\nvar isFunction = require( '@stdlib/assert-is-function' );\nvar ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar format = require( '@stdlib/string-format' );\nvar ndarrayFcn = require( './ndarray.js' );\nvar arrayFcn = require( './array.js' );\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/number-float64-base-add' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( 'invalid argument. First argument must be an array-like object or an ndarray. Value: `%s`.', arr ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = mapReduceRight;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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* Perform a map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.\n*\n* @module @stdlib/utils-map-reduce-right\n*\n* @example\n* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' );\n*\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, sum );\n* // returns 30\n*\n* @example\n* var naryFunction = require( '@stdlib/utils-nary-function' );\n* var add = require( '@stdlib/number-float64-base-add' );\n* var abs = require( '@stdlib/math-base-special-abs' );\n* var array = require( '@stdlib/ndarray-array' );\n* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' );\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\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,EAAY,QAAS,gCAAiC,EAKtDC,EAAO,QA0EX,SAASC,EAAgBC,EAAGC,EAASC,EAAQC,EAASC,EAAU,CAC/D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMR,EAAE,OAGRW,EAAMX,EAAE,MAGRK,EAAOL,EAAE,KAGTY,EAAKZ,EAAE,QAGPa,EAAKb,EAAE,OAGPM,EAAON,EAAE,MAGTS,EAAMT,EAAE,UAAW,CAAE,EAGrBU,EAAMV,EAAE,IAGHW,EAAI,SAAW,EACnB,OAAOR,EAAQ,KAAMC,EAASH,EAASC,EAAQO,EAAKJ,EAAMQ,CAAG,EAAG,EAAGH,CAAI,EAAG,EAAGA,CAAI,EAIlF,IADAH,EAAMN,EACAc,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKjB,EAAWc,EAAKC,EAAIC,EAAIP,EAAMS,EAAGjB,CAAK,EAC3CS,EAAMJ,EAAQ,KAAMC,EAASG,EAAKL,EAAQO,EAAKJ,EAAMS,CAAG,EAAGC,EAAGL,CAAI,EAAGK,EAAGL,CAAI,EAE7E,OAAOH,CACR,CAKAX,EAAO,QAAUG,IC1JjB,IAAAiB,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cA2DA,SAASC,EAAgBC,EAAGC,EAASC,EAAQC,EAASC,EAAU,CAC/D,IAAIC,EACAC,EACAC,EACAC,EAUJ,IAPAH,EAAOL,EAAE,KAGTM,EAAMN,EAAE,UAAW,CAAE,EAGrBO,EAAMN,EACAO,EAAIH,EAAK,OAAO,EAAGG,GAAK,EAAGA,IAChCD,EAAMJ,EAAQ,KAAMC,EAASG,EAAKL,EAAQI,EAAKD,EAAMG,CAAE,EAAGA,EAAGH,CAAK,EAAGG,EAAGH,CAAK,EAE9E,OAAOE,CACR,CAKAT,EAAO,QAAUC,IClFjB,IAAAU,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAoB,QAAS,qCAAsC,EACnEC,EAAgB,QAAS,gCAAiC,EAC1DC,EAAa,QAAS,4BAA6B,EACnDC,EAAqB,QAAS,yCAA0C,EACxEC,EAAmB,QAAS,qCAAsC,EAClEC,EAAS,QAAS,uBAAwB,EAC1CC,EAAa,IACbC,EAAW,IA6Df,SAASC,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,EAAU,CACjE,GAAK,CAACX,EAAYS,CAAO,EACxB,MAAM,IAAI,UAAWN,EAAQ,oEAAqEM,CAAO,CAAE,EAE5G,GAAK,CAACT,EAAYU,CAAQ,EACzB,MAAM,IAAI,UAAWP,EAAQ,qEAAsEO,CAAQ,CAAE,EAE9G,GAAKX,EAAeQ,CAAI,EACvB,OAAOH,EAAYH,EAAoBM,CAAI,EAAGC,EAASC,EAAQC,EAASC,CAAQ,EAEjF,GAAKb,EAAmBS,CAAI,EAC3B,OAAOF,EAAUH,EAAkBK,CAAI,EAAGC,EAASC,EAAQC,EAASC,CAAQ,EAE7E,MAAM,IAAI,UAAWR,EAAQ,4FAA6FI,CAAI,CAAE,CACjI,CAKAV,EAAO,QAAUS,IClDjB,IAAIM,EAAO,IAKX,OAAO,QAAUA", - "names": ["require_ndarray", "__commonJSMin", "exports", "module", "vind2bind", "MODE", "mapReduceRight", "x", "initial", "mapper", "reducer", "thisArg", "xbuf", "ordx", "acc", "len", "get", "ref", "shx", "sx", "ox", "ix", "i", "require_array", "__commonJSMin", "exports", "module", "mapReduceRight", "x", "initial", "mapper", "reducer", "thisArg", "xbuf", "get", "acc", "i", "require_main", "__commonJSMin", "exports", "module", "isArrayLikeObject", "isndarrayLike", "isFunction", "ndarraylike2object", "arraylike2object", "format", "ndarrayFcn", "arrayFcn", "mapReduceRight", "arr", "initial", "mapper", "reducer", "thisArg", "main"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 7501299..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,65 +0,0 @@ - -{{alias}}( arr, initial, mapper, reducer[, thisArg] ) - Performs a map-reduce operation for each element in an array while iterating - from right to left and returns the accumulated result. - - When invoked, the mapping function is provided three arguments: - - - value: array element. - - index: element index. - - arr: input array. - - When invoked, the reducing function is provided four arguments: - - - accumulator: accumulated value. - - value: result after applying the mapping function to the current array - element. - - index: element index. - - arr: input array. - - If provided an empty array, the function returns the initial value. - - When provided an ndarray, the function performs a single-pass map-reduce - operation over the entire input ndarray (i.e., higher-order ndarray - dimensions are flattened to a single-dimension). - - Parameters - ---------- - arr: ArrayLikeObject|ndarray - Input array. - - initial: any - Accumulator value used in the first invocation of the reduction - function. - - mapper: Function - Mapping function. - - reducer: Function - Reducing function. - - thisArg: any (optional) - Execution context for the reducing function. - - Returns - ------- - out: any - Accumulated result. - - Examples - -------- - // array-like object: - > var f1 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/special/abs}}, 1 ); - > var f2 = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/number/float64/base/add}}, 2 ); - > var arr = [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0 ]; - > var out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - // ndarray: - > arr = {{alias:@stdlib/ndarray/array}}( arr, { 'shape': [ 2, 3 ] } ); - > out = {{alias}}( arr, 0.0, f1, f2 ) - 21.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 58a6cae..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,184 +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. -*/ - -import array = require( '@stdlib/ndarray-array' ); -import mapReduceRight = require( './index' ); - -/** -* Mapping function. -* -* @param value - array element -* @returns result -*/ -function mapper( value: number ): number { - return value; -} - -/** -* Reducing function. -* -* @param acc - accumulated value -* @param value - array element -* @returns result -*/ -function reducer( acc: number, value: number ): number { - return acc + value; -} - - -// TESTS // - -// The function returns the accumulated value when provided a collection... -{ - mapReduceRight( [ 0, 1, 1, NaN, 2 ], 0, mapper, reducer ); // $ExpectType number - mapReduceRight( [ -1, 1, 2 ], 100, mapper, reducer ); // $ExpectType number - mapReduceRight( [ -1, 1, 2 ], 0, mapper, reducer, {} ); // $ExpectType number -} - -// The function returns the accumulated value when provided an ndarray... -{ - const arr = array( [ 1, 2, 3, 4, 5, 6 ] ); - - mapReduceRight( arr, 0, mapper, reducer ); // $ExpectType number - mapReduceRight( arr, 100, mapper, reducer ); // $ExpectType number - mapReduceRight( arr, 0, mapper, reducer, {} ); // $ExpectType number -} - -// The compiler throws an error if the function is provided a first argument which is not a collection or ndarray... -{ - mapReduceRight( 2, 0, mapper, reducer ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer ); // $ExpectError - - mapReduceRight( 2, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( false, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( true, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( null, 0, mapper, reducer, {} ); // $ExpectError - mapReduceRight( {}, 0, mapper, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a third argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr1, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr1, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr1, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, 'abc', reducer ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer ); // $ExpectError - - mapReduceRight( arr2, 0, 'abc', reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, 2, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, false, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, true, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, null, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, {}, reducer, {} ); // $ExpectError - mapReduceRight( arr2, 0, [], reducer, {} ); // $ExpectError - - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer ); // $ExpectError - mapReduceRight( arr2, 0, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, reducer, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided a fourth argument which is not a function with a supported signature... -{ - const arr1 = [ 0, 1, 1, NaN, 2 ]; - - mapReduceRight( arr1, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr1, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr1, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError - - const arr2 = array( [ 0, 1, 1, NaN, 2 ] ); - - mapReduceRight( arr2, 0, mapper, 'abc' ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2 ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [] ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, 'abc', {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, 2, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, false, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, true, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, null, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, {}, {} ); // $ExpectError - mapReduceRight( arr2, 0, mapper, [], {} ); // $ExpectError - - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w ); // $ExpectError - mapReduceRight( arr2, 0, mapper, ( x: number, y: number, z: number, w: number ): number => x + y + z + w, {} ); // $ExpectError -} - -// The compiler throws an error if the function is provided an unsupported number of arguments... -{ - const arr1 = [ 1, 2, 3 ]; - - mapReduceRight(); // $ExpectError - mapReduceRight( arr1 ); // $ExpectError - mapReduceRight( arr1, 0 ); // $ExpectError - mapReduceRight( arr1, 0, mapper ); // $ExpectError - mapReduceRight( arr1, 0, mapper, reducer, {}, 3 ); // $ExpectError - - const arr2 = array( [ 1, 2, 3 ] ); - - mapReduceRight(); // $ExpectError - mapReduceRight( arr2 ); // $ExpectError - mapReduceRight( arr2, 0 ); // $ExpectError - mapReduceRight( arr2, 0, mapper ); // $ExpectError - mapReduceRight( arr2, 0, mapper, reducer, {}, 3 ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 257051e..0000000 --- a/examples/index.js +++ /dev/null @@ -1,52 +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. -*/ - -'use strict'; - -var filledarrayBy = require( '@stdlib/array-filled-by' ); -var discreteUniform = require( '@stdlib/random-base-discrete-uniform' ).factory; -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/number-float64-base-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var array = require( '@stdlib/ndarray-array' ); -var mapReduceRight = require( './../lib' ); - -function fill( i ) { - var rand = discreteUniform( -10*(i+1), 10*(i+1) ); - return filledarrayBy( 10, 'generic', rand ); -} - -// Create a two-dimensional ndarray (i.e., a matrix): -var x = array( filledarrayBy( 10, 'generic', fill ), { - 'dtype': 'generic', - 'flatten': true -}); - -// Create an explicit unary function: -var f1 = naryFunction( abs, 1 ); - -// Create an explicit binary function: -var f2 = naryFunction( add, 2 ); - -// Compute the sum of absolute values: -var out = mapReduceRight( x, 0, f1, f2 ); - -console.log( 'x:' ); -console.log( x.data ); - -console.log( 'sum: %d', out ); diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 5dba991..54a2de2 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { Collection } from '@stdlib/types/array'; import { typedndarray } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..f002e6b --- /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 r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array-like-object@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-function@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ndarraylike2object@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-vind2bind@v0.2.2-esm/index.mjs";var o="throw";function a(a,m,l,j,f){if(!e(l))throw new TypeError(n("1VL3N",l));if(!e(j))throw new TypeError(n("1VL32",j));if(s(a))return function(r,s,e,t,i){var n,a,m,l,j,f,h,c,p,v,b;if(l=r.length,h=r.shape,n=r.data,c=r.strides,p=r.offset,a=r.order,j=r.accessors[0],f=r.ref,0===h.length)return t.call(i,s,e(j(n,p),0,f),0,f);for(m=s,b=l-1;b>=0;b--)v=d(h,c,p,a,b,o),m=t.call(i,m,e(j(n,v),b,f),b,f);return m}(t(a),m,l,j,f);if(r(a))return function(r,s,e,t,i){var n,d,o,a;for(n=r.data,d=r.accessors[0],o=s,a=n.length-1;a>=0;a--)o=t.call(i,o,e(d(n,a),a,n),a,n);return o}(i(a),m,l,j,f);throw new TypeError(n("1VLBH",a))}export{a as default}; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..4888dcc --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../lib/ndarray.js","../lib/main.js","../lib/array.js"],"sourcesContent":["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport vind2bind from '@stdlib/ndarray-base-vind2bind';\n\n\n// VARIABLES //\n\nvar MODE = 'throw';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input ndarray meta data\n* @param {string} x.ref - reference to original input ndarray-like object\n* @param {string} x.dtype - data type\n* @param {Collection} x.data - data buffer\n* @param {NonNegativeInteger} x.length - number of elements\n* @param {NonNegativeIntegerArray} x.shape - dimensions\n* @param {IntegerArray} x.strides - stride lengths\n* @param {NonNegativeInteger} x.offset - index offset\n* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)\n* @param {Array} x.accessors - accessors for accessing data buffer elements\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* import Complex64Array from '@stdlib/array-complex64';\n* import Complex64 from '@stdlib/complex-float32-ctor';\n* import realf from '@stdlib/complex-float32-real';\n* import imagf from '@stdlib/complex-float32-imag';\n* import cceil from '@stdlib/math-base-special-cceil';\n* import cadd from '@stdlib/complex-float64-base-add';\n* import naryFunction from '@stdlib/utils-nary-function';\n*\n* // Create a data buffer:\n* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] );\n*\n* // Define the shape of the input array:\n* var shape = [ 2, 2 ];\n*\n* // Define the array strides:\n* var sx = [ 2, 1 ];\n*\n* // Define the index offset:\n* var ox = 0;\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf.get( idx );\n* }\n*\n* // Create the input ndarray-like object:\n* var x = {\n* 'ref': null,\n* 'dtype': 'complex64',\n* 'data': xbuf,\n* 'length': 4,\n* 'shape': shape,\n* 'strides': sx,\n* 'offset': ox,\n* 'order': 'row-major',\n* 'accessors': [ getter ]\n* };\n* x.ref = x;\n*\n* // Compute the sum:\n* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) );\n*\n* var re = realf( v );\n* // returns 20.0\n*\n* var im = imagf( v );\n* // returns 24.0\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar ordx;\n\tvar acc;\n\tvar len;\n\tvar get;\n\tvar ref;\n\tvar shx;\n\tvar sx;\n\tvar ox;\n\tvar ix;\n\tvar i;\n\n\t// Cache the total number of elements over which to iterate:\n\tlen = x.length;\n\n\t// Cache the input array shape:\n\tshx = x.shape;\n\n\t// Cache reference to the input ndarray data buffer:\n\txbuf = x.data;\n\n\t// Cache reference to the stride array:\n\tsx = x.strides;\n\n\t// Cache the index of the first indexed element:\n\tox = x.offset;\n\n\t// Cache the array order:\n\tordx = x.order;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Cache the reference to the original input array:\n\tref = x.ref;\n\n\t// Check for a zero-dimensional array...\n\tif ( shx.length === 0 ) {\n\t\treturn reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len\n\t}\n\t// Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)...\n\tacc = initial;\n\tfor ( i = len-1; i >= 0; i-- ) {\n\t\tix = vind2bind( shx, sx, ox, ordx, i, MODE );\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nimport isArrayLikeObject from '@stdlib/assert-is-array-like-object';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport isFunction from '@stdlib/assert-is-function';\nimport ndarraylike2object from '@stdlib/ndarray-base-ndarraylike2object';\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport ndarrayFcn from './ndarray.js';\nimport arrayFcn from './array.js';\n\n\n// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* ## Notes\n*\n* - The mapping function is provided the following arguments:\n*\n* - **value**: array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* - The reducing function is provided the following arguments:\n*\n* - **accumulator**: accumulated value.\n* - **value**: result of applying the mapping function against the current array element.\n* - **index**: element index.\n* - **arr**: input array.\n*\n* @param {(ArrayLikeObject|ndarray)} arr - input array\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} [thisArg] - reduction function execution context\n* @throws {TypeError} first argument must be an array-like object or an ndarray\n* @throws {TypeError} third argument must be a function\n* @throws {TypeError} fourth argument must be a function\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* var arr = [ 1, 2, 3, 4 ];\n*\n* var out = mapReduceRight( arr, 0, square, sum );\n* // returns 30\n*\n* @example\n* import naryFunction from '@stdlib/utils-nary-function';\n* import add from '@stdlib/number-float64-base-add';\n* import abs from '@stdlib/math-base-special-abs';\n* import array from '@stdlib/ndarray-array';\n*\n* var opts = {\n* 'dtype': 'generic'\n* };\n* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts );\n*\n* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) );\n* // returns 21\n*/\nfunction mapReduceRight( arr, initial, mapper, reducer, thisArg ) {\n\tif ( !isFunction( mapper ) ) {\n\t\tthrow new TypeError( format( '1VL3N', mapper ) );\n\t}\n\tif ( !isFunction( reducer ) ) {\n\t\tthrow new TypeError( format( '1VL32', reducer ) );\n\t}\n\tif ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like\n\t\treturn ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tif ( isArrayLikeObject( arr ) ) {\n\t\treturn arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len\n\t}\n\tthrow new TypeError( format( '1VLBH', arr ) );\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n","/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 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// MAIN //\n\n/**\n* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result.\n*\n* @private\n* @param {Object} x - object containing input array data\n* @param {ArrayLikeObject} x.data - input array data\n* @param {Array} x.accessors - input array accessors\n* @param {*} initial - initial value\n* @param {Function} mapper - mapping function\n* @param {Function} reducer - reducing function\n* @param {*} thisArg - reducing function execution context\n* @returns {*} accumulated result\n*\n* @example\n* function square( value ) {\n* return value * value;\n* }\n*\n* function sum( acc, value ) {\n* return acc + value;\n* }\n*\n* // Define a getter:\n* function getter( buf, idx ) {\n* return buf[ idx ];\n* }\n*\n* // Create the input array object:\n* var x = {\n* 'data': [ 1, 2, 3, 4 ],\n* 'accessors': [ getter ]\n* };\n*\n* // Compute the sum of squared values:\n* var out = mapReduceRight( x, 0, square, sum );\n* // returns 30\n*/\nfunction mapReduceRight( x, initial, mapper, reducer, thisArg ) {\n\tvar xbuf;\n\tvar get;\n\tvar acc;\n\tvar i;\n\n\t// Cache reference to the input data:\n\txbuf = x.data;\n\n\t// Cache the element accessor:\n\tget = x.accessors[ 0 ];\n\n\t// Iterate over each element...\n\tacc = initial;\n\tfor ( i = xbuf.length-1; i >= 0; i-- ) {\n\t\tacc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len\n\t}\n\treturn acc;\n}\n\n\n// EXPORTS //\n\nexport default mapReduceRight;\n"],"names":["MODE","mapReduceRight","arr","initial","mapper","reducer","thisArg","isFunction","TypeError","format","isndarrayLike","x","xbuf","ordx","acc","len","get","ref","shx","sx","ox","ix","i","length","shape","data","strides","offset","order","accessors","call","vind2bind","ndarrayFcn","ndarraylike2object","isArrayLikeObject","arrayFcn","arraylike2object"],"mappings":";;srBA2BA,IAAIA,EAAO,QC+DX,SAASC,EAAgBC,EAAKC,EAASC,EAAQC,EAASC,GACvD,IAAMC,EAAYH,GACjB,MAAM,IAAII,UAAWC,EAAQ,QAASL,IAEvC,IAAMG,EAAYF,GACjB,MAAM,IAAIG,UAAWC,EAAQ,QAASJ,IAEvC,GAAKK,EAAeR,GACnB,ODGF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EA2BJ,GAxBAP,EAAMJ,EAAEY,OAGRL,EAAMP,EAAEa,MAGRZ,EAAOD,EAAEc,KAGTN,EAAKR,EAAEe,QAGPN,EAAKT,EAAEgB,OAGPd,EAAOF,EAAEiB,MAGTZ,EAAML,EAAEkB,UAAW,GAGnBZ,EAAMN,EAAEM,IAGY,IAAfC,EAAIK,OACR,OAAOlB,EAAQyB,KAAMxB,EAASH,EAASC,EAAQY,EAAKJ,EAAMQ,GAAM,EAAGH,GAAO,EAAGA,GAI9E,IADAH,EAAMX,EACAmB,EAAIP,EAAI,EAAGO,GAAK,EAAGA,IACxBD,EAAKU,EAAWb,EAAKC,EAAIC,EAAIP,EAAMS,EAAGtB,GACtCc,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMS,GAAMC,EAAGL,GAAOK,EAAGL,GAEzE,OAAOH,CACR,CCnDSkB,CAAYC,EAAoB/B,GAAOC,EAASC,EAAQC,EAASC,GAEzE,GAAK4B,EAAmBhC,GACvB,OC1CF,SAAyBS,EAAGR,EAASC,EAAQC,EAASC,GACrD,IAAIM,EACAI,EACAF,EACAQ,EAUJ,IAPAV,EAAOD,EAAEc,KAGTT,EAAML,EAAEkB,UAAW,GAGnBf,EAAMX,EACAmB,EAAIV,EAAKW,OAAO,EAAGD,GAAK,EAAGA,IAChCR,EAAMT,EAAQyB,KAAMxB,EAASQ,EAAKV,EAAQY,EAAKJ,EAAMU,GAAKA,EAAGV,GAAQU,EAAGV,GAEzE,OAAOE,CACR,CDwBSqB,CAAUC,EAAkBlC,GAAOC,EAASC,EAAQC,EAASC,GAErE,MAAM,IAAIE,UAAWC,EAAQ,QAASP,GACvC"} \ No newline at end of file diff --git a/lib/array.js b/lib/array.js deleted file mode 100644 index 69c0a8c..0000000 --- a/lib/array.js +++ /dev/null @@ -1,83 +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. -*/ - -'use strict'; - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input array data -* @param {ArrayLikeObject} x.data - input array data -* @param {Array} x.accessors - input array accessors -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf[ idx ]; -* } -* -* // Create the input array object: -* var x = { -* 'data': [ 1, 2, 3, 4 ], -* 'accessors': [ getter ] -* }; -* -* // Compute the sum of squared values: -* var out = mapReduceRight( x, 0, square, sum ); -* // returns 30 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var get; - var acc; - var i; - - // Cache reference to the input data: - xbuf = x.data; - - // Cache the element accessor: - get = x.accessors[ 0 ]; - - // Iterate over each element... - acc = initial; - for ( i = xbuf.length-1; i >= 0; i-- ) { - acc = reducer.call( thisArg, acc, mapper( get( xbuf, i ), i, xbuf ), i, xbuf ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 3b25355..0000000 --- a/lib/index.js +++ /dev/null @@ -1,65 +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. -*/ - -'use strict'; - -/** -* Perform a map-reduce operation against each element in an array while iterating from right to left and return the accumulated result. -* -* @module @stdlib/utils-map-reduce-right -* -* @example -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/number-float64-base-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* var mapReduceRight = require( '@stdlib/utils-map-reduce-right' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ - -// 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 c7692a8..0000000 --- a/lib/main.js +++ /dev/null @@ -1,110 +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. -*/ - -'use strict'; - -// MODULES // - -var isArrayLikeObject = require( '@stdlib/assert-is-array-like-object' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var isFunction = require( '@stdlib/assert-is-function' ); -var ndarraylike2object = require( '@stdlib/ndarray-base-ndarraylike2object' ); -var arraylike2object = require( '@stdlib/array-base-arraylike2object' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var ndarrayFcn = require( './ndarray.js' ); -var arrayFcn = require( './array.js' ); - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* ## Notes -* -* - The mapping function is provided the following arguments: -* -* - **value**: array element. -* - **index**: element index. -* - **arr**: input array. -* -* - The reducing function is provided the following arguments: -* -* - **accumulator**: accumulated value. -* - **value**: result of applying the mapping function against the current array element. -* - **index**: element index. -* - **arr**: input array. -* -* @param {(ArrayLikeObject|ndarray)} arr - input array -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} [thisArg] - reduction function execution context -* @throws {TypeError} first argument must be an array-like object or an ndarray -* @throws {TypeError} third argument must be a function -* @throws {TypeError} fourth argument must be a function -* @returns {*} accumulated result -* -* @example -* function square( value ) { -* return value * value; -* } -* -* function sum( acc, value ) { -* return acc + value; -* } -* -* var arr = [ 1, 2, 3, 4 ]; -* -* var out = mapReduceRight( arr, 0, square, sum ); -* // returns 30 -* -* @example -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* var add = require( '@stdlib/number-float64-base-add' ); -* var abs = require( '@stdlib/math-base-special-abs' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic' -* }; -* var arr = array( [ [ -1, -2, -3 ], [ -4, -5, -6 ] ], opts ); -* -* var out = mapReduceRight( arr, 0, naryFunction( abs, 1 ), naryFunction( add, 2 ) ); -* // returns 21 -*/ -function mapReduceRight( arr, initial, mapper, reducer, thisArg ) { - if ( !isFunction( mapper ) ) { - throw new TypeError( format( '1VL3N', mapper ) ); - } - if ( !isFunction( reducer ) ) { - throw new TypeError( format( '1VL32', reducer ) ); - } - if ( isndarrayLike( arr ) ) { // note: assertion order matters here, as an ndarray-like object is also array-like - return ndarrayFcn( ndarraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - if ( isArrayLikeObject( arr ) ) { - return arrayFcn( arraylike2object( arr ), initial, mapper, reducer, thisArg ); // eslint-disable-line max-len - } - throw new TypeError( format( '1VLBH', arr ) ); -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/lib/ndarray.js b/lib/ndarray.js deleted file mode 100644 index bcf9eb1..0000000 --- a/lib/ndarray.js +++ /dev/null @@ -1,155 +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. -*/ - -'use strict'; - -// MODULES // - -var vind2bind = require( '@stdlib/ndarray-base-vind2bind' ); - - -// VARIABLES // - -var MODE = 'throw'; - - -// MAIN // - -/** -* Performs a map-reduce operation against each element in an array while iterating from right to left and returns the accumulated result. -* -* @private -* @param {Object} x - object containing input ndarray meta data -* @param {string} x.ref - reference to original input ndarray-like object -* @param {string} x.dtype - data type -* @param {Collection} x.data - data buffer -* @param {NonNegativeInteger} x.length - number of elements -* @param {NonNegativeIntegerArray} x.shape - dimensions -* @param {IntegerArray} x.strides - stride lengths -* @param {NonNegativeInteger} x.offset - index offset -* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style) -* @param {Array} x.accessors - accessors for accessing data buffer elements -* @param {*} initial - initial value -* @param {Function} mapper - mapping function -* @param {Function} reducer - reducing function -* @param {*} thisArg - reducing function execution context -* @returns {*} accumulated result -* -* @example -* var Complex64Array = require( '@stdlib/array-complex64' ); -* var Complex64 = require( '@stdlib/complex-float32-ctor' ); -* var realf = require( '@stdlib/complex-float32-real' ); -* var imagf = require( '@stdlib/complex-float32-imag' ); -* var cceil = require( '@stdlib/math-base-special-cceil' ); -* var cadd = require( '@stdlib/complex-float64-base-add' ); -* var naryFunction = require( '@stdlib/utils-nary-function' ); -* -* // Create a data buffer: -* var xbuf = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5 ] ); -* -* // Define the shape of the input array: -* var shape = [ 2, 2 ]; -* -* // Define the array strides: -* var sx = [ 2, 1 ]; -* -* // Define the index offset: -* var ox = 0; -* -* // Define a getter: -* function getter( buf, idx ) { -* return buf.get( idx ); -* } -* -* // Create the input ndarray-like object: -* var x = { -* 'ref': null, -* 'dtype': 'complex64', -* 'data': xbuf, -* 'length': 4, -* 'shape': shape, -* 'strides': sx, -* 'offset': ox, -* 'order': 'row-major', -* 'accessors': [ getter ] -* }; -* x.ref = x; -* -* // Compute the sum: -* var v = mapReduceRight( x, new Complex64( 0.0, 0.0 ), naryFunction( cceil, 1 ), naryFunction( cadd, 2 ) ); -* -* var re = realf( v ); -* // returns 20.0 -* -* var im = imagf( v ); -* // returns 24.0 -*/ -function mapReduceRight( x, initial, mapper, reducer, thisArg ) { - var xbuf; - var ordx; - var acc; - var len; - var get; - var ref; - var shx; - var sx; - var ox; - var ix; - var i; - - // Cache the total number of elements over which to iterate: - len = x.length; - - // Cache the input array shape: - shx = x.shape; - - // Cache reference to the input ndarray data buffer: - xbuf = x.data; - - // Cache reference to the stride array: - sx = x.strides; - - // Cache the index of the first indexed element: - ox = x.offset; - - // Cache the array order: - ordx = x.order; - - // Cache the element accessor: - get = x.accessors[ 0 ]; - - // Cache the reference to the original input array: - ref = x.ref; - - // Check for a zero-dimensional array... - if ( shx.length === 0 ) { - return reducer.call( thisArg, initial, mapper( get( xbuf, ox ), 0, ref ), 0, ref ); // eslint-disable-line max-len - } - // Iterate over each element based on the linear **view** index, regardless as to how the data is stored in memory (note: this has negative performance implications for non-contiguous ndarrays due to a lack of data locality)... - acc = initial; - for ( i = len-1; i >= 0; i-- ) { - ix = vind2bind( shx, sx, ox, ordx, i, MODE ); - acc = reducer.call( thisArg, acc, mapper( get( xbuf, ix ), i, ref ), i, ref ); // eslint-disable-line max-len - } - return acc; -} - - -// EXPORTS // - -module.exports = mapReduceRight; diff --git a/package.json b/package.json index d39f6e2..3df9694 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Perform a single-pass map-reduce operation against each element in an array while iterating from right to left and return the accumulated result.", "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/array-base-arraylike2object": "^0.2.1", - "@stdlib/assert-is-array-like-object": "^0.2.2", - "@stdlib/assert-is-function": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/ndarray-base-ndarraylike2object": "^0.2.2", - "@stdlib/ndarray-base-vind2bind": "^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-base-filled": "^0.2.2", - "@stdlib/array-complex64": "^0.3.0", - "@stdlib/array-filled-by": "^0.2.1", - "@stdlib/array-float64": "^0.2.2", - "@stdlib/complex-float32-ctor": "^0.0.2", - "@stdlib/complex-float32-imag": "^0.1.1", - "@stdlib/complex-float32-real": "^0.1.1", - "@stdlib/complex-float64-base-add": "^0.1.0", - "@stdlib/math-base-assert-is-nan": "^0.2.2", - "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/math-base-special-cceil": "^0.2.2", - "@stdlib/math-base-special-pow": "^0.3.0", - "@stdlib/ndarray-array": "^0.2.1", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/number-float64-base-add": "github:stdlib-js/number-float64-base-add#main", - "@stdlib/random-base-discrete-uniform": "^0.2.1", - "@stdlib/utils-nary-function": "^0.2.2", - "@stdlib/utils-noop": "^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", "stdutils", diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..150aec2 --- /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/test.js b/test/test.js deleted file mode 100644 index 3ac2622..0000000 --- a/test/test.js +++ /dev/null @@ -1,637 +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. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var noop = require( '@stdlib/utils-noop' ); -var naryFunction = require( '@stdlib/utils-nary-function' ); -var add = require( '@stdlib/number-float64-base-add' ); -var cadd = require( '@stdlib/complex-float64-base-add' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var cceil = require( '@stdlib/math-base-special-cceil' ); -var Float64Array = require( '@stdlib/array-float64' ); -var Complex64Array = require( '@stdlib/array-complex64' ); -var array = require( '@stdlib/ndarray-array' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Complex64 = require( '@stdlib/complex-float32-ctor' ); -var realf = require( '@stdlib/complex-float32-real' ); -var imagf = require( '@stdlib/complex-float32-imag' ); -var isnan = require( '@stdlib/math-base-assert-is-nan' ); -var mapReduceRight = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof mapReduceRight, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided a first argument which is either an array-like object or an ndarray', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - function noop() {}, - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( value, 0, noop, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop ); - }; - } -}); - -tape( 'the function throws an error if not provided a third argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, value, noop, {} ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a fourth argument which is a function (context)', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - {}, - [], - /.*/, - new Date() - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - mapReduceRight( [ 1, 2, 3 ], 0, noop, value, {} ); - }; - } -}); - -tape( 'the function performs a map-reduce operation for each element in an array (array-like object)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = [ -1, -2, -3 ]; - expected = 7; - actual = mapReduceRight( arr, 1, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (typed array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = new Float64Array( [ -1.0, -2.0, -3.0 ] ); - expected = 7.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (complex number array)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( cceil, 1 ); - f2 = naryFunction( cadd, 2 ); - - arr = new Complex64Array( [ 1.5, 2.5, 3.5, 4.5, 5.5, 6.5 ] ); - expected = new Complex64( 12.0, 15.0 ); - actual = mapReduceRight( arr, new Complex64( 0.0, 0.0 ), f1, f2 ); - - t.strictEqual( realf( actual ), realf( expected ), 'returns expected value' ); - t.strictEqual( imagf( actual ), imagf( expected ), 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = array( [ -1.0, -2.0, -3.0, -4.0 ], { - 'dtype': 'generic' - }); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'the function performs a map-reduce operation for each element in an array (ndarray; 0-dimensional)', function test( t ) { - var expected; - var actual; - var arr; - var f1; - var f2; - - f1 = naryFunction( abs, 1 ); - f2 = naryFunction( add, 2 ); - - arr = ndarray( 'generic', [ -10.0 ], [], [ 0 ], 0, 'row-major' ); - expected = 11.0; - actual = mapReduceRight( arr, 1.0, f1, f2 ); - - t.strictEqual( actual, expected, 'returns expected value' ); - t.end(); -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (array-like object)', function test( t ) { - var out = mapReduceRight( [], 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'if provided an empty array, the function returns the initial value and never performs a map-reduce operation (ndarray)', function test( t ) { - var arr; - var out; - - arr = ndarray( 'generic', [ 1, 2, 3, 4 ], [ 2, 0, 2 ], [ 0, 2, 1 ], 0, 'row-major' ); - out = mapReduceRight( arr, 0, foo, foo ); - t.strictEqual( out, 0, 'expected result' ); - - t.end(); - - function foo() { - t.fail( 'should not be invoked' ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a mapping function with three arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - values = []; - idx = []; - arrays = []; - - actual = mapReduceRight( arr, 0, fcn, add ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ -6, -5, -4, -3, -2, -1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 3, 3, 3, 3, 3, 3 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( v, i, arr ) { - nargs.push( arguments.length ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return abs( v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = [ -1, -2, -3, -4, -5, -6 ]; - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function invokes a reducing function with four arguments (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arrays; - var nargs; - var idx; - var arr; - var acc; - var f; - - arr = array( [ -1, -2, -3, -4, -5, -6 ], { - 'dtype': 'generic', - 'shape': [ 2, 3 ] - }); - - nargs = []; - acc = []; - values = []; - idx = []; - arrays = []; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0, f, fcn ); - - expected = 21; - t.strictEqual( actual, expected, 'returns expected value' ); - - expected = [ 0, 6, 11, 15, 18, 20 ]; - t.deepEqual( acc, expected, 'returns expected value' ); - - expected = [ 6, 5, 4, 3, 2, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - expected = [ 5, 4, 3, 2, 1, 0 ]; - t.deepEqual( idx, expected, 'returns expected value' ); - - expected = [ arr, arr, arr, arr, arr, arr ]; - t.deepEqual( arrays, expected, 'returns expected value' ); - - expected = [ 4, 4, 4, 4, 4, 4 ]; - t.deepEqual( nargs, expected, 'returns expected value' ); - - t.end(); - - function fcn( accumulator, v, i, arr ) { - nargs.push( arguments.length ); - acc.push( accumulator ); - values.push( v ); - idx.push( i ); - arrays.push( arr ); - return add( accumulator, v ); - } -}); - -tape( 'the function supports providing a `this` context (array-like object)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = [ -1.0, -2.0, -3.0 ]; - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function supports providing a `this` context (ndarray)', function test( t ) { - var expected; - var actual; - var ctx; - var arr; - var f; - - arr = array( [ -1.0, -2.0, -3.0 ], { - 'dtype': 'generic' - }); - - ctx = { - 'count': 0 - }; - - expected = 6.0; - - f = naryFunction( abs, 1 ); - actual = mapReduceRight( arr, 0.0, f, sum, ctx ); - - t.strictEqual( actual, expected, 'expected value' ); - t.strictEqual( ctx.count, 3, 'returns expected value' ); - - t.end(); - - function sum( acc, value ) { - this.count += 1; // eslint-disable-line no-invalid-this - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (array-like object)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = [ 1, , , 4 ]; // eslint-disable-line no-sparse-arrays - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -}); - -tape( 'the function does not skip empty elements (ndarray)', function test( t ) { - var expected; - var actual; - var values; - var arr; - var f; - - arr = array( [ 1, , , 4 ], { // eslint-disable-line no-sparse-arrays - 'dtype': 'generic' - }); - - values = []; - - f = naryFunction( identity, 1 ); - actual = mapReduceRight( arr, 0, f, sum ); - - t.strictEqual( isnan( actual ), true, 'returns expected value' ); - - expected = [ 4, void 0, void 0, 1 ]; - t.deepEqual( values, expected, 'returns expected value' ); - - t.end(); - - function identity( value ) { - return value; - } - - function sum( acc, value ) { - values.push( value ); - return acc + value; - } -});